diff --git a/addons/mail/static/src/js/models/threads/abstract_thread.js b/addons/mail/static/src/js/models/threads/abstract_thread.js index 322541af016..b0a7f1d0b2e 100644 --- a/addons/mail/static/src/js/models/threads/abstract_thread.js +++ b/addons/mail/static/src/js/models/threads/abstract_thread.js @@ -16,7 +16,7 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, { * @param {Object} params.data * @param {integer|string} params.data.id the ID of this thread * @param {string} params.data.name the name of this thread - * @param {string} params.data.status the status of this thread + * @param {string} [params.data.status=''] the status of this thread * @param {Object} params.parent Object with the event-dispatcher mixin * (@see {web.mixins.EventDispatcherMixin}) */ @@ -27,7 +27,7 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, { this._folded = false; // threads are unfolded by default this._id = params.data.id; this._name = params.data.name; - this._status = params.data.status; + this._status = params.data.status || ''; this._unreadCounter = 0; // amount of messages not yet been read }, diff --git a/addons/mail/static/src/js/models/threads/channel.js b/addons/mail/static/src/js/models/threads/channel.js index 8f0f664b6b0..51ebe34a651 100644 --- a/addons/mail/static/src/js/models/threads/channel.js +++ b/addons/mail/static/src/js/models/threads/channel.js @@ -51,7 +51,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { this._autoswitch = 'autoswitch' in options ? options.autoswitch : true; this._commands = undefined; this._creatorUID = data.create_uid; - this._detached = data.is_minimized; + this._detached = data.is_minimized || false; this._directPartnerID = undefined; this._folded = data.state === 'folded'; // if set: hide 'Leave channel' button @@ -66,7 +66,6 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { // number of messages in this channel that are in inbox. this._needactionCounter = data.message_needaction_counter || 0; this._serverType = data.channel_type; - this._status = undefined; this._throttleFetchSeen = _.throttle(this._fetchSeen.bind(this), 3000); // unique identifier for this channel, which is required for some rpc this._uuid = data.uuid; diff --git a/addons/mail/static/src/js/models/threads/mailbox.js b/addons/mail/static/src/js/models/threads/mailbox.js index f3e0754ee20..f3b541d07a7 100644 --- a/addons/mail/static/src/js/models/threads/mailbox.js +++ b/addons/mail/static/src/js/models/threads/mailbox.js @@ -46,11 +46,8 @@ var Mailbox = SearchableThread.extend({ this._mailboxCounter = Math.max(this._mailboxCounter - num, 0); }, /** - * Get the local messages of the mailbox (by local messages, we mean - * messages that have already been fetched from the server). - * - * It is possible to filter on local messages that are specific to a - * document with the `options` parameter. + * Override so that there are options to filter messages based on document + * model and ID. * * @param {Object} [options] * @param {string} [options.documentModel] model of the document that the @@ -58,15 +55,15 @@ var Mailbox = SearchableThread.extend({ * @param {integer} [options.documentID] ID of the document that the local * messages of inbox must be linked to. */ - getLocalMessages: function (options) { - var localMessages = this._cache['[]'].messages; + getMessages: function (options) { + var messages = this._super.apply(this, arguments); if (!options) { - return localMessages; + return messages; } if (options.documentModel && options.documentID) { - return _.filter(localMessages, function (localMessage) { - return localMessage.getDocumentModel() === options.documentModel && - localMessage.getDocumentID() === options.documentID; + return _.filter(messages, function (message) { + return message.getDocumentModel() === options.documentModel && + message.getDocumentID() === options.documentID; }); } }, diff --git a/addons/mail/static/src/js/systray/systray_messaging_menu.js b/addons/mail/static/src/js/systray/systray_messaging_menu.js index d4b1b078a02..4fc3e9a4940 100644 --- a/addons/mail/static/src/js/systray/systray_messaging_menu.js +++ b/addons/mail/static/src/js/systray/systray_messaging_menu.js @@ -312,7 +312,7 @@ var MessagingMenu = Widget.extend({ if (previewID === 'mailbox_inbox') { var documentID = $preview.data('document-id'); var inbox = this.call('mail_service', 'getMailbox', 'inbox'); - var messages = inbox.getLocalMessages({ + var messages = inbox.getMessages({ documentModel: documentModel, documentID: documentID, }); diff --git a/addons/mail/static/src/js/thread_windows/abstract_thread_window.js b/addons/mail/static/src/js/thread_windows/abstract_thread_window.js index eb8a7da3634..8a8bf3a0077 100644 --- a/addons/mail/static/src/js/thread_windows/abstract_thread_window.js +++ b/addons/mail/static/src/js/thread_windows/abstract_thread_window.js @@ -384,13 +384,6 @@ var AbstractThreadWindow = Widget.extend({ this.updateVisualFoldState(); } }, - /** - * Warn other mail components that the unread counter has been updated - * - * @abstract - * @private - */ - _warnUpdatedUnreadCounter: function () {}, //-------------------------------------------------------------------------- // Handlers diff --git a/addons/mail/static/src/js/thread_windows/thread_window.js b/addons/mail/static/src/js/thread_windows/thread_window.js index f0662b531b9..20c0965205e 100644 --- a/addons/mail/static/src/js/thread_windows/thread_window.js +++ b/addons/mail/static/src/js/thread_windows/thread_window.js @@ -156,14 +156,6 @@ var ThreadWindow = AbstractThreadWindow.extend({ removePassive: function () { this._passive = false; }, - /** - * Set the thread window in passive mode, so that new received message will - * keep the thread window as unread until there is focus on the thread - * window. - */ - setPassive: function () { - this._passive = true; - }, /** * Update this thread window * @@ -177,7 +169,7 @@ var ThreadWindow = AbstractThreadWindow.extend({ update: function (options) { var self = this; if (options.passively) { - this.setPassive(); + this._setPassive(); } var bottomVisible = !this.isFolded() && !this.isHidden() && @@ -231,6 +223,16 @@ var ThreadWindow = AbstractThreadWindow.extend({ _open: function () { this.call('mail_service', 'openThreadWindow', this.getID()); }, + /** + * Set the thread window in passive mode, so that new received message will + * keep the thread window as unread until there is focus on the thread + * window. + * + * @private + */ + _setPassive: function () { + this._passive = true; + }, /** * @private */ diff --git a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js index ffda7d95700..347682e68df 100644 --- a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js +++ b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js @@ -196,23 +196,10 @@ QUnit.test('emoji popover should open correctly in thread windows', function (as QUnit.test('do not increase unread counter when receiving message with myself as author', function (assert) { assert.expect(4); - var generalChannelID = 1; - var myselfPartnerID = 44; - - this.data.initMessaging = { - channel_slots: { - channel_channel: [{ - id: generalChannelID, - channel_type: 'channel', - name: "general", - }], - }, - }; - var parent = this.createParent({ data: this.data, services: this.services, - session: { partner_id: myselfPartnerID } + session: { partner_id: 3 } }); // get channel instance to link to thread window @@ -228,14 +215,14 @@ QUnit.test('do not increase unread counter when receiving message with myself as // simulate receiving message from myself var messageData = { - author_id: [myselfPartnerID, "Myself"], + author_id: [3, "Myself"], body: "

Test message

", id: 2, model: 'mail.channel', res_id: 1, channel_ids: [1], }; - var notification = [[false, 'mail.channel', generalChannelID], messageData]; + var notification = [[false, 'mail.channel', 1], messageData]; parent.call('bus_service', 'trigger', 'notification', [notification]); threadWindowHeaderText = $('.o_thread_window_header').text().replace(/\s/g, "");