From 8af392865deac628b1ff57627fa116131547bea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 7 Nov 2018 10:20:48 +0000 Subject: [FIX] mail: mark as read per preview Before this commit, when there was several previews on the messaging menu that were not linked to any document, marking one of them as read had the unintended behaviour to mark all of them as read. Steps to reproduce: - Admin with notification management as 'Handle with Odoo' - Demo assign Admin to two different tasks - Admin mark one preview as read > Both previews notifying assignment to a task have been marked as read This is caused by the fact that messages of those previews are not related to any document. As a result, when marking one preview as read, it maps related messages to mark as read, which was taking into account all messages that are not related to any document. With this commit, previews now tracks message IDs, so that marking one preview as read only mark the related messages as read. Task-ID 1907159 --- .../mail/static/src/js/models/threads/mailbox.js | 33 +++++++--------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'addons/mail/static/src/js/models/threads') diff --git a/addons/mail/static/src/js/models/threads/mailbox.js b/addons/mail/static/src/js/models/threads/mailbox.js index 28dbc4b7163..8d49d84d777 100644 --- a/addons/mail/static/src/js/models/threads/mailbox.js +++ b/addons/mail/static/src/js/models/threads/mailbox.js @@ -45,28 +45,6 @@ var Mailbox = SearchableThread.extend({ num = _.isNumber(num) ? num : 1; this._mailboxCounter = Math.max(this._mailboxCounter - num, 0); }, - /** - * Override so that there are options to filter messages based on document - * model and ID. - * - * @override - * @param {Object} [options] - * @param {string} [options.documentModel] model of the document that the - * local messages of inbox must be linked to. - * @param {integer} [options.documentID] ID of the document that the local - * messages of inbox must be linked to. - * @returns {mail.model.Message[]} - */ - getMessages: function (options) { - var messages = this._super.apply(this, arguments); - if (options.documentModel && options.documentID) { - return _.filter(messages, function (message) { - return message.getDocumentModel() === options.documentModel && - message.getDocumentID() === options.documentID; - }); - } - return messages; - }, /** * Get the mailbox counter of this mailbox. * @@ -89,31 +67,40 @@ var Mailbox = SearchableThread.extend({ return this.fetchMessages().then(function (messages) { // pick only last message of chatter // items = list of objects - // { unreadCounter: integer, message: mail.model.Message } + // { + // unreadCounter: {integer}, + // message: {mail.model.Message}, + // messageIDs: {integer[]}, + // } var items = []; _.each(messages, function (message) { var unreadCounter = 1; + var messageIDs = [message.getID()]; var similarItem = _.find(items, function (item) { return self._areMessagesFromSameDocumentThread(item.message, message) || self._areMessagesFromSameChannel(item.message, message); }); if (similarItem) { unreadCounter = similarItem.unreadCounter + 1; + messageIDs = similarItem.messagesIDs.concat(messageIDs); var index = _.findIndex(items, similarItem); items[index] = { unreadCounter: unreadCounter, message: message, + messageIDs: messageIDs }; } else { items.push({ unreadCounter: unreadCounter, message: message, + messageIDs: messageIDs, }); } }); return _.map(items, function (item) { return _.extend(item.message.getPreview(), { unreadCounter: item.unreadCounter, + messageIDs: item.messageIDs, }); }); }); -- cgit v1.2.3 From 2b245ebb436a6880f05e25c65470bd48c3eea4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 14 Nov 2018 20:19:59 +0000 Subject: [FIX] mail: no crash on grouped inbox messages previews Revision on https://github.com/odoo/odoo/commit/5f8d3c61bee40d027efc5041cdc4bca5e67c42d7 Before this commit, there was a traceback when you had two needaction notifications related to the same document. This is caused by a typo in the commit above: the object `similarItem` has a property `messageIDs`, but the code wrongly access the property `messagesIDs` (see the extra "s"). Steps to reproduce: - Set notification management to 'Handle with Odoo' for Admin - Demo mention Admin twice on a specific project task - Admin opens messaging menu Display error `Cannot read property 'concat' of undefined` Issue reported on this PR comment: https://github.com/odoo/odoo/pull/28462#pullrequestreview-175001349 Task-ID 1909521 closes odoo/odoo#28703 --- addons/mail/static/src/js/models/threads/mailbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js/models/threads') diff --git a/addons/mail/static/src/js/models/threads/mailbox.js b/addons/mail/static/src/js/models/threads/mailbox.js index 8d49d84d777..82d65bdd6cc 100644 --- a/addons/mail/static/src/js/models/threads/mailbox.js +++ b/addons/mail/static/src/js/models/threads/mailbox.js @@ -82,7 +82,7 @@ var Mailbox = SearchableThread.extend({ }); if (similarItem) { unreadCounter = similarItem.unreadCounter + 1; - messageIDs = similarItem.messagesIDs.concat(messageIDs); + messageIDs = similarItem.messageIDs.concat(messageIDs); var index = _.findIndex(items, similarItem); items[index] = { unreadCounter: unreadCounter, -- cgit v1.2.3 From 9eff26367fdc7f57bea5dca10c3e5d7b3a858f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 15 Nov 2018 20:37:21 +0000 Subject: [FIX] mail: easily mention followers and employees in chatter Revision on https://github.com/odoo/odoo/commit/cd34f6de727d5b3858420cff3c9d3c5995c4e75c Resulting of the mail JS refactoring, the list of prefetched suggestions has been changed as follow: - before: list of list of mention suggestions `{Array}` - after: list of mention suggestions `{Object[]}` The change resulted in wrongly thinking that wrapping the list of suggestions in a list was pointless, thus simplifying it as a simple list of mention suggestions. However, because of this change, it has become much harder to mention employees and followers of documents from the chatter: it now always fetches all partner suggestions at all time, whereas before it was suggesting followers, then employees, and finally all partners based on the input of the user. In fact, there was a purpose of using a list of list of prefetched mention suggestions, which is to group suggestions by "priority": followers first, then employees, and all partners as a last resort. This commit re-introduces prefetched mention suggestions as a list of list of partners, so that it re-becomes easier to mention followers and partners of a document from the chatter. Task-ID 1910111 --- addons/mail/static/src/js/models/threads/channel.js | 5 +++-- addons/mail/static/src/js/models/threads/livechat.js | 5 +++-- addons/mail/static/src/js/models/threads/thread.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'addons/mail/static/src/js/models/threads') diff --git a/addons/mail/static/src/js/models/threads/channel.js b/addons/mail/static/src/js/models/threads/channel.js index 695275e799e..808e8b7fbca 100644 --- a/addons/mail/static/src/js/models/threads/channel.js +++ b/addons/mail/static/src/js/models/threads/channel.js @@ -179,7 +179,8 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { /** * Get listeners of a channel * - * @returns {$.Promise} resolved with list of channel listeners + * @returns {$.Promise>} resolved with list of list of + * channel listeners. */ getMentionPartnerSuggestions: function () { var self = this; @@ -193,7 +194,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { }) .then(function (members) { self._members = members; - return members; + return [members]; }); } return this._membersDef; diff --git a/addons/mail/static/src/js/models/threads/livechat.js b/addons/mail/static/src/js/models/threads/livechat.js index b7235e7bc0e..f4cb58ebad3 100644 --- a/addons/mail/static/src/js/models/threads/livechat.js +++ b/addons/mail/static/src/js/models/threads/livechat.js @@ -37,7 +37,8 @@ var Livechat = TwoUserChannel.extend({ * display of a user that is typing. * * @override - * @returns {$.Promise} resolved with list of livechat members + * @returns {$.Promise>} resolved with list of list of + * livechat members. */ getMentionPartnerSuggestions: function () { var self = this; @@ -49,7 +50,7 @@ var Livechat = TwoUserChannel.extend({ name: self._WEBSITE_USER_NAME, }); } - return self._members; + return [self._members]; }); }, /** diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js index c9dda28dd93..b15ceb8563c 100644 --- a/addons/mail/static/src/js/models/threads/thread.js +++ b/addons/mail/static/src/js/models/threads/thread.js @@ -111,7 +111,7 @@ var Thread = AbstractThread.extend(ServicesMixin, { * By default, a thread has not listener. * * @abstract - * @returns {$.Promise} + * @returns {$.Promise>} */ getMentionPartnerSuggestions: function () { return $.when([]); -- cgit v1.2.3 From e3f36b10ac6c47954dd29b003161a289f7baaeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 15 Nov 2018 23:43:23 +0000 Subject: [FIX] mail: no crash when searching messages Revision on https://github.com/odoo/odoo/commit/299ebb2cdf63de2e3967da0d2f3e7effd239812b The commit above added the notion of moderation, which requires re-rendering the thread when a message has its moderation changed (i.e. the message is deleted on reject or is no longer marked as 'pending moderation'). However, this condition was triggered even when the moderation status on the message has not changed. This introduced a crash when using the search in discuss: - Access a channel with more than 30 messages, so that not all messages have been fetched. - Search messages in this thread so that it displays more than 30 messages, and the last message of those has already been fetched. > It crashes with "Cannot read property 'getID' of undefined". The bug comes from re-fetching messages: it behaves as a "load more" fetch, although no message has been stored yet. A "load more" fetch requires at least one message in order to determine the minimum message ID to fetch, thus the crash due to having no message to get such an ID. Here's the explanation why it fetches with load more: when performing the search and fetching the same last message, it will detect that it has already been fetched. Its moderation status is 'accepted', and it will assume a change of moderation status. This will trigger a fetch and render of the thread. At this moment, if the search exceeds the fetch limit, not all messages will be fetched, so that this fetch is considered as a "load more" fetch. This commit fixes the issue by only re-rendering the thread when there is a change of the moderation status on an already fetched message. Since changes of the moderation status are handled by means of the longpolling, it should be rare to run into the case of having a change of moderation status on a message while using the search on a thread. Task-ID 1910180 --- addons/mail/static/src/js/models/threads/thread.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'addons/mail/static/src/js/models/threads') diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js index b15ceb8563c..8c2beb8bbfa 100644 --- a/addons/mail/static/src/js/models/threads/thread.js +++ b/addons/mail/static/src/js/models/threads/thread.js @@ -15,7 +15,8 @@ var ServicesMixin = require('web.ServicesMixin'); * In particular, channels and mailboxes are two different kinds of threads. */ var Thread = AbstractThread.extend(ServicesMixin, { - + // max number of fetched messages from the server + _FETCH_LIMIT: 30, /** * @override * @param {Object} params @@ -33,8 +34,6 @@ var Thread = AbstractThread.extend(ServicesMixin, { // means that there is no message in this channel. this._previewed = false; this._type = params.data.type || params.data.channel_type; - // max number of fetched messages from the server - this._FETCH_LIMIT = 30; }, //-------------------------------------------------------------------------- -- cgit v1.2.3