[IMP] mail: turn 'Discuss/orderedMailboxes' into field
Task-2793280 closes odoo/odoo#86444 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
-28
@@ -10,34 +10,6 @@ export class DiscussMobileMailboxSelection extends Component {
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @returns {Thread[]}
|
||||
*/
|
||||
get orderedMailboxes() {
|
||||
if (!this.messaging) {
|
||||
return [];
|
||||
}
|
||||
return this.messaging.models['Thread']
|
||||
.all(thread => thread.isPinned && thread.model === 'mail.box')
|
||||
.sort((mailbox1, mailbox2) => {
|
||||
if (mailbox1 === this.messaging.inbox) {
|
||||
return -1;
|
||||
}
|
||||
if (mailbox2 === this.messaging.inbox) {
|
||||
return 1;
|
||||
}
|
||||
if (mailbox1 === this.messaging.starred) {
|
||||
return -1;
|
||||
}
|
||||
if (mailbox2 === this.messaging.starred) {
|
||||
return 1;
|
||||
}
|
||||
const mailbox1Name = mailbox1.displayName;
|
||||
const mailbox2Name = mailbox2.displayName;
|
||||
mailbox1Name < mailbox2Name ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Discuss}
|
||||
*/
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
<t t-name="mail.DiscussMobileMailboxSelection" owl="1">
|
||||
<div class="o_DiscussMobileMailboxSelection" t-attf-class="{{ className }}" t-ref="root">
|
||||
<t t-foreach="orderedMailboxes" t-as="mailbox" t-key="mailbox.localId">
|
||||
<t t-foreach="discuss.orderedMailboxes" t-as="mailbox" t-key="mailbox.localId">
|
||||
<button class="o_DiscussMobileMailboxSelection_button btn btn-secondary"
|
||||
t-att-class="{
|
||||
'active o-active': discuss.thread === mailbox,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registerModel } from '@mail/model/model_core';
|
||||
import { attr, one } from '@mail/model/model_field';
|
||||
import { clear, insertAndReplace, link, unlink } from '@mail/model/model_field_command';
|
||||
import { attr, many, one } from '@mail/model/model_field';
|
||||
import { clear, insertAndReplace, link, replace, unlink } from '@mail/model/model_field_command';
|
||||
import { escape } from '@web/core/utils/strings';
|
||||
|
||||
registerModel({
|
||||
@@ -316,6 +316,35 @@ registerModel({
|
||||
_computeNotificationListView() {
|
||||
return (this.messaging.device.isMobile && this.activeMobileNavbarTabId !== 'mailbox') ? insertAndReplace() : clear();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {FieldCommand}
|
||||
*/
|
||||
_computeOrderedMailboxes() {
|
||||
if (!this.messaging) {
|
||||
return clear();
|
||||
}
|
||||
const orderedMailboxes = this.messaging.models['Thread']
|
||||
.all(thread => thread.isPinned && thread.model === 'mail.box')
|
||||
.sort((mailbox1, mailbox2) => {
|
||||
if (mailbox1 === this.messaging.inbox) {
|
||||
return -1;
|
||||
}
|
||||
if (mailbox2 === this.messaging.inbox) {
|
||||
return 1;
|
||||
}
|
||||
if (mailbox1 === this.messaging.starred) {
|
||||
return -1;
|
||||
}
|
||||
if (mailbox2 === this.messaging.starred) {
|
||||
return 1;
|
||||
}
|
||||
const mailbox1Name = mailbox1.displayName;
|
||||
const mailbox2Name = mailbox2.displayName;
|
||||
return mailbox1Name < mailbox2Name ? -1 : 1;
|
||||
});
|
||||
return replace(orderedMailboxes);
|
||||
},
|
||||
/**
|
||||
* Only pinned threads are allowed in discuss.
|
||||
*
|
||||
@@ -443,6 +472,9 @@ registerModel({
|
||||
inverse: 'discuss',
|
||||
isCausal: true,
|
||||
}),
|
||||
orderedMailboxes: many('Thread', {
|
||||
compute: '_computeOrderedMailboxes',
|
||||
}),
|
||||
/**
|
||||
* Quick search input value in the discuss sidebar (desktop). Useful
|
||||
* to filter channels and chats based on this input content.
|
||||
|
||||
Reference in New Issue
Block a user