From ff49527fb56677fb828dc8fd261f173473cc362e Mon Sep 17 00:00:00 2001 From: "Louis Wicket (wil)" Date: Wed, 31 Aug 2022 09:01:31 +0000 Subject: [PATCH] [IMP] mail, *: convert ThreadPreview to use Channel instead of Thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * = im_livechat, rating, test_mail_full Part of task-2948676. closes odoo/odoo#99342 Related: odoo/enterprise#30921 Signed-off-by: Alexandre Kühn (aku) --- .../channel_preview_view.js | 25 ----- .../static/src/models/channel_preview_view.js | 17 ++++ .../src/models/notification_list_view.js | 9 +- .../components/messaging_menu_tests.js | 4 +- .../channel_preview_view.js | 31 ++---- .../channel_preview_view.xml | 69 +++++++------ .../notification_list/notification_list.xml | 4 +- addons/mail/static/src/models/channel.js | 4 + .../static/src/models/channel_preview_view.js | 40 +++++--- .../src/models/message_author_prefix_view.js | 20 ++-- .../src/models/notification_list_view.js | 98 +++++++++---------- .../src/models/persona_im_status_icon_view.js | 22 ++--- addons/mail/static/src/models/thread.js | 4 - .../components/channel_preview_view_tests.js | 8 +- .../components/chat_window_manager_tests.js | 20 ++-- .../components/messaging_menu_tests.js | 82 ++++++++-------- .../components/notification_list_tests.js | 18 ++-- .../models/file_uploader_tests.js | 2 +- .../channel_preview_view.scss | 2 +- .../channel_preview_view.xml | 10 +- .../static/src/models/channel_preview_view.js | 6 +- .../channel_preview_view_tests.js | 8 +- 22 files changed, 244 insertions(+), 259 deletions(-) delete mode 100644 addons/im_livechat/static/src/components/channel_preview_view/channel_preview_view.js create mode 100644 addons/im_livechat/static/src/models/channel_preview_view.js diff --git a/addons/im_livechat/static/src/components/channel_preview_view/channel_preview_view.js b/addons/im_livechat/static/src/components/channel_preview_view/channel_preview_view.js deleted file mode 100644 index aa9fb0fa9f9..00000000000 --- a/addons/im_livechat/static/src/components/channel_preview_view/channel_preview_view.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @odoo-module **/ - -import { ThreadPreview } from '@mail/components/channel_preview_view/channel_preview_view'; - -import { patch } from 'web.utils'; - -const components = { ThreadPreview }; - -patch(components.ThreadPreview.prototype, 'im_livechat/static/src/components/channel_preview_view/channel_preview_view.js', { - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * @override - */ - image(...args) { - if (this.threadPreviewView.thread.channel.channel_type === 'livechat') { - return '/mail/static/src/img/smiley/avatar.jpg'; - } - return this._super(...args); - } - -}); diff --git a/addons/im_livechat/static/src/models/channel_preview_view.js b/addons/im_livechat/static/src/models/channel_preview_view.js new file mode 100644 index 00000000000..87c26838ea3 --- /dev/null +++ b/addons/im_livechat/static/src/models/channel_preview_view.js @@ -0,0 +1,17 @@ +/** @odoo-module **/ + +import { patchRecordMethods } from '@mail/model/model_core'; +// ensure that the model definition is loaded before the patch +import '@mail/models/channel_preview_view'; + +patchRecordMethods('ChannelPreviewView', { + /** + * @override + */ + _computeImageUrl() { + if (this.channel.channel_type === 'livechat') { + return '/mail/static/src/img/smiley/avatar.jpg'; + } + return this._super(); + }, +}); diff --git a/addons/im_livechat/static/src/models/notification_list_view.js b/addons/im_livechat/static/src/models/notification_list_view.js index 39958c35787..a2179669648 100644 --- a/addons/im_livechat/static/src/models/notification_list_view.js +++ b/addons/im_livechat/static/src/models/notification_list_view.js @@ -7,12 +7,11 @@ patchRecordMethods('NotificationListView', { /** * @override */ - _computeFilteredThreads() { + _computeFilteredChannels() { if (this.filter === 'livechat') { - return this.messaging.models['Thread'].all(thread => - thread.channel && - thread.channel.channel_type === 'livechat' && - thread.isPinned + return this.messaging.models['Channel'].all(channel => + channel.channel_type === 'livechat' && + channel.thread.isPinned ); } return this._super(); diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js index 06c5423666e..2191dbe0a35 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js @@ -48,7 +48,7 @@ QUnit.test('livechats should be in "chat" filter', async function (assert) { ); assert.containsOnce( document.body, - `.o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"]`, + `.o_ChannelPreviewView[data-channel-id="${mailChannelId1}"]`, "livechat should be listed in 'all' tab/filter of messaging menu" ); @@ -62,7 +62,7 @@ QUnit.test('livechats should be in "chat" filter', async function (assert) { ); assert.containsOnce( document.body, - `.o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"]`, + `.o_ChannelPreviewView[data-channel-id="${mailChannelId1}"]`, "livechat should be listed in 'chat' tab/filter of messaging menu" ); }); diff --git a/addons/mail/static/src/components/channel_preview_view/channel_preview_view.js b/addons/mail/static/src/components/channel_preview_view/channel_preview_view.js index 0ac07e567a8..1b8165ecc8b 100644 --- a/addons/mail/static/src/components/channel_preview_view/channel_preview_view.js +++ b/addons/mail/static/src/components/channel_preview_view/channel_preview_view.js @@ -5,7 +5,7 @@ import { registerMessagingComponent } from '@mail/utils/messaging_component'; const { Component } = owl; -export class ThreadPreview extends Component { +export class ChannelPreviewView extends Component { /** * @override @@ -15,37 +15,18 @@ export class ThreadPreview extends Component { useRefToModel({ fieldName: 'markAsReadRef', refName: 'markAsRead' }); } - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - /** - * Get the image route of the thread. - * - * @returns {string} + * @returns {ChannelPreviewView} */ - image() { - if (!this.threadPreviewView.thread.channel) { - return '/mail/static/src/img/smiley/avatar.jpg'; - } - if (this.threadPreviewView.thread.channel.correspondent) { - return this.threadPreviewView.thread.channel.correspondent.avatarUrl; - } - return `/web/image/mail.channel/${this.threadPreviewView.thread.id}/avatar_128?unique=${this.threadPreviewView.thread.channel.avatarCacheKey}`; - } - - /** - * @returns {ThreadPreviewView} - */ - get threadPreviewView() { + get channelPreviewView() { return this.props.record; } } -Object.assign(ThreadPreview, { +Object.assign(ChannelPreviewView, { props: { record: Object }, - template: 'mail.ThreadPreview', + template: 'mail.ChannelPreviewView', }); -registerMessagingComponent(ThreadPreview); +registerMessagingComponent(ChannelPreviewView); diff --git a/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml b/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml index 6fae3a1333e..1c898ca68e7 100644 --- a/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml +++ b/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml @@ -1,71 +1,70 @@ - - + + -
-
-
- Thread Image - +
+
+ Thread Image +
-
-
- - +
+
+ + - - - () + + + () - - + + - - - + + +
-
- - - +
+ + + - - + + - + - - + +
diff --git a/addons/mail/static/src/components/notification_list/notification_list.xml b/addons/mail/static/src/components/notification_list/notification_list.xml index fabe5c02825..857360b6b59 100644 --- a/addons/mail/static/src/components/notification_list/notification_list.xml +++ b/addons/mail/static/src/components/notification_list/notification_list.xml @@ -11,8 +11,8 @@ - - + { + if (c1.localMessageUnreadCounter > 0 && c2.localMessageUnreadCounter === 0) { + return -1; + } + if (c1.localMessageUnreadCounter === 0 && c2.localMessageUnreadCounter > 0) { + return 1; + } + if (c1.thread.lastMessage && c2.thread.lastMessage) { + return c1.thread.lastMessage.id < c2.thread.lastMessage.id ? 1 : -1; + } + if (c1.thread.lastMessage) { + return -1; + } + if (c2.thread.lastMessage) { + return 1; + } + return c1.id < c2.id ? -1 : 1; + }) + .map(channel => ({ channel })); + }, /** * @private * @returns {string|FieldCommand} @@ -28,32 +54,30 @@ registerModel({ }, /** * @private - * @returns {FieldCommand} + * @returns {Channel[]|FieldCommand} */ - _computeFilteredThreads() { + _computeFilteredChannels() { switch (this.filter) { case 'channel': { - return this.messaging.models['Thread'] - .all(thread => - thread.channel && - thread.channel.channel_type === 'channel' && - thread.isPinned + return this.messaging.models['Channel'] + .all(channel => + channel.channel_type === 'channel' && + channel.thread.isPinned ) .sort((c1, c2) => c1.displayName < c2.displayName ? -1 : 1); } case 'chat': { - return this.messaging.models['Thread'] - .all(thread => - thread.isChatChannel && - thread.isPinned && - thread.model === 'mail.channel' + return this.messaging.models['Channel'] + .all(channel => + channel.thread.isChatChannel && + channel.thread.isPinned ) .sort((c1, c2) => c1.displayName < c2.displayName ? -1 : 1); } case 'all': { // "All" filter is for channels and chats - return this.messaging.models['Thread'] - .all(thread => thread.isPinned && thread.model === 'mail.channel') + return this.messaging.models['Channel'] + .all(channel => channel.thread.isPinned) .sort((c1, c2) => c1.displayName < c2.displayName ? -1 : 1); } } @@ -90,7 +114,7 @@ registerModel({ } notifications.push(...this.notificationGroupViews); notifications.push(...this.threadNeedactionPreviewViews); - notifications.push(...this.threadPreviewViews); + notifications.push(...this.channelPreviewViews); return notifications; }, /** @@ -123,32 +147,6 @@ registerModel({ }) .map(thread => ({ thread })); }, - /** - * @private - * @returns {FieldCommand} - */ - _computeThreadPreviewViews() { - return this.filteredThreads - .sort((t1, t2) => { - if (t1.channel.localMessageUnreadCounter > 0 && t2.channel.localMessageUnreadCounter === 0) { - return -1; - } - if (t1.channel.localMessageUnreadCounter === 0 && t2.channel.localMessageUnreadCounter > 0) { - return 1; - } - if (t1.lastMessage && t2.lastMessage) { - return t1.lastMessage.id < t2.lastMessage.id ? 1 : -1; - } - if (t1.lastMessage) { - return -1; - } - if (t2.lastMessage) { - return 1; - } - return t1.id < t2.id ? -1 : 1; - }) - .map(thread => ({ thread })); - }, /** * Load previews of given thread. Basically consists of fetching all missing * last messages of each thread. @@ -156,12 +154,17 @@ registerModel({ * @private */ async _loadPreviews() { - const threads = this.threadPreviewViews - .map(threadPreviewView => threadPreviewView.thread); + const threads = this.channelPreviewViews + .map(channelPreviewView => channelPreviewView.thread); this.messaging.models['Thread'].loadPreviews(threads); }, }, fields: { + channelPreviewViews: many('ChannelPreviewView', { + compute: '_computeChannelPreviewViews', + inverse: 'notificationListViewOwner', + isCausal: true, + }), discussOwner: one('Discuss', { identifying: true, inverse: 'notificationListView', @@ -169,8 +172,8 @@ registerModel({ filter: attr({ compute: '_computeFilter', }), - filteredThreads: many('Thread', { - compute: '_computeFilteredThreads', + filteredChannels: many('Channel', { + compute: '_computeFilteredChannels', }), messagingMenuOwner: one('MessagingMenu', { identifying: true, @@ -195,10 +198,5 @@ registerModel({ inverse: 'notificationListViewOwner', isCausal: true, }), - threadPreviewViews: many('ThreadPreviewView', { - compute: '_computeThreadPreviewViews', - inverse: 'notificationListViewOwner', - isCausal: true, - }), }, }); diff --git a/addons/mail/static/src/models/persona_im_status_icon_view.js b/addons/mail/static/src/models/persona_im_status_icon_view.js index d24b82a9b9e..75e71ec814a 100644 --- a/addons/mail/static/src/models/persona_im_status_icon_view.js +++ b/addons/mail/static/src/models/persona_im_status_icon_view.js @@ -19,6 +19,9 @@ registerModel({ if (this.channelMemberViewOwner) { return this.channelMemberViewOwner.channelMember.persona; } + if (this.channelPreviewViewOwner) { + return this.channelPreviewViewOwner.channel.correspondent.persona; + } if (this.composerSuggestionViewOwner) { return this.composerSuggestionViewOwner.suggestable.partner.persona; } @@ -36,9 +39,6 @@ registerModel({ if (this.threadNeedactionPreviewViewOwner) { return this.threadNeedactionPreviewViewOwner.thread.channel.correspondent.persona; } - if (this.threadPreviewViewOwner) { - return this.threadPreviewViewOwner.thread.channel.correspondent.persona; - } return clear(); }, }, @@ -51,6 +51,10 @@ registerModel({ identifying: true, inverse: 'personaImStatusIconView', }), + channelPreviewViewOwner: one('ChannelPreviewView', { + identifying: true, + inverse: 'personaImStatusIconView', + }), composerSuggestionViewOwner: one('ComposerSuggestionView', { identifying: true, inverse: 'personaImStatusIconView', @@ -63,17 +67,13 @@ registerModel({ identifying: true, inverse: 'personaImStatusIconView', }), - threadNeedactionPreviewViewOwner: one('ThreadNeedactionPreviewView', { - identifying: true, - inverse: 'personaImStatusIconView', - }), - threadPreviewViewOwner: one('ThreadPreviewView', { - identifying: true, - inverse: 'personaImStatusIconView', - }), persona: one('Persona', { compute: '_computePersona', required: true, }), + threadNeedactionPreviewViewOwner: one('ThreadNeedactionPreviewView', { + identifying: true, + inverse: 'personaImStatusIconView', + }), }, }); diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index 5f1eeb37759..d4c4b0a4a91 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -2110,10 +2110,6 @@ registerModel({ inverse: 'thread', isCausal: true, }), - threadPreviewViews: many('ThreadPreviewView', { - inverse: 'thread', - isCausal: true, - }), /** * Members that are currently typing something in the composer of this * thread, including current partner. diff --git a/addons/mail/static/tests/qunit_suite_tests/components/channel_preview_view_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/channel_preview_view_tests.js index b325ffac682..1080b6ccafe 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/channel_preview_view_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/channel_preview_view_tests.js @@ -39,23 +39,23 @@ QUnit.test('mark as read', async function (assert) { await click('.o_MessagingMenu_toggler'); assert.containsOnce( document.body, - '.o_ThreadPreview_markAsRead', + '.o_ChannelPreviewView_markAsRead', "should have the mark as read button" ); - await click('.o_ThreadPreview_markAsRead'); + await click('.o_ChannelPreviewView_markAsRead'); assert.verifySteps( ['set_last_seen_message'], "should have marked the thread as seen" ); assert.hasClass( - document.querySelector('.o_ThreadPreview'), + document.querySelector('.o_ChannelPreviewView'), 'o-muted', "should be muted once marked as read" ); assert.containsNone( document.body, - '.o_ThreadPreview_markAsRead', + '.o_ChannelPreviewView_markAsRead', "should no longer have the mark as read button" ); assert.containsNone( diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js index 67d6ae8110d..3ee17f98183 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js @@ -274,7 +274,7 @@ QUnit.test('open chat from "new message" chat window should open chat in place o // open channel-2 await click(`.o_MessagingMenu_toggler`); - await click(`.o_NotificationListItem[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"]`); + await click(`.o_ChannelPreviewView[data-channel-id="${mailChannelId2}"]`); assert.containsN( document.body, '.o_ChatWindow', @@ -1015,7 +1015,7 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `); assert.strictEqual( document.querySelectorAll(`.o_ChatWindow`).length, @@ -1039,7 +1039,7 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]', await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `); assert.strictEqual( document.querySelectorAll(`.o_ChatWindow`).length, @@ -1106,7 +1106,7 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `); assert.strictEqual( document.querySelectorAll(`.o_ChatWindow`).length, @@ -1127,7 +1127,7 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `); assert.strictEqual( document.querySelectorAll(`.o_ChatWindow`).length, @@ -1148,7 +1148,7 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId3}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId3}"] `); assert.strictEqual( document.querySelectorAll(`.o_ChatWindow`).length, @@ -1197,7 +1197,7 @@ QUnit.test('chat window: switch on TAB', async function (assert) { await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"]` + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"]` ); assert.containsOnce(document.body, '.o_ChatWindow', "Only 1 chatWindow must be opened"); @@ -1229,7 +1229,7 @@ QUnit.test('chat window: switch on TAB', async function (assert) { await click(`.o_MessagingMenu_toggler`); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"]` + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"]` ); assert.containsN(document.body, '.o_ChatWindow', 2, "2 chatWindows must be opened"); @@ -1955,12 +1955,12 @@ QUnit.test('should not have chat window hidden menu in mobile (transition from 2 await click('.o_MessagingMenu_toggler'); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `); await click('.o_ChatWindowHeader_commandBack'); await click(` .o_MessagingMenu_dropdownMenu - .o_NotificationList_preview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `); // simulate resize to go into mobile await afterNextRender( diff --git a/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js index 5e13203ba2d..786db8aaf57 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js @@ -440,7 +440,7 @@ QUnit.test('channel preview: basic rendering', async function (assert) { await click(`.o_MessagingMenu_toggler`); assert.strictEqual( document.querySelectorAll(` - .o_MessagingMenu_dropdownMenu .o_ThreadPreview + .o_MessagingMenu_dropdownMenu .o_ChannelPreviewView `).length, 1, "should have one preview" @@ -448,7 +448,7 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_sidebar + .o_ChannelPreviewView_sidebar `).length, 1, "preview should have a sidebar" @@ -456,7 +456,7 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_content + .o_ChannelPreviewView_content `).length, 1, "preview should have some content" @@ -464,7 +464,7 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_header + .o_ChannelPreviewView_header `).length, 1, "preview should have header in content" @@ -472,8 +472,8 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_header - .o_ThreadPreview_name + .o_ChannelPreviewView_header + .o_ChannelPreviewView_name `).length, 1, "preview should have name in header of content" @@ -481,15 +481,15 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelector(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_name + .o_ChannelPreviewView_name `).textContent, "General", "preview should have name of channel" ); assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_content - .o_ThreadPreview_core + .o_ChannelPreviewView_content + .o_ChannelPreviewView_core `).length, 1, "preview should have core in content" @@ -497,8 +497,8 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_core - .o_ThreadPreview_inlineText + .o_ChannelPreviewView_core + .o_ChannelPreviewView_inlineText `).length, 1, "preview should have inline text in core of content" @@ -506,8 +506,8 @@ QUnit.test('channel preview: basic rendering', async function (assert) { assert.strictEqual( document.querySelector(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview_core - .o_ThreadPreview_inlineText + .o_ChannelPreviewView_core + .o_ChannelPreviewView_inlineText `).textContent.trim(), "Demo: test", "preview should have message content as inline text of core content" @@ -536,14 +536,14 @@ QUnit.test('filtered previews', async function (assert) { await click(`.o_MessagingMenu_toggler`); assert.strictEqual( - document.querySelectorAll(`.o_MessagingMenu_dropdownMenu .o_ThreadPreview`).length, + document.querySelectorAll(`.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView`).length, 2, "should have 2 previews" ); assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `).length, 1, "should have preview of chat" @@ -551,7 +551,7 @@ QUnit.test('filtered previews', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `).length, 1, "should have preview of channel" @@ -559,14 +559,14 @@ QUnit.test('filtered previews', async function (assert) { await click('.o_MessagingMenuTab[data-tab-id="chat"]'); assert.strictEqual( - document.querySelectorAll(`.o_MessagingMenu_dropdownMenu .o_ThreadPreview`).length, + document.querySelectorAll(`.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView`).length, 1, "should have one preview" ); assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `).length, 1, "should have preview of chat" @@ -574,7 +574,7 @@ QUnit.test('filtered previews', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `).length, 0, "should not have preview of channel" @@ -584,7 +584,7 @@ QUnit.test('filtered previews', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview + .o_ChannelPreviewView `).length, 1, "should have one preview" @@ -592,7 +592,7 @@ QUnit.test('filtered previews', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `).length, 0, "should not have preview of chat" @@ -600,7 +600,7 @@ QUnit.test('filtered previews', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `).length, 1, "should have preview of channel" @@ -608,14 +608,14 @@ QUnit.test('filtered previews', async function (assert) { await click('.o_MessagingMenuTab[data-tab-id="all"]'); assert.strictEqual( - document.querySelectorAll(`.o_MessagingMenu_dropdownMenu .o_ThreadPreview`).length, + document.querySelectorAll(`.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView`).length, 2, "should have 2 previews" ); assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `).length, 1, "should have preview of chat" @@ -623,7 +623,7 @@ QUnit.test('filtered previews', async function (assert) { assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId2}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId2}"] `).length, 1, "should have preview of channel" @@ -638,7 +638,7 @@ QUnit.test('open chat window from preview', async function (assert) { const { click } = await start(); await click(`.o_MessagingMenu_toggler`); - await click(`.o_MessagingMenu_dropdownMenu .o_ThreadPreview`); + await click(`.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView`); assert.strictEqual( document.querySelectorAll(`.o_ChatWindow`).length, 1, @@ -661,27 +661,27 @@ QUnit.test('no code injection in message body preview', async function (assert) await click(`.o_MessagingMenu_toggler`); assert.containsOnce( document.body, - '.o_MessagingMenu_dropdownMenu .o_ThreadPreview', + '.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView', "should display a preview", ); assert.containsOnce( document.body, - '.o_ThreadPreview_core', + '.o_ChannelPreviewView_core', "preview should have core in content", ); assert.containsOnce( document.body, - '.o_ThreadPreview_inlineText', + '.o_ChannelPreviewView_inlineText', "preview should have inline text in core of content", ); assert.strictEqual( - document.querySelector('.o_ThreadPreview_inlineText') + document.querySelector('.o_ChannelPreviewView_inlineText') .textContent.replace(/\s/g, ""), "You:&shoulnotberaisedthrownewError('CodeInjectionError');", "should display correct uninjected last message inline content" ); assert.containsNone( - document.querySelector('.o_ThreadPreview_inlineText'), + document.querySelector('.o_ChannelPreviewView_inlineText'), 'script', "last message inline content should not have any code injection" ); @@ -702,27 +702,27 @@ QUnit.test('no code injection in message body preview from sanitized message', a await click(`.o_MessagingMenu_toggler`); assert.containsOnce( document.body, - '.o_MessagingMenu_dropdownMenu .o_ThreadPreview', + '.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView', "should display a preview", ); assert.containsOnce( document.body, - '.o_ThreadPreview_core', + '.o_ChannelPreviewView_core', "preview should have core in content", ); assert.containsOnce( document.body, - '.o_ThreadPreview_inlineText', + '.o_ChannelPreviewView_inlineText', "preview should have inline text in core of content", ); assert.strictEqual( - document.querySelector('.o_ThreadPreview_inlineText') + document.querySelector('.o_ChannelPreviewView_inlineText') .textContent.replace(/\s/g, ""), "You:&shoulnotberaised", "should display correct uninjected last message inline content" ); assert.containsNone( - document.querySelector('.o_ThreadPreview_inlineText'), + document.querySelector('.o_ChannelPreviewView_inlineText'), 'script', "last message inline content should not have any code injection" ); @@ -743,21 +743,21 @@ QUnit.test('
tags in message body preview are transformed in spaces', async await click(`.o_MessagingMenu_toggler`); assert.containsOnce( document.body, - '.o_MessagingMenu_dropdownMenu .o_ThreadPreview', + '.o_MessagingMenu_dropdownMenu .o_ChannelPreviewView', "should display a preview", ); assert.containsOnce( document.body, - '.o_ThreadPreview_core', + '.o_ChannelPreviewView_core', "preview should have core in content", ); assert.containsOnce( document.body, - '.o_ThreadPreview_inlineText', + '.o_ChannelPreviewView_inlineText', "preview should have inline text in core of content", ); assert.strictEqual( - document.querySelector('.o_ThreadPreview_inlineText').textContent, + document.querySelector('.o_ChannelPreviewView_inlineText').textContent, "You: a b c d", "should display correct last message inline content with brs replaced by spaces" ); @@ -902,7 +902,7 @@ QUnit.test('Group chat should be displayed inside the chat section of the messag assert.strictEqual( document.querySelectorAll(` .o_MessagingMenu_dropdownMenu - .o_ThreadPreview[data-thread-id="${mailChannelId1}"][data-thread-model="mail.channel"] + .o_ChannelPreviewView[data-channel-id="${mailChannelId1}"] `).length, 1, "should have one preview of group" diff --git a/addons/mail/static/tests/qunit_suite_tests/components/notification_list_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/notification_list_tests.js index 1d666d34f32..de4abe58265 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/notification_list_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/notification_list_tests.js @@ -30,18 +30,18 @@ QUnit.test('marked as read thread notifications are ordered by last message date await click('.o_MessagingMenu_toggler'); assert.containsN( document.body, - '.o_ThreadPreview', + '.o_ChannelPreviewView', 2, "there should be two thread previews" ); - const threadPreviewElList = document.querySelectorAll('.o_ThreadPreview'); + const channelPreviewViewElList = document.querySelectorAll('.o_ChannelPreviewView'); assert.strictEqual( - threadPreviewElList[0].querySelector(':scope .o_ThreadPreview_name').textContent, + channelPreviewViewElList[0].querySelector(':scope .o_ChannelPreviewView_name').textContent, 'Channel 2020', "First channel in the list should be the channel of 2020 (more recent last message)" ); assert.strictEqual( - threadPreviewElList[1].querySelector(':scope .o_ThreadPreview_name').textContent, + channelPreviewViewElList[1].querySelector(':scope .o_ChannelPreviewView_name').textContent, 'Channel 2019', "Second channel in the list should be the channel of 2019 (least recent last message)" ); @@ -71,7 +71,7 @@ QUnit.test('thread notifications are re-ordered on receiving a new message', asy await click('.o_MessagingMenu_toggler'); assert.containsN( document.body, - '.o_ThreadPreview', + '.o_ChannelPreviewView', 2, "there should be two thread previews" ); @@ -94,18 +94,18 @@ QUnit.test('thread notifications are re-ordered on receiving a new message', asy }); assert.containsN( document.body, - '.o_ThreadPreview', + '.o_ChannelPreviewView', 2, "there should still be two thread previews" ); - const threadPreviewElList = document.querySelectorAll('.o_ThreadPreview'); + const channelPreviewViewElList = document.querySelectorAll('.o_ChannelPreviewView'); assert.strictEqual( - threadPreviewElList[0].querySelector(':scope .o_ThreadPreview_name').textContent, + channelPreviewViewElList[0].querySelector(':scope .o_ChannelPreviewView_name').textContent, 'Channel 2019', "First channel in the list should now be 'Channel 2019'" ); assert.strictEqual( - threadPreviewElList[1].querySelector(':scope .o_ThreadPreview_name').textContent, + channelPreviewViewElList[1].querySelector(':scope .o_ChannelPreviewView_name').textContent, 'Channel 2020', "Second channel in the list should now be 'Channel 2020'" ); diff --git a/addons/mail/static/tests/qunit_suite_tests/models/file_uploader_tests.js b/addons/mail/static/tests/qunit_suite_tests/models/file_uploader_tests.js index db7615bcacc..863fc986a62 100644 --- a/addons/mail/static/tests/qunit_suite_tests/models/file_uploader_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/models/file_uploader_tests.js @@ -42,7 +42,7 @@ QUnit.test('no conflicts between file uploaders', async function (assert) { // Uploading file in the second thread: mail.channel in chatWindow. await click(`.o_MessagingMenu_toggler`); - await click(`.o_NotificationListItem[data-thread-id="${channelId}"][data-thread-model="mail.channel"]`); + await click(`.o_ChannelPreviewView[data-channel-id="${channelId}"]`); const file2 = await createFile({ name: 'text2.txt', content: 'hello, world', diff --git a/addons/rating/static/src/components/channel_preview_view/channel_preview_view.scss b/addons/rating/static/src/components/channel_preview_view/channel_preview_view.scss index f6cf4b8f920..7568e863634 100644 --- a/addons/rating/static/src/components/channel_preview_view/channel_preview_view.scss +++ b/addons/rating/static/src/components/channel_preview_view/channel_preview_view.scss @@ -1,4 +1,4 @@ -.o_ThreadPreview_ratingImage { +.o_ChannelPreviewView_ratingImage { height: $font-size-base; width: $font-size-base; } diff --git a/addons/rating/static/src/components/channel_preview_view/channel_preview_view.xml b/addons/rating/static/src/components/channel_preview_view/channel_preview_view.xml index 8e2d503a66a..c65e28f13a7 100644 --- a/addons/rating/static/src/components/channel_preview_view/channel_preview_view.xml +++ b/addons/rating/static/src/components/channel_preview_view/channel_preview_view.xml @@ -1,10 +1,10 @@ - - - - Rating: - + + + + Rating: + $0 diff --git a/addons/rating/static/src/models/channel_preview_view.js b/addons/rating/static/src/models/channel_preview_view.js index bcec7b2dc25..b077e5c05dd 100644 --- a/addons/rating/static/src/models/channel_preview_view.js +++ b/addons/rating/static/src/models/channel_preview_view.js @@ -5,7 +5,7 @@ import { attr } from '@mail/model/model_field'; // ensure the model definition is loaded before the patch import '@mail/models/channel_preview_view'; -patchRecordMethods('ThreadPreviewView', { +patchRecordMethods('ChannelPreviewView', { /** * @override */ @@ -14,7 +14,7 @@ patchRecordMethods('ThreadPreviewView', { }, }); -addRecordMethods('ThreadPreviewView', { +addRecordMethods('ChannelPreviewView', { /** * @private */ @@ -23,7 +23,7 @@ addRecordMethods('ThreadPreviewView', { }, }); -addFields('ThreadPreviewView', { +addFields('ChannelPreviewView', { isRating: attr({ compute: '_computeIsRating', }), diff --git a/addons/test_mail_full/static/tests/qunit_suite_tests/channel_preview_view_tests.js b/addons/test_mail_full/static/tests/qunit_suite_tests/channel_preview_view_tests.js index 18f7c7fa41a..a3d04338563 100644 --- a/addons/test_mail_full/static/tests/qunit_suite_tests/channel_preview_view_tests.js +++ b/addons/test_mail_full/static/tests/qunit_suite_tests/channel_preview_view_tests.js @@ -31,22 +31,22 @@ QUnit.test('rating value displayed on the thread preview', async function (asser }, })); assert.strictEqual( - document.querySelector('.o_ThreadPreview_ratingText').textContent, + document.querySelector('.o_ChannelPreviewView_ratingText').textContent, "Rating:", "should display the correct content (Rating:)" ); assert.containsOnce( document.body, - '.o_ThreadPreview_ratingImage', + '.o_ChannelPreviewView_ratingImage', "should have a rating image in the body" ); assert.strictEqual( - $('.o_ThreadPreview_ratingImage').attr('data-src'), + $('.o_ChannelPreviewView_ratingImage').attr('data-src'), "/rating/static/src/img/rating_5.png", "should contain the correct rating image" ); assert.strictEqual( - $('.o_ThreadPreview_ratingImage').attr('data-alt'), + $('.o_ChannelPreviewView_ratingImage').attr('data-alt'), "top", "should contain the correct rating text" );