diff --git a/addons/im_livechat/static/src/models/discuss_sidebar_category.js b/addons/im_livechat/static/src/models/discuss_sidebar_category.js index efaa41556c4..92b20c7a45e 100644 --- a/addons/im_livechat/static/src/models/discuss_sidebar_category.js +++ b/addons/im_livechat/static/src/models/discuss_sidebar_category.js @@ -14,6 +14,14 @@ addFields('DiscussSidebarCategory', { }); patchFields('DiscussSidebarCategory', { + categoryItemsOrderedByLastAction: { + compute() { + if (this.discussAsLivechat) { + return this.categoryItems; + } + return this._super(); + }, + }, isServerOpen: { compute() { // there is no server state for non-users (guests) @@ -37,18 +45,18 @@ patchFields('DiscussSidebarCategory', { return this._super(); }, }, - serverStateKey: { + orderedCategoryItems: { compute() { if (this.discussAsLivechat) { - return 'is_discuss_sidebar_category_livechat_open'; + return this.categoryItemsOrderedByLastAction; } return this._super(); }, }, - sortComputeMethod: { + serverStateKey: { compute() { if (this.discussAsLivechat) { - return 'last_action'; + return 'is_discuss_sidebar_category_livechat_open'; } return this._super(); }, diff --git a/addons/mail/static/src/models/discuss_sidebar_category.js b/addons/mail/static/src/models/discuss_sidebar_category.js index 8542271cf95..82976a5c92b 100644 --- a/addons/mail/static/src/models/discuss_sidebar_category.js +++ b/addons/mail/static/src/models/discuss_sidebar_category.js @@ -168,6 +168,49 @@ registerModel({ }, default: '', }), + /** + * Determines the discuss sidebar category items that are displayed by + * this discuss sidebar category. + */ + categoryItems: many('DiscussSidebarCategoryItem', { + inverse: 'category', + }), + categoryItemsOrderedByLastAction: many('DiscussSidebarCategoryItem', { + compute() { + if (this.discussAsChat) { + return this.categoryItems; + } + // clear if the value is not going to be used, so that it avoids + // sorting the items for nothing + return clear(); + }, + sort() { + return [ + ['truthy-first', 'thread'], + ['truthy-first', 'thread.lastInterestDateTime'], + ['most-recent-first', 'thread.lastInterestDateTime'], + ['greater-first', 'channel.id'], + ]; + }, + }), + categoryItemsOrderedByName: many('DiscussSidebarCategoryItem', { + compute() { + if (this.discussAsChannel) { + return this.categoryItems; + } + // clear if the value is not going to be used, so that it avoids + // sorting the items for nothing + return clear(); + }, + sort() { + return [ + ['truthy-first', 'thread'], + ['truthy-first', 'thread.displayName'], + ['case-insensitive-asc', 'thread.displayName'], + ['smaller-first', 'channel.id'], + ]; + }, + }), /** * The title text in UI for command `add` */ @@ -183,31 +226,6 @@ registerModel({ }, default: '', }), - /** - * Determines the discuss sidebar category items that are displayed by - * this discuss sidebar category. - */ - categoryItems: many('DiscussSidebarCategoryItem', { - inverse: 'category', - sort() { - switch (this.sortComputeMethod) { - case 'name': - return [ - ['truthy-first', 'thread'], - ['truthy-first', 'thread.displayName'], - ['case-insensitive-asc', 'thread.displayName'], - ['smaller-first', 'channel.id'], - ]; - case 'last_action': - return [ - ['truthy-first', 'thread'], - ['truthy-first', 'thread.lastInterestDateTime'], - ['most-recent-first', 'thread.lastInterestDateTime'], - ['greater-first', 'channel.id'], - ]; - } - }, - }), /** * States the total amount of unread/action-needed threads in this * category. @@ -231,7 +249,7 @@ registerModel({ */ filteredCategoryItems: many('DiscussSidebarCategoryItem', { compute() { - let categoryItems = this.categoryItems; + let categoryItems = this.orderedCategoryItems; const searchValue = this.messaging.discuss.sidebarQuickSearchValue; if (searchValue) { const qsVal = searchValue.toLowerCase(); @@ -343,6 +361,17 @@ registerModel({ return clear(); }, }), + orderedCategoryItems: many('DiscussSidebarCategoryItem', { + compute() { + if (this.discussAsChannel) { + return this.categoryItemsOrderedByName; + } + if (this.discussAsChat) { + return this.categoryItemsOrderedByLastAction; + } + return clear(); + }, + }), /** * The key used in the server side for the category state */ @@ -357,22 +386,6 @@ registerModel({ return clear(); }, }), - /** - * Determines the sorting method of channels in this category. - * Must be one of: 'name', 'last_action'. - */ - sortComputeMethod: attr({ - compute() { - if (this.discussAsChannel) { - return 'name'; - } - if (this.discussAsChat) { - return 'last_action'; - } - return clear(); - }, - required: true, - }), /** * Channel type which is supported by the category. */