diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-09-03 16:24:19 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-09-04 14:59:01 +0000 |
| commit | 8d3413ff647de8d98c6858062dd07dde4160af95 (patch) | |
| tree | 3dc134e83c874d5c7f7bf739f13a88ab986ddb1b /addons/mail/static/src/models/message | |
| parent | a5ab687be4e7890262ce9429e18dd011021513d5 (diff) | |
[FIX] mail, sms, snailmail: prevent message_fetch for hidden threads
Automatically load messages from a thread cache only if the thread cache is used
in at least one thread view.
Ensure thread viewer don't keep thread view records alive when they are not
displayed.
This change is particularly important for performance, to avoid spamming RPC at
init if many threads are opened in chat windows.
task-2310623
closes odoo/odoo#57061
X-original-commit: dd6981c7812134e0588f80a157eaba45512cd68e
Related: odoo/enterprise#12936
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models/message')
| -rw-r--r-- | addons/mail/static/src/models/message/message.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/mail/static/src/models/message/message.js b/addons/mail/static/src/models/message/message.js index c92714fb3e8..2c3e3b53c91 100644 --- a/addons/mail/static/src/models/message/message.js +++ b/addons/mail/static/src/models/message/message.js @@ -197,6 +197,51 @@ function factory(dependencies) { kwargs: kwargs, }); } + /** + * Performs the `message_fetch` RPC on `mail.message`. + * + * @static + * @param {Array[]} domain + * @param {integer} [limit] + * @param {integer[]} [moderated_channel_ids] + * @param {Object} [context] + * @returns {mail.message[]} + */ + static async performRpcMessageFetch(domain, limit, moderated_channel_ids, context) { + const messagesData = await this.env.services.rpc({ + model: 'mail.message', + method: 'message_fetch', + kwargs: { + context, + domain, + limit, + moderated_channel_ids, + }, + }, { shadow: true }); + const messages = this.env.models['mail.message'].insert(messagesData.map( + messageData => this.env.models['mail.message'].convertData(messageData) + )); + // compute seen indicators (if applicable) + for (const message of messages) { + for (const thread of message.threads) { + if (thread.model !== 'mail.channel' || thread.channel_type === 'channel') { + // disabled on non-channel threads and + // on `channel` channels for performance reasons + continue; + } + thread.update({ + messageSeenIndicators: [[ + 'insert', + { + id: this.env.models['mail.message_seen_indicator'].computeId(message.id, thread.id), + message: [['link', message]], + }, + ]], + }); + } + } + return messages; + } /** * @static |
