[IMP] mail, im_livechat: remove conditions from sort
This commit makes all sorts unconditional, which would allow us to get rid of the functions that wrap the sorting rules and use arrays directly instead. This will allow us to lighten the syntax and to perform some optimizations in subsequent PRs. Task-2992581. closes odoo/odoo#100895 X-original-commit: 4d15ca0f6883fb089e8d7514c4e639b86cedbd45 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Signed-off-by: Louis Wicket (wil) <wil@odoo.com>
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user