From 48b25a5069d9f7e576f4fc347dec10d19570342c Mon Sep 17 00:00:00 2001 From: Xavier Dubuc Date: Mon, 2 Nov 2020 14:13:22 +0000 Subject: [PATCH] [FIX] mail: prevent load messages if already loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit task-2373952 closes odoo/odoo#61424 X-original-commit: a4c737eb1d45610f6ab70268d5134dc5ed00ba8d Signed-off-by: Sébastien Theys (seb) --- .../components/discuss/tests/discuss_tests.js | 31 +++++++++++++++++++ .../src/models/thread_cache/thread_cache.js | 10 ++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/components/discuss/tests/discuss_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_tests.js index 91a578e7b1b..481e78681bc 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -14,6 +14,12 @@ const { const Bus = require('web.Bus'); const { makeTestPromise, file: { createFile, inputFiles } } = require('web.test_utils'); +const { + applyFilter, + toggleAddCustomFilter, + toggleFilterMenu, +} = require('web.test_utils_control_panel'); + QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { QUnit.module('discuss', {}, function () { @@ -4262,6 +4268,31 @@ QUnit.test('mark channel as seen if last message is visible when switching chann ); }); +QUnit.test('add custom filter should filter messages accordingly to selected filter', async function (assert) { + assert.expect(4); + + this.data['mail.channel'].records.push({ + id: 20, + name: "General" + }); + await this.start({ + async mockRPC(route, args) { + if (args.method === 'message_fetch') { + const domainsAsStr = args.kwargs.domain.map(domain => domain.join('')); + assert.step(`message_fetch:${domainsAsStr.join(',')}`); + } + return this._super(...arguments); + }, + }); + assert.verifySteps(['message_fetch:needaction=true'], "A message_fetch request should have been done for needaction messages as inbox is selected by default"); + + // Open filter menu of control panel and select a custom filter (id = 0, the only one available) + await toggleFilterMenu(document.body); + await toggleAddCustomFilter(document.body); + await applyFilter(document.body); + assert.verifySteps(['message_fetch:id=0,needaction=true'], "A message_fetch request should have been done for selected filter & domain of current thread (inbox)"); +}); + }); }); }); diff --git a/addons/mail/static/src/models/thread_cache/thread_cache.js b/addons/mail/static/src/models/thread_cache/thread_cache.js index c474c565219..c684861e2be 100644 --- a/addons/mail/static/src/models/thread_cache/thread_cache.js +++ b/addons/mail/static/src/models/thread_cache/thread_cache.js @@ -203,13 +203,17 @@ function factory(dependencies) { if (!wasCacheRefreshRequested && this.threadViews.length === 0) { // don't load message that won't be used return false; - } - if (!wasCacheRefreshRequested && (this.isLoaded || this.isLoading)) { + } + if (this.isLoading) { + // avoid duplicate RPC + return false; + } + if (!wasCacheRefreshRequested && this.isLoaded) { // avoid duplicate RPC return false; } const isMainCache = this.thread.mainCache === this; - if (isMainCache && (this.isLoaded || this.isLoading)) { + if (isMainCache && this.isLoaded) { // Ignore request on the main cache if it is already loaded or // loading. Indeed the main cache is automatically sync with // server updates already, so there is never a need to refresh