From 5289fb87b5ecb9cd5abaa27d1824d8b293d0aff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Mon, 18 Jan 2021 16:49:01 +0000 Subject: [PATCH] [FIX] mail, im_livechat, snailmail: use findFromIdentifyingData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit find is O(n) and findFromIdentifyingData is O(1) task-2440693 closes odoo/odoo#64745 X-original-commit: e995f03a9a55280b1e9173223cdfa619ae164cc3 Signed-off-by: Alexandre Kühn (aku) --- .../src/components/discuss/discuss_tests.js | 8 +- .../thread_icon/thread_icon_tests.js | 8 +- .../thread_textual_typing_status_tests.js | 8 +- .../components/attachment/attachment_tests.js | 2 +- .../attachment_box/attachment_box_tests.js | 4 +- .../chat_window_manager_tests.js | 150 ++++----- .../src/components/chatter/chatter_tests.js | 8 +- .../src/components/composer/composer_tests.js | 96 +++--- .../discuss/tests/discuss_moderation_tests.js | 84 ++--- .../discuss/tests/discuss_pinned_tests.js | 35 ++- .../components/discuss/tests/discuss_tests.js | 296 +++++++++--------- .../src/components/message/message_tests.js | 2 +- .../message_seen_indicator.js | 22 +- .../messaging_menu/messaging_menu_tests.js | 64 ++-- .../thread_icon/thread_icon_tests.js | 8 +- .../thread_textual_typing_status_tests.js | 40 +-- .../src/models/attachment/attachment_tests.js | 40 +-- .../src/models/message/message_tests.js | 58 ++-- .../messaging_notification_handler.js | 26 +- .../mail/static/src/models/thread/thread.js | 12 +- .../static/src/models/thread/thread_tests.js | 66 ++-- .../discuss_invite_partner_dialog.js | 6 +- .../src/components/message/message_tests.js | 2 +- 23 files changed, 525 insertions(+), 520 deletions(-) diff --git a/addons/im_livechat/static/src/components/discuss/discuss_tests.js b/addons/im_livechat/static/src/components/discuss/discuss_tests.js index c756f2dff93..4cfd207ff1c 100644 --- a/addons/im_livechat/static/src/components/discuss/discuss_tests.js +++ b/addons/im_livechat/static/src/components/discuss/discuss_tests.js @@ -57,10 +57,10 @@ QUnit.test('livechat in the sidebar: basic rendering', async function (assert) { ); const livechat = groupLivechat.querySelector(` .o_DiscussSidebarItem[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 11 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 11, + model: 'mail.channel', + }).localId }"] `); assert.ok( diff --git a/addons/im_livechat/static/src/components/thread_icon/thread_icon_tests.js b/addons/im_livechat/static/src/components/thread_icon/thread_icon_tests.js index 6be180805bc..3d9316cf65b 100644 --- a/addons/im_livechat/static/src/components/thread_icon/thread_icon_tests.js +++ b/addons/im_livechat/static/src/components/thread_icon/thread_icon_tests.js @@ -50,10 +50,10 @@ QUnit.test('livechat: public website visitor is typing', async function (assert) members: [this.data.currentPartnerId, this.data.publicPartnerId], }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadIcon(thread); assert.containsOnce( document.body, diff --git a/addons/im_livechat/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js b/addons/im_livechat/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js index 452b2c1e794..87aa5d61f75 100644 --- a/addons/im_livechat/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js +++ b/addons/im_livechat/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js @@ -50,10 +50,10 @@ QUnit.test('receive visitor typing status "is typing"', async function (assert) members: [this.data.currentPartnerId, this.data.publicPartnerId], }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadTextualTypingStatusComponent(thread); assert.strictEqual( diff --git a/addons/mail/static/src/components/attachment/attachment_tests.js b/addons/mail/static/src/components/attachment/attachment_tests.js index 1c97ac4b628..0698aafe227 100644 --- a/addons/mail/static/src/components/attachment/attachment_tests.js +++ b/addons/mail/static/src/components/attachment/attachment_tests.js @@ -65,7 +65,7 @@ QUnit.test('simplest layout', async function (assert) { const attachmentEl = document.querySelector('.o_Attachment'); assert.strictEqual( attachmentEl.dataset.attachmentLocalId, - this.env.models['mail.attachment'].find(attachment => attachment.id === 750).localId, + this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 }).localId, "attachment component should be linked to attachment store model" ); assert.strictEqual( diff --git a/addons/mail/static/src/components/attachment_box/attachment_box_tests.js b/addons/mail/static/src/components/attachment_box/attachment_box_tests.js index 885742b72cc..142eb804102 100644 --- a/addons/mail/static/src/components/attachment_box/attachment_box_tests.js +++ b/addons/mail/static/src/components/attachment_box/attachment_box_tests.js @@ -228,9 +228,7 @@ QUnit.test('view attachments', async function (assert) { id: 100, model: 'res.partner', }); - const firstAttachment = this.env.models['mail.attachment'].find( - attachment => attachment.id === 143 - ); + const firstAttachment = this.env.models['mail.attachment'].findFromIdentifyingData({ id: 143 }); await this.createAttachmentBoxComponent(thread); await afterNextRender(() => diff --git a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js index 3b221971d0e..1da10ea91d7 100644 --- a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js +++ b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js @@ -445,10 +445,10 @@ QUnit.test('chat window: basic rendering', async function (assert) { const chatWindow = document.querySelector(`.o_ChatWindow`); assert.strictEqual( chatWindow.dataset.threadLocalId, - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId, + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId, "should have open a chat window of channel" ); assert.strictEqual( @@ -936,10 +936,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -951,10 +951,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', assert.strictEqual( document.querySelectorAll(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -963,10 +963,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', assert.ok( document.querySelector(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).classList.contains('o-focused'), "chat window of chat should have focus" @@ -977,10 +977,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -992,10 +992,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', assert.strictEqual( document.querySelectorAll(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -1004,10 +1004,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', assert.strictEqual( document.querySelectorAll(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -1016,10 +1016,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', assert.ok( document.querySelector(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).classList.contains('o-focused'), "chat window of channel should have focus" @@ -1027,10 +1027,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', assert.notOk( document.querySelector(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).classList.contains('o-focused'), "chat window of chat should no longer have focus" @@ -1285,10 +1285,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 1 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 1, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -1315,10 +1315,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 2 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 2, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -1345,10 +1345,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 3 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 3, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -1370,10 +1370,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct assert.strictEqual( document.querySelectorAll(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 1 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 1, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -1382,10 +1382,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct assert.strictEqual( document.querySelectorAll(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 3 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 3, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -1394,10 +1394,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct assert.ok( document.querySelector(` .o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 3 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 3, + model: 'mail.channel', + }).localId }"] `).classList.contains('o-focused'), "chat window of channel 3 should have focus" @@ -1422,10 +1422,10 @@ QUnit.test('chat window: switch on TAB', async function (assert) { document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 1 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 1, + model: 'mail.channel', + }).localId }"]` ).click() ); @@ -1463,10 +1463,10 @@ QUnit.test('chat window: switch on TAB', async function (assert) { document.querySelector(` .o_MessagingMenu_dropdownMenu .o_NotificationList_preview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 2 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 2, + model: 'mail.channel', + }).localId }"]` ).click() ); @@ -1958,9 +1958,10 @@ QUnit.test('chat window does not fetch messages if hidden', async function (asse assert.containsNone( document.body, `.o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(t => - t.model === 'mail.channel' && t.id === 12 - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"]`, "chat window for Channel #12 should be hidden" ); @@ -1995,9 +1996,10 @@ QUnit.test('chat window does not fetch messages if hidden', async function (asse assert.containsOnce( document.body, `.o_ChatWindow[data-thread-local-id="${ - this.env.models['mail.thread'].find(t => - t.model === 'mail.channel' && t.id === 12 - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"]`, "chat window for Channel #12 should now be visible" ); diff --git a/addons/mail/static/src/components/chatter/chatter_tests.js b/addons/mail/static/src/components/chatter/chatter_tests.js index 24ff6c5da2f..15163e85709 100644 --- a/addons/mail/static/src/components/chatter/chatter_tests.js +++ b/addons/mail/static/src/components/chatter/chatter_tests.js @@ -89,10 +89,10 @@ QUnit.test('base rendering when chatter has no attachment', async function (asse ); assert.strictEqual( document.querySelector(`.o_Chatter_thread`).dataset.threadLocalId, - this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'res.partner' - ).localId, + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'res.partner', + }).localId, "thread should have the right thread local id" ); assert.strictEqual( diff --git a/addons/mail/static/src/components/composer/composer_tests.js b/addons/mail/static/src/components/composer/composer_tests.js index b83a17ab4e8..b93670aaf97 100644 --- a/addons/mail/static/src/components/composer/composer_tests.js +++ b/addons/mail/static/src/components/composer/composer_tests.js @@ -206,10 +206,10 @@ QUnit.test('mailing channel composer: basic rendering', async function (assert) // value and a random unique id that will be referenced in the test this.data['mail.channel'].records.push({ id: 20, mass_mailing: true }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer); assert.containsOnce( document.body, @@ -1325,10 +1325,10 @@ QUnit.test('send message when enter is pressed while holding ctrl key (this shor return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { textInputSendShortcuts: ['ctrl-enter'], }); @@ -1380,10 +1380,10 @@ QUnit.test('send message when enter is pressed while holding meta key (this shor return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { textInputSendShortcuts: ['meta-enter'], }); @@ -1434,10 +1434,10 @@ QUnit.test('composer text input cleared on message post', async function (assert return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer); // Type message await afterNextRender(() => { @@ -1494,10 +1494,10 @@ QUnit.test('composer inputs cleared on message post in composer of a mailing cha return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer); // Type message await afterNextRender(() => { @@ -1544,10 +1544,10 @@ QUnit.test('composer with thread typing notification status', async function (as // with a random unique id that will be referenced in the test this.data['mail.channel'].records.push({ id: 20 }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { hasThreadTyping: true }); assert.containsOnce( @@ -1576,10 +1576,10 @@ QUnit.test('current partner notify is typing to other thread members', async fun return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { hasThreadTyping: true }); document.querySelector(`.o_ComposerTextInput_textarea`).focus(); @@ -1608,10 +1608,10 @@ QUnit.test('current partner is typing should not translate on textual typing sta return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { hasThreadTyping: true }); document.querySelector(`.o_ComposerTextInput_textarea`).focus(); @@ -1647,10 +1647,10 @@ QUnit.test('current partner notify no longer is typing to thread members after 5 return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { hasThreadTyping: true }); document.querySelector(`.o_ComposerTextInput_textarea`).focus(); @@ -1685,10 +1685,10 @@ QUnit.test('current partner notify is typing again to other members every 50s of return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { hasThreadTyping: true }); document.querySelector(`.o_ComposerTextInput_textarea`).focus(); @@ -2042,10 +2042,10 @@ QUnit.test('send message only once when button send is clicked twice quickly', a return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer); // Type message await afterNextRender(() => { @@ -2075,10 +2075,10 @@ QUnit.test('send message only once when enter is pressed twice quickly', async f return this._super(...arguments); }, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createComposerComponent(thread.composer, { textInputSendShortcuts: ['enter'], }); diff --git a/addons/mail/static/src/components/discuss/tests/discuss_moderation_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_moderation_tests.js index 2afd997a42b..c4c53cb568e 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_moderation_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_moderation_tests.js @@ -217,10 +217,10 @@ QUnit.test('as moderator, moderated channel with pending moderation message', as await afterNextRender(() => document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -355,14 +355,14 @@ QUnit.test('as moderator, accept pending moderation message', async function (as assert.ok( document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `), "should display the message to moderate" ); const acceptButton = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_moderationAction.o-accept `); @@ -379,10 +379,10 @@ QUnit.test('as moderator, accept pending moderation message', async function (as // 2. go to channel 'general' const channel = document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `); assert.ok( @@ -393,7 +393,7 @@ QUnit.test('as moderator, accept pending moderation message', async function (as await afterNextRender(() => channel.click()); const message = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); assert.ok( @@ -474,7 +474,7 @@ QUnit.test('as moderator, reject pending moderation message (reject with explana await afterNextRender(() => moderationBox.click()); const pendingMessage = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); assert.ok( @@ -553,10 +553,10 @@ QUnit.test('as moderator, reject pending moderation message (reject with explana // 2. go to channel 'general' const channel = document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `); assert.ok( @@ -616,7 +616,7 @@ QUnit.test('as moderator, discard pending moderation message (reject without exp await afterNextRender(() => moderationBox.click()); const pendingMessage = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); assert.ok( @@ -670,10 +670,10 @@ QUnit.test('as moderator, discard pending moderation message (reject without exp // 2. go to channel 'general' const channel = document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `); assert.ok( @@ -700,10 +700,10 @@ QUnit.test('as author, send message in moderated channel', async function (asser await this.start(); const channel = document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `); assert.ok( @@ -757,10 +757,10 @@ QUnit.test('as author, sent message accepted in moderated channel', async functi const channel = document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `); assert.ok( @@ -771,7 +771,7 @@ QUnit.test('as author, sent message accepted in moderated channel', async functi await afterNextRender(() => channel.click()); const messagePending = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_moderationPending `); @@ -798,7 +798,7 @@ QUnit.test('as author, sent message accepted in moderated channel', async functi // check message is accepted const message = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); assert.ok( @@ -831,10 +831,10 @@ QUnit.test('as author, sent message rejected in moderated channel', async functi const channel = document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `); assert.ok( @@ -845,7 +845,7 @@ QUnit.test('as author, sent message rejected in moderated channel', async functi await afterNextRender(() => channel.click()); const messagePending = document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_moderationPending `); @@ -894,7 +894,7 @@ QUnit.test('as moderator, pending moderation message accessibility', async funct }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => thread.id === 20 && thread.model === 'mail.channel'); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel' }); assert.ok( document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ @@ -909,7 +909,7 @@ QUnit.test('as moderator, pending moderation message accessibility', async funct .o_DiscussSidebar_item[data-thread-local-id="${thread.localId}"] `).click() ); - const message = this.env.models['mail.message'].find(message => message.id === 100); + const message = this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }); assert.containsOnce( document.body, `.o_Message[data-message-local-id="${message.localId}"]`, @@ -946,14 +946,14 @@ QUnit.test('as author, pending moderation message should appear in origin thread res_id: 20, // id of the channel }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => thread.id === 20 && thread.model === 'mail.channel'); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel' }); await afterNextRender(() => document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${thread.localId}"] `).click() ); - const message = this.env.models['mail.message'].find(message => message.id === 100); + const message = this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }); assert.containsOnce( document.body, `.o_Message[data-message-local-id="${message.localId}"]`, @@ -971,7 +971,7 @@ QUnit.test('as moderator, new pending moderation message posted by someone else' moderation: true, // channel must be moderated to test the feature }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => thread.id === 20 && thread.model === 'mail.channel'); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel' }); await afterNextRender(() => document.querySelector(` @@ -1001,7 +1001,7 @@ QUnit.test('as moderator, new pending moderation message posted by someone else' ]]; this.widget.call('bus_service', 'trigger', 'notification', notifications); }); - const message = this.env.models['mail.message'].find(message => message.id === 1); + const message = this.env.models['mail.message'].findFromIdentifyingData({ id: 1 }); assert.containsOnce( document.body, `.o_Message[data-message-local-id="${message.localId}"]`, diff --git a/addons/mail/static/src/components/discuss/tests/discuss_pinned_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_pinned_tests.js index 108e7a28d1d..a24ce411a5c 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_pinned_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_pinned_tests.js @@ -45,9 +45,10 @@ QUnit.test('sidebar: pinned channel 1: init with one pinned channel', async func assert.containsOnce( document.body, `.o_DiscussSidebarItem[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"]`, "should have the only channel of which user is member in discuss sidebar" ); @@ -61,9 +62,10 @@ QUnit.test('sidebar: pinned channel 2: open pinned channel', async function (ass this.data['mail.channel'].records.push({ id: 20 }); await this.start(); - const threadGeneral = this.env.models['mail.thread'].find(thread => - thread.id === 20 && thread.model === 'mail.channel' - ); + const threadGeneral = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await afterNextRender(() => document.querySelector(`.o_DiscussSidebarItem[data-thread-local-id="${ threadGeneral.localId @@ -104,9 +106,10 @@ QUnit.test('sidebar: pinned channel 3: open pinned channel and unpin it', async }, }); - const threadGeneral = this.env.models['mail.thread'].find(thread => - thread.id === 20 && thread.model === 'mail.channel' - ); + const threadGeneral = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await afterNextRender(() => document.querySelector(`.o_DiscussSidebarItem[data-thread-local-id="${ threadGeneral.localId @@ -142,9 +145,10 @@ QUnit.test('sidebar: unpin channel from bus', async function (assert) { // with a random unique id that will be referenced in the test this.data['mail.channel'].records.push({ id: 20 }); await this.start(); - const threadGeneral = this.env.models['mail.thread'].find(thread => - thread.id === 20 && thread.model === 'mail.channel' - ); + const threadGeneral = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); assert.containsOnce( document.body, @@ -211,9 +215,10 @@ QUnit.test('[technical] sidebar: channel group_based_subscription: mandatorily p is_pinned: false, // expected value for this test }); await this.start(); - const threadGeneral = this.env.models['mail.thread'].find(thread => - thread.id === 20 && thread.model === 'mail.channel' - ); + const threadGeneral = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); assert.containsOnce( document.body, `.o_DiscussSidebarItem[data-thread-local-id="${threadGeneral.localId}"]`, 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 9695d8d005a..97b826487cd 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -438,10 +438,10 @@ QUnit.test('sidebar: basic channel rendering', async function (assert) { `); assert.strictEqual( channel.dataset.threadLocalId, - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId, + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId, "should have channel with Id 20" ); assert.strictEqual( @@ -589,10 +589,10 @@ QUnit.test('sidebar: public/private channel rendering', async function (assert) document.querySelectorAll(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -602,10 +602,10 @@ QUnit.test('sidebar: public/private channel rendering', async function (assert) document.querySelectorAll(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 101 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 101, + model: 'mail.channel' + }).localId }"] `).length, 1, @@ -614,19 +614,19 @@ QUnit.test('sidebar: public/private channel rendering', async function (assert) const channel1 = document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel' + }).localId }"] `); const channel2 = document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 101 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 101, + model: 'mail.channel' + }).localId }"] `); assert.strictEqual( @@ -663,10 +663,10 @@ QUnit.test('sidebar: basic chat rendering', async function (assert) { const chat = document.querySelector(`.o_DiscussSidebar_groupChat .o_DiscussSidebar_item`); assert.strictEqual( chat.dataset.threadLocalId, - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId, + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel' + }).localId, "should have chat with Id 10" ); assert.strictEqual( @@ -796,10 +796,10 @@ QUnit.test('sidebar: chat im_status rendering', async function (assert) { document.querySelectorAll(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 11 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 11, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -809,10 +809,10 @@ QUnit.test('sidebar: chat im_status rendering', async function (assert) { document.querySelectorAll(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -822,10 +822,10 @@ QUnit.test('sidebar: chat im_status rendering', async function (assert) { document.querySelectorAll(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 13 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 13, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -834,28 +834,28 @@ QUnit.test('sidebar: chat im_status rendering', async function (assert) { const chat1 = document.querySelector(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 11 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 11, + model: 'mail.channel', + }).localId }"] `); const chat2 = document.querySelector(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"] `); const chat3 = document.querySelector(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 13 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 13, + model: 'mail.channel', + }).localId }"] `); assert.strictEqual( @@ -998,10 +998,10 @@ QUnit.test('default thread rendering', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -1088,20 +1088,20 @@ QUnit.test('default thread rendering', async function (assert) { await afterNextRender(() => document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).click() ); assert.ok( document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).classList.contains('o-active'), "channel 20 should be active thread" @@ -1246,7 +1246,7 @@ QUnit.test('load single message from channel initially', async function (assert) document.querySelectorAll(` .o_Discuss_thread .o_MessageList_message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `).length, 1, @@ -1305,7 +1305,7 @@ QUnit.test('basic rendering of message', async function (assert) { .o_Discuss_thread .o_ThreadView_messageList .o_MessageList_message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); assert.strictEqual( @@ -1426,14 +1426,14 @@ QUnit.test('basic rendering of squashed message', async function (assert) { .o_Discuss_thread .o_ThreadView_messageList .o_MessageList_message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); const message2 = document.querySelector(` .o_Discuss_thread .o_ThreadView_messageList .o_MessageList_message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] `); assert.notOk( @@ -1532,14 +1532,14 @@ QUnit.test('inbox messages are never squashed', async function (assert) { .o_Discuss_thread .o_ThreadView_messageList .o_MessageList_message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); const message2 = document.querySelector(` .o_Discuss_thread .o_ThreadView_messageList .o_MessageList_message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] `); assert.notOk( @@ -2020,10 +2020,10 @@ QUnit.test('restore thread scroll position', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"] `).click(); }, @@ -2052,10 +2052,10 @@ QUnit.test('restore thread scroll position', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 11 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 11, + model: 'mail.channel', + }).localId }"] `).click(); }, @@ -2081,10 +2081,10 @@ QUnit.test('restore thread scroll position', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"] `).click(); }, @@ -2145,7 +2145,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `).length, 1, @@ -2155,7 +2155,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] `).length, 1, @@ -2165,7 +2165,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_originThread `).length, @@ -2176,7 +2176,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] .o_Message_originThread `).length, @@ -2187,7 +2187,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelector(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] .o_Message_originThread `).textContent.trim(), @@ -2198,7 +2198,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] .o_Message_originThreadLink `).length, @@ -2211,7 +2211,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelector(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] .o_Message_originThreadLink `).click() @@ -2220,10 +2220,10 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_activeIndicator `).classList.contains('o-item-active'), @@ -2238,7 +2238,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `).length, 1, @@ -2248,7 +2248,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] `).length, 1, @@ -2258,7 +2258,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_originThread `).length, @@ -2269,7 +2269,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] .o_Message_originThread `).length, @@ -2280,7 +2280,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelector(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_originThread `).textContent.trim(), @@ -2291,7 +2291,7 @@ QUnit.test('message origin redirect to channel', async function (assert) { document.querySelectorAll(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] .o_Message_originThreadLink `).length, @@ -2342,10 +2342,10 @@ QUnit.test('redirect to author (open chat)', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 1 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 1, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_activeIndicator `).classList.contains('o-item-active'), @@ -2355,10 +2355,10 @@ QUnit.test('redirect to author (open chat)', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_activeIndicator `).classList.contains('o-item-active'), @@ -2372,7 +2372,7 @@ QUnit.test('redirect to author (open chat)', async function (assert) { const msg1 = document.querySelector(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `); assert.strictEqual( @@ -2392,10 +2392,10 @@ QUnit.test('redirect to author (open chat)', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 1 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 1, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_activeIndicator `).classList.contains('o-item-active'), @@ -2405,10 +2405,10 @@ QUnit.test('redirect to author (open chat)', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChat .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_activeIndicator `).classList.contains('o-item-active'), @@ -2463,10 +2463,10 @@ QUnit.test('sidebar quick search', async function (assert) { document.querySelector(` .o_DiscussSidebar_groupChannel .o_DiscussSidebar_item `).dataset.threadLocalId, - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId, + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 12, + model: 'mail.channel', + }).localId, "should have filtered to a single channel item with Id 12" ); @@ -2533,10 +2533,10 @@ QUnit.test('basic control panel rendering', async function (assert) { await afterNextRender(() => document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).click() ); @@ -2606,10 +2606,10 @@ QUnit.test('inbox: mark all messages as read', async function (assert) { assert.strictEqual( document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_counter `).textContent, @@ -2641,10 +2641,10 @@ QUnit.test('inbox: mark all messages as read', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] .o_DiscussSidebarItem_counter `).length, @@ -2945,7 +2945,7 @@ QUnit.test('composer state: attachments save and restore', async function (asser ); assert.strictEqual( document.querySelector(`.o_Composer .o_Attachment`).dataset.attachmentLocalId, - this.env.models['mail.attachment'].find(attachment => attachment.id === 1).localId, + this.env.models['mail.attachment'].findFromIdentifyingData({ id: 1 }).localId, "should have correct 1st attachment in the composer" ); @@ -2959,17 +2959,17 @@ QUnit.test('composer state: attachments save and restore', async function (asser ); assert.strictEqual( document.querySelectorAll(`.o_Composer .o_Attachment`)[0].dataset.attachmentLocalId, - this.env.models['mail.attachment'].find(attachment => attachment.id === 2).localId, + this.env.models['mail.attachment'].findFromIdentifyingData({ id: 2 }).localId, "should have attachment with id 2 as 1st attachment" ); assert.strictEqual( document.querySelectorAll(`.o_Composer .o_Attachment`)[1].dataset.attachmentLocalId, - this.env.models['mail.attachment'].find(attachment => attachment.id === 3).localId, + this.env.models['mail.attachment'].findFromIdentifyingData({ id: 3 }).localId, "should have attachment with id 3 as 2nd attachment" ); assert.strictEqual( document.querySelectorAll(`.o_Composer .o_Attachment`)[2].dataset.attachmentLocalId, - this.env.models['mail.attachment'].find(attachment => attachment.id === 4).localId, + this.env.models['mail.attachment'].findFromIdentifyingData({ id: 4 }).localId, "should have attachment with id 4 as 3rd attachment" ); }); @@ -3060,7 +3060,7 @@ QUnit.test('post a simple message', async function (assert) { const message = document.querySelector(`.o_Message`); assert.strictEqual( message.dataset.messageLocalId, - this.env.models['mail.message'].find(message => message.id === postedMessageId).localId, + this.env.models['mail.message'].findFromIdentifyingData({ id: postedMessageId }).localId, "new message in thread should be linked to newly created message from message post" ); assert.strictEqual( @@ -3450,7 +3450,7 @@ QUnit.test('receive new needaction messages', async function (assert) { ); assert.strictEqual( document.querySelector(`.o_Discuss_thread .o_Message`).dataset.messageLocalId, - this.env.models['mail.message'].find(message => message.id === 100).localId, + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId, "should display newly received needaction message" ); @@ -3485,7 +3485,7 @@ QUnit.test('receive new needaction messages', async function (assert) { document.querySelector(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `), "should still display 1st needaction message" @@ -3494,7 +3494,7 @@ QUnit.test('receive new needaction messages', async function (assert) { document.querySelector(` .o_Discuss_thread .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 101).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 101 }).localId }"] `), "should display 2nd needaction message" @@ -3557,7 +3557,7 @@ QUnit.test('reply to message from inbox (message linked to document)', async fun ); assert.strictEqual( document.querySelector('.o_Message').dataset.messageLocalId, - this.env.models['mail.message'].find(message => message.id === 100).localId, + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId, "should display message with ID 100" ); assert.strictEqual( @@ -3606,7 +3606,7 @@ QUnit.test('reply to message from inbox (message linked to document)', async fun ); assert.strictEqual( document.querySelector('.o_Message').dataset.messageLocalId, - this.env.models['mail.message'].find(message => message.id === 100).localId, + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId, "should still display message with ID 100 after posting reply" ); assert.notOk( @@ -3652,7 +3652,7 @@ QUnit.test('load recent messages from thread (already loaded some old messages)' ); assert.strictEqual( document.querySelector('.o_Message').dataset.messageLocalId, - this.env.models['mail.message'].find(message => message.id === 100).localId, + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId, "the only message initially should be the one marked as 'needaction'" ); @@ -3661,10 +3661,10 @@ QUnit.test('load recent messages from thread (already loaded some old messages)' func: () => { document.querySelector(` .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).click(); }, @@ -3687,7 +3687,7 @@ QUnit.test('load recent messages from thread (already loaded some old messages)' assert.strictEqual( document.querySelectorAll(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `).length, 1, @@ -3714,7 +3714,7 @@ QUnit.test('load recent messages from thread (already loaded some old messages)' assert.strictEqual( document.querySelectorAll(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 100).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId }"] `).length, 1, @@ -3927,7 +3927,7 @@ QUnit.test('mark a single message as read should only move this message to "Hist await afterNextRender(() => document.querySelector(` .o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 1).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 1 }).localId }"] .o_Message_commandMarkAsRead `).click() ); @@ -3939,7 +3939,7 @@ QUnit.test('mark a single message as read should only move this message to "Hist assert.containsOnce( document.body, `.o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 2).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 2 }).localId }"]`, "message still in inbox should be the one not marked as read" ); @@ -3968,7 +3968,7 @@ QUnit.test('mark a single message as read should only move this message to "Hist assert.containsOnce( document.body, `.o_Message[data-message-local-id="${ - this.env.models['mail.message'].find(message => message.id === 1).localId + this.env.models['mail.message'].findFromIdentifyingData({ id: 1 }).localId }"]`, "message moved in history should be the one marked as read" ); diff --git a/addons/mail/static/src/components/message/message_tests.js b/addons/mail/static/src/components/message/message_tests.js index 73403d71eee..8aaf1d2a268 100644 --- a/addons/mail/static/src/components/message/message_tests.js +++ b/addons/mail/static/src/components/message/message_tests.js @@ -62,7 +62,7 @@ QUnit.test('basic rendering', async function (assert) { const messageEl = document.querySelector('.o_Message'); assert.strictEqual( messageEl.dataset.messageLocalId, - this.env.models['mail.message'].find(message => message.id === 100).localId, + this.env.models['mail.message'].findFromIdentifyingData({ id: 100 }).localId, "message component should be linked to message store model" ); assert.strictEqual( diff --git a/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js b/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js index 8c5239c9e2d..9a3d9172cd1 100644 --- a/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js +++ b/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js @@ -15,11 +15,12 @@ class MessageSeenIndicator extends Component { useStore(props => { const message = this.env.models['mail.message'].get(props.messageLocalId); const thread = this.env.models['mail.thread'].get(props.threadLocalId); - const messageSeenIndicator = this.env.models['mail.message_seen_indicator'].find( - messageSeenIndicator => - messageSeenIndicator.message === message && - messageSeenIndicator.thread === thread - ); + const messageSeenIndicator = thread && thread.model === 'mail.channel' + ? this.env.models['mail.message_seen_indicator'].findFromIdentifyingData({ + channelId: thread.id, + messageId: message.id, + }) + : undefined; return { messageSeenIndicator: messageSeenIndicator ? messageSeenIndicator.__state : undefined, }; @@ -103,10 +104,13 @@ class MessageSeenIndicator extends Component { * @returns {mail.message_seen_indicator} */ get messageSeenIndicator() { - return this.env.models['mail.message_seen_indicator'].find(messageSeenIndicator => - messageSeenIndicator.message === this.message && - messageSeenIndicator.thread === this.thread - ); + if (!this.thread || this.thread.model !== 'mail.channel') { + return undefined; + } + return this.env.models['mail.message_seen_indicator'].findFromIdentifyingData({ + channelId: this.thread.id, + messageId: this.message.id, + }); } /** diff --git a/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js b/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js index 8224c088611..d049ab7a5b3 100644 --- a/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js +++ b/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js @@ -621,10 +621,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -634,10 +634,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -656,10 +656,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -669,10 +669,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).length, 0, @@ -694,10 +694,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).length, 0, @@ -707,10 +707,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -729,10 +729,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 10 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 10, + model: 'mail.channel', + }).localId }"] `).length, 1, @@ -742,10 +742,10 @@ QUnit.test('filtered previews', async function (assert) { document.querySelectorAll(` .o_MessagingMenu_dropdownMenu .o_ThreadPreview[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ).localId + this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }).localId }"] `).length, 1, diff --git a/addons/mail/static/src/components/thread_icon/thread_icon_tests.js b/addons/mail/static/src/components/thread_icon/thread_icon_tests.js index 21966cc206f..d233d6f88a8 100644 --- a/addons/mail/static/src/components/thread_icon/thread_icon_tests.js +++ b/addons/mail/static/src/components/thread_icon/thread_icon_tests.js @@ -54,10 +54,10 @@ QUnit.test('chat: correspondent is typing', async function (assert) { members: [this.data.currentPartnerId, 17], }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadIcon(thread); assert.containsOnce( diff --git a/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js b/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js index 4c525d193fa..284ca788ff6 100644 --- a/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js +++ b/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js @@ -49,10 +49,10 @@ QUnit.test('receive other member typing status "is typing"', async function (ass members: [this.data.currentPartnerId, 17], }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadTextualTypingStatusComponent(thread); assert.strictEqual( @@ -88,10 +88,10 @@ QUnit.test('receive other member typing status "is typing" then "no longer is ty members: [this.data.currentPartnerId, 17], }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadTextualTypingStatusComponent(thread); assert.strictEqual( @@ -146,10 +146,10 @@ QUnit.test('assume other member typing status becomes "no longer is typing" afte await this.start({ hasTimeControl: true, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadTextualTypingStatusComponent(thread); assert.strictEqual( @@ -194,10 +194,10 @@ QUnit.test ('other member typing status "is typing" refreshes 60 seconds timer o await this.start({ hasTimeControl: true, }); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadTextualTypingStatusComponent(thread); assert.strictEqual( @@ -262,10 +262,10 @@ QUnit.test('receive several other members typing status "is typing"', async func members: [this.data.currentPartnerId, 10, 11, 12], }); await this.start(); - const thread = this.env.models['mail.thread'].find(thread => - thread.id === 20 && - thread.model === 'mail.channel' - ); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel', + }); await this.createThreadTextualTypingStatusComponent(thread); assert.strictEqual( diff --git a/addons/mail/static/src/models/attachment/attachment_tests.js b/addons/mail/static/src/models/attachment/attachment_tests.js index bdb0115de09..089a1acd164 100644 --- a/addons/mail/static/src/models/attachment/attachment_tests.js +++ b/addons/mail/static/src/models/attachment/attachment_tests.js @@ -27,7 +27,7 @@ QUnit.test('create (txt)', async function (assert) { assert.expect(9); await this.start(); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); const attachment = this.env.models['mail.attachment'].create({ filename: "test.txt", @@ -36,8 +36,8 @@ QUnit.test('create (txt)', async function (assert) { name: "test.txt", }); assert.ok(attachment); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.strictEqual(this.env.models['mail.attachment'].find(attachment => attachment.id === 750), attachment); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.strictEqual(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 }), attachment); assert.strictEqual(attachment.filename, "test.txt"); assert.strictEqual(attachment.id, 750); assert.notOk(attachment.isUploading); @@ -49,7 +49,7 @@ QUnit.test('displayName', async function (assert) { assert.expect(5); await this.start(); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); const attachment = this.env.models['mail.attachment'].create({ filename: "test.txt", @@ -58,8 +58,8 @@ QUnit.test('displayName', async function (assert) { name: "test.txt", }); assert.ok(attachment); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.strictEqual(attachment, this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.strictEqual(attachment, this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); assert.strictEqual(attachment.displayName, "test.txt"); }); @@ -67,7 +67,7 @@ QUnit.test('extension', async function (assert) { assert.expect(5); await this.start(); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); const attachment = this.env.models['mail.attachment'].create({ filename: "test.txt", @@ -76,8 +76,8 @@ QUnit.test('extension', async function (assert) { name: "test.txt", }); assert.ok(attachment); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.strictEqual(attachment, this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.strictEqual(attachment, this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); assert.strictEqual(attachment.extension, 'txt'); }); @@ -85,7 +85,7 @@ QUnit.test('fileType', async function (assert) { assert.expect(5); await this.start(); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); const attachment = this.env.models['mail.attachment'].create({ filename: "test.txt", @@ -94,10 +94,10 @@ QUnit.test('fileType', async function (assert) { name: "test.txt", }); assert.ok(attachment); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.strictEqual(attachment, this.env.models['mail.attachment'].find(attachment => - attachment.id === 750) - ); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.strictEqual(attachment, this.env.models['mail.attachment'].findFromIdentifyingData({ + id: 750, + })); assert.strictEqual(attachment.fileType, 'text'); }); @@ -105,7 +105,7 @@ QUnit.test('isTextFile', async function (assert) { assert.expect(5); await this.start(); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); const attachment = this.env.models['mail.attachment'].create({ filename: "test.txt", @@ -114,8 +114,8 @@ QUnit.test('isTextFile', async function (assert) { name: "test.txt", }); assert.ok(attachment); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.strictEqual(attachment, this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.strictEqual(attachment, this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); assert.ok(attachment.isTextFile); }); @@ -123,7 +123,7 @@ QUnit.test('isViewable', async function (assert) { assert.expect(5); await this.start(); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); const attachment = this.env.models['mail.attachment'].create({ filename: "test.txt", @@ -132,8 +132,8 @@ QUnit.test('isViewable', async function (assert) { name: "test.txt", }); assert.ok(attachment); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.strictEqual(attachment, this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.strictEqual(attachment, this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); assert.ok(attachment.isViewable); }); diff --git a/addons/mail/static/src/models/message/message_tests.js b/addons/mail/static/src/models/message/message_tests.js index 92ac23d08a6..febf839552f 100644 --- a/addons/mail/static/src/models/message/message_tests.js +++ b/addons/mail/static/src/models/message/message_tests.js @@ -29,13 +29,13 @@ QUnit.test('create', async function (assert) { assert.expect(31); await this.start(); - assert.notOk(this.env.models['mail.partner'].find(partner => partner.id === 5)); - assert.notOk(this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )); - assert.notOk(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.notOk(this.env.models['mail.message'].find(message => message.id === 4000)); + assert.notOk(this.env.models['mail.partner'].findFromIdentifyingData({ id: 5 })); + assert.notOk(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })); + assert.notOk(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.notOk(this.env.models['mail.message'].findFromIdentifyingData({ id: 4000 })); const thread = this.env.models['mail.thread'].create({ id: 100, @@ -58,16 +58,16 @@ QUnit.test('create', async function (assert) { originThread: [['link', thread]], }); - assert.ok(this.env.models['mail.partner'].find(partner => partner.id === 5)); - assert.ok(this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )); - assert.ok(this.env.models['mail.attachment'].find(attachment => attachment.id === 750)); - assert.ok(this.env.models['mail.message'].find(message => message.id === 4000)); + assert.ok(this.env.models['mail.partner'].findFromIdentifyingData({ id: 5 })); + assert.ok(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })); + assert.ok(this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 })); + assert.ok(this.env.models['mail.message'].findFromIdentifyingData({ id: 4000 })); assert.ok(message); - assert.strictEqual(this.env.models['mail.message'].find(message => message.id === 4000), message); + assert.strictEqual(this.env.models['mail.message'].findFromIdentifyingData({ id: 4000 }), message); assert.strictEqual(message.body, "

Test

"); assert.ok(message.date instanceof moment); assert.strictEqual( @@ -75,36 +75,36 @@ QUnit.test('create', async function (assert) { "2019-05-05 10:00:00" ); assert.strictEqual(message.id, 4000); - assert.strictEqual(message.originThread, this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )); + assert.strictEqual(message.originThread, this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })); assert.ok( - message.threads.includes(this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )) + message.threads.includes(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })) ); // from partnerId being in needaction_partner_ids assert.ok(message.threads.includes(this.env.messaging.inbox)); // from partnerId being in starred_partner_ids assert.ok(message.threads.includes(this.env.messaging.starred)); - const attachment = this.env.models['mail.attachment'].find(attachment => attachment.id === 750); + const attachment = this.env.models['mail.attachment'].findFromIdentifyingData({ id: 750 }); assert.ok(attachment); assert.strictEqual(attachment.filename, "test.txt"); assert.strictEqual(attachment.id, 750); assert.notOk(attachment.isUploading); assert.strictEqual(attachment.mimetype, 'text/plain'); assert.strictEqual(attachment.name, "test.txt"); - const channel = this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - ); + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + }); assert.ok(channel); assert.strictEqual(channel.model, 'mail.channel'); assert.strictEqual(channel.id, 100); assert.strictEqual(channel.name, "General"); - const partner = this.env.models['mail.partner'].find(partner => partner.id === 5); + const partner = this.env.models['mail.partner'].findFromIdentifyingData({ id: 5 }); assert.ok(partner); assert.strictEqual(partner.display_name, "Demo"); assert.strictEqual(partner.id, 5); diff --git a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js index 2c484cf96a6..537007dc29c 100644 --- a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js @@ -505,7 +505,7 @@ function factory(dependencies) { _handleNotificationPartnerDeletion({ message_ids }) { const moderationMailbox = this.env.messaging.moderation; for (const id of message_ids) { - const message = this.env.models['mail.message'].find(message => message.id === id); + const message = this.env.models['mail.message'].findFromIdentifyingData({ id }); if (message) { if ( message.moderation_status === 'pending_moderation' && @@ -558,7 +558,7 @@ function factory(dependencies) { // Furthermore, server should not send back all message_ids marked as read // but something like last read message_id or something like that. // (just imagine you mark 1000 messages as read ... ) - const message = this.env.models['mail.message'].find(m => m.id === message_id); + const message = this.env.models['mail.message'].findFromIdentifyingData({ id: message_id }); if (message) { message.update({ isNeedaction: false, @@ -571,10 +571,10 @@ function factory(dependencies) { let channels; if (channel_ids) { channels = channel_ids - .map(id => this.env.models['mail.thread'].find(thread => - thread.id === id && - thread.model === 'mail.channel' - )) + .map(id => this.env.models['mail.thread'].findFromIdentifyingData({ + id, + model: 'mail.channel', + })) .filter(thread => !!thread); } else { // flux specific: channel_ids unset means "mark all as read" @@ -617,9 +617,9 @@ function factory(dependencies) { _handleNotificationPartnerToggleStar({ message_ids = [], starred }) { const starredMailbox = this.env.messaging.starred; for (const messageId of message_ids) { - const message = this.env.models['mail.message'].find(message => - message.id === messageId - ); + const message = this.env.models['mail.message'].findFromIdentifyingData({ + id: messageId, + }); if (!message) { continue; } @@ -662,10 +662,10 @@ function factory(dependencies) { * @param {integer} channelId */ _handleNotificationPartnerUnsubscribe(channelId) { - const channel = this.env.models['mail.thread'].find(thread => - thread.id === channelId && - thread.model === 'mail.channel' - ); + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ + id: channelId, + model: 'mail.channel', + }); if (!channel) { return; } diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index b62c4752a3f..f208147ba91 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -547,14 +547,10 @@ function factory(dependencies) { * @returns {mail.thread_cache} */ cache(stringifiedDomain = '[]') { - let cache = this.caches.find(cache => cache.stringifiedDomain === stringifiedDomain); - if (!cache) { - cache = this.env.models['mail.thread_cache'].create({ - stringifiedDomain, - thread: [['link', this]], - }); - } - return cache; + return this.env.models['mail.thread_cache'].insert({ + stringifiedDomain, + thread: [['link', this]], + }); } /** diff --git a/addons/mail/static/src/models/thread/thread_tests.js b/addons/mail/static/src/models/thread/thread_tests.js index 8f9efe0111f..a535cf4e72f 100644 --- a/addons/mail/static/src/models/thread/thread_tests.js +++ b/addons/mail/static/src/models/thread/thread_tests.js @@ -45,12 +45,12 @@ QUnit.test('create (channel)', async function (assert) { assert.expect(23); await this.start(); - assert.notOk(this.env.models['mail.partner'].find(partner => partner.id === 9)); - assert.notOk(this.env.models['mail.partner'].find(partner => partner.id === 10)); - assert.notOk(this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )); + assert.notOk(this.env.models['mail.partner'].findFromIdentifyingData({ id: 9 })); + assert.notOk(this.env.models['mail.partner'].findFromIdentifyingData({ id: 10 })); + assert.notOk(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })); const thread = this.env.models['mail.thread'].create({ channel_type: 'channel', @@ -71,18 +71,18 @@ QUnit.test('create (channel)', async function (assert) { serverMessageUnreadCounter: 5, }); assert.ok(thread); - assert.ok(this.env.models['mail.partner'].find(partner => partner.id === 9)); - assert.ok(this.env.models['mail.partner'].find(partner => partner.id === 10)); - assert.ok(this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )); - const partner9 = this.env.models['mail.partner'].find(partner => partner.id === 9); - const partner10 = this.env.models['mail.partner'].find(partner => partner.id === 10); - assert.strictEqual(thread, this.env.models['mail.thread'].find(thread => - thread.id === 100 && - thread.model === 'mail.channel' - )); + assert.ok(this.env.models['mail.partner'].findFromIdentifyingData({ id: 9 })); + assert.ok(this.env.models['mail.partner'].findFromIdentifyingData({ id: 10 })); + assert.ok(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })); + const partner9 = this.env.models['mail.partner'].findFromIdentifyingData({ id: 9 }); + const partner10 = this.env.models['mail.partner'].findFromIdentifyingData({ id: 10 }); + assert.strictEqual(thread, this.env.models['mail.thread'].findFromIdentifyingData({ + id: 100, + model: 'mail.channel', + })); assert.strictEqual(thread.model, 'mail.channel'); assert.strictEqual(thread.channel_type, 'channel'); assert.strictEqual(thread.id, 100); @@ -104,11 +104,11 @@ QUnit.test('create (chat)', async function (assert) { assert.expect(15); await this.start(); - assert.notOk(this.env.models['mail.partner'].find(partner => partner.id === 5)); - assert.notOk(this.env.models['mail.thread'].find(thread => - thread.id === 200 && - thread.model === 'mail.channel' - )); + assert.notOk(this.env.models['mail.partner'].findFromIdentifyingData({ id: 5 })); + assert.notOk(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 200, + model: 'mail.channel', + })); const channel = this.env.models['mail.thread'].create({ channel_type: 'chat', @@ -122,16 +122,16 @@ QUnit.test('create (chat)', async function (assert) { model: 'mail.channel', }); assert.ok(channel); - assert.ok(this.env.models['mail.thread'].find(thread => - thread.id === 200 && - thread.model === 'mail.channel' - )); - assert.ok(this.env.models['mail.partner'].find(partner => partner.id === 5)); - const partner = this.env.models['mail.partner'].find(partner => partner.id === 5); - assert.strictEqual(channel, this.env.models['mail.thread'].find(thread => - thread.id === 200 && - thread.model === 'mail.channel' - )); + assert.ok(this.env.models['mail.thread'].findFromIdentifyingData({ + id: 200, + model: 'mail.channel', + })); + assert.ok(this.env.models['mail.partner'].findFromIdentifyingData({ id: 5 })); + const partner = this.env.models['mail.partner'].findFromIdentifyingData({ id: 5 }); + assert.strictEqual(channel, this.env.models['mail.thread'].findFromIdentifyingData({ + id: 200, + model: 'mail.channel', + })); assert.strictEqual(channel.model, 'mail.channel'); assert.strictEqual(channel.channel_type, 'chat'); assert.strictEqual(channel.id, 200); diff --git a/addons/mail/static/src/widgets/discuss_invite_partner_dialog/discuss_invite_partner_dialog.js b/addons/mail/static/src/widgets/discuss_invite_partner_dialog/discuss_invite_partner_dialog.js index 29040a27dce..9a009a120d7 100644 --- a/addons/mail/static/src/widgets/discuss_invite_partner_dialog/discuss_invite_partner_dialog.js +++ b/addons/mail/static/src/widgets/discuss_invite_partner_dialog/discuss_invite_partner_dialog.js @@ -57,9 +57,9 @@ const PartnerInviteDialog = Dialog.extend({ if (item.id === 'odoobot') { status = 'bot'; } else { - const partner = this.env.models['mail.partner'].find(partner => - partner.id === item.id - ); + const partner = this.env.models['mail.partner'].findFromIdentifyingData({ + id: item.id, + }); status = partner.im_status; } const $status = QWeb.render('mail.widgets.UserStatus', { status }); diff --git a/addons/snailmail/static/src/components/message/message_tests.js b/addons/snailmail/static/src/components/message/message_tests.js index 69c16c571f5..67044509812 100644 --- a/addons/snailmail/static/src/components/message/message_tests.js +++ b/addons/snailmail/static/src/components/message/message_tests.js @@ -638,7 +638,7 @@ QUnit.test('Missing Required Fields', async function (assert) { hasThreadView: true, thread: [['insert', { id: 20, model: 'res.partner' }]], }); - const message = this.env.models['mail.message'].find(message => message.id === 10); + const message = this.env.models['mail.message'].findFromIdentifyingData({ id: 10 }); await this.createMessageComponent(message, { threadViewLocalId: threadViewer.threadView.localId, });