[REF] mail: move mail.message/mark_as_read to new service
Part of task-3265211 Part-of: odoo/odoo#129583
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { CannedResponse } from "@mail/core/common/canned_response_model";
|
||||
import { removeFromArray, removeFromArrayWithPredicate } from "@mail/utils/common/arrays";
|
||||
import { cleanTerm } from "@mail/utils/common/format";
|
||||
|
||||
import { markup, reactive } from "@odoo/owl";
|
||||
@@ -129,45 +128,6 @@ export class Messaging {
|
||||
handleNotification(notifications) {
|
||||
for (const notif of notifications) {
|
||||
switch (notif.type) {
|
||||
case "mail.message/mark_as_read": {
|
||||
const { message_ids: messageIds, needaction_inbox_counter } = notif.payload;
|
||||
const inbox = this.store.discuss.inbox;
|
||||
for (const messageId of messageIds) {
|
||||
// We need to ignore all not yet known messages because we don't want them
|
||||
// to be shown partially as they would be linked directly to cache.
|
||||
// Furthermore, server should not send back all messageIds marked as read
|
||||
// but something like last read messageId or something like that.
|
||||
// (just imagine you mark 1000 messages as read ... )
|
||||
const message = this.store.messages[messageId];
|
||||
if (!message) {
|
||||
continue;
|
||||
}
|
||||
// update thread counter (before removing message from Inbox, to ensure isNeedaction check is correct)
|
||||
const originThread = message.originThread;
|
||||
if (originThread && message.isNeedaction) {
|
||||
originThread.message_needaction_counter--;
|
||||
removeFromArrayWithPredicate(
|
||||
originThread.needactionMessages,
|
||||
({ id }) => id === messageId
|
||||
);
|
||||
}
|
||||
// move messages from Inbox to history
|
||||
const partnerIndex = message.needaction_partner_ids.find(
|
||||
(p) => p === this.store.user?.id
|
||||
);
|
||||
removeFromArray(message.needaction_partner_ids, partnerIndex);
|
||||
removeFromArrayWithPredicate(inbox.messages, ({ id }) => id === messageId);
|
||||
const history = this.store.discuss.history;
|
||||
if (!history.messages.includes(message)) {
|
||||
history.messages.push(message);
|
||||
}
|
||||
}
|
||||
inbox.counter = needaction_inbox_counter;
|
||||
if (inbox.counter > inbox.messages.length) {
|
||||
this.threadService.fetchMoreMessages(inbox);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "mail.message/toggle_star": {
|
||||
const { message_ids: messageIds, starred } = notif.payload;
|
||||
for (const messageId of messageIds) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { removeFromArrayWithPredicate } from "@mail/utils/common/arrays";
|
||||
import { removeFromArray, removeFromArrayWithPredicate } from "@mail/utils/common/arrays";
|
||||
|
||||
import { markup, reactive } from "@odoo/owl";
|
||||
|
||||
@@ -84,6 +84,44 @@ export class MailCoreWeb {
|
||||
thread.message_needaction_counter++;
|
||||
}
|
||||
});
|
||||
this.busService.subscribe("mail.message/mark_as_read", (payload) => {
|
||||
const { message_ids: messageIds, needaction_inbox_counter } = payload;
|
||||
const inbox = this.store.discuss.inbox;
|
||||
for (const messageId of messageIds) {
|
||||
// We need to ignore all not yet known messages because we don't want them
|
||||
// to be shown partially as they would be linked directly to cache.
|
||||
// Furthermore, server should not send back all messageIds marked as read
|
||||
// but something like last read messageId or something like that.
|
||||
// (just imagine you mark 1000 messages as read ... )
|
||||
const message = this.store.messages[messageId];
|
||||
if (!message) {
|
||||
continue;
|
||||
}
|
||||
// update thread counter (before removing message from Inbox, to ensure isNeedaction check is correct)
|
||||
const originThread = message.originThread;
|
||||
if (originThread && message.isNeedaction) {
|
||||
originThread.message_needaction_counter--;
|
||||
removeFromArrayWithPredicate(
|
||||
originThread.needactionMessages,
|
||||
({ id }) => id === messageId
|
||||
);
|
||||
}
|
||||
// move messages from Inbox to history
|
||||
const partnerIndex = message.needaction_partner_ids.find(
|
||||
(p) => p === this.store.user?.id
|
||||
);
|
||||
removeFromArray(message.needaction_partner_ids, partnerIndex);
|
||||
removeFromArrayWithPredicate(inbox.messages, ({ id }) => id === messageId);
|
||||
const history = this.store.discuss.history;
|
||||
if (!history.messages.includes(message)) {
|
||||
history.messages.push(message);
|
||||
}
|
||||
}
|
||||
inbox.counter = needaction_inbox_counter;
|
||||
if (inbox.counter > inbox.messages.length) {
|
||||
this.threadService.fetchMoreMessages(inbox);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user