From a409fbdc5a8432770fb1540b9c26ff90aa6f260a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Mon, 28 Sep 2020 16:55:09 +0000 Subject: [PATCH] [FIX] mail: prevent sync fold state for non-channels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit task-2346650 closes odoo/odoo#58801 X-original-commit: f5b6e78e77eac27af3b3812ac3818a67acaa1c85 Signed-off-by: Alexandre Kühn (aku) --- .../thread_needaction_preview_tests.js | 50 +++++++++++++++++++ .../mail/static/src/models/thread/thread.js | 7 +++ 2 files changed, 57 insertions(+) diff --git a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js index 5c59a8f3d50..ff7d6e4cc08 100644 --- a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js +++ b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js @@ -201,6 +201,56 @@ QUnit.test('click on expand from chat window should close the chat window and op ); }); +QUnit.test('[technical] opening a non-channel chat window should not call channel_fold', async function (assert) { + // channel_fold should not be called when opening non-channels in chat + // window, because there is no server sync of fold state for them. + assert.expect(3); + + await this.start({ + hasChatWindow: true, + async mockRPC(route, args) { + if (route.includes('channel_fold')) { + const message = "should not call channel_fold when opening a non-channel chat window"; + assert.step(message); + console.error(message); + throw Error(message); + } + return this._super(...arguments); + }, + }); + const thread = this.env.models['mail.thread'].create({ + id: 11, + model: 'mail.channel', + }); + this.env.models['mail.message'].create({ + id: 21, + isNeedaction: true, + originThread: [['link', thread]], + }); + await this.createThreadNeedactionPreviewComponent({ + threadLocalId: thread.localId, + }); + assert.containsOnce( + document.body, + '.o_ThreadNeedactionPreview', + "should have a preview initially" + ); + assert.containsNone( + document.body, + '.o_ChatWindow', + "should have no chat window initially" + ); + + await afterNextRender(() => + document.querySelector('.o_ThreadNeedactionPreview').click() + ); + assert.containsOnce( + document.body, + '.o_ChatWindow', + "should have opened the chat window on clicking on the preview" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index bd40751ca59..4ad43577b1f 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -616,6 +616,13 @@ function factory(dependencies) { * @param {string} state */ async notifyFoldStateToServer(state) { + if (this.model !== 'mail.channel') { + // Server sync of fold state is only supported for channels. + return; + } + if (!this.uuid) { + return; + } return this.env.models['mail.thread'].performRpcChannelFold(this.uuid, state); }