diff --git a/addons/mail/static/src/core/common/record.js b/addons/mail/static/src/core/common/record.js index 7acabf05219..ad311c81103 100644 --- a/addons/mail/static/src/core/common/record.js +++ b/addons/mail/static/src/core/common/record.js @@ -29,6 +29,7 @@ export function OR(...args) { } export function makeStore(env) { + Record.UPDATE = 0; let storeReady = false; const res = { // fake store for now, until it becomes a model diff --git a/addons/mail/static/src/core/common/thread_service.js b/addons/mail/static/src/core/common/thread_service.js index ee1dce06e4a..bc214be2b3e 100644 --- a/addons/mail/static/src/core/common/thread_service.js +++ b/addons/mail/static/src/core/common/thread_service.js @@ -2,6 +2,7 @@ import { loadEmoji } from "@web/core/emoji_picker/emoji_picker"; import { DEFAULT_AVATAR } from "@mail/core/common/persona_service"; +import { Record } from "@mail/core/common/record"; import { prettifyMessageContent } from "@mail/utils/common/format"; import { browser } from "@web/core/browser/browser"; @@ -255,12 +256,14 @@ export class ThreadService { // same for needaction messages, special case for mailbox: // kinda "fetch new/more" with needactions on many origin threads at once if (thread.eq(this.store.discuss.inbox)) { - for (const message of fetched) { - const thread = message.originThread; - if (message.notIn(thread.needactionMessages)) { - thread.needactionMessages.unshift(message); + Record.MAKE_UPDATE(() => { + for (const message of fetched) { + const thread = message.originThread; + if (thread && message.notIn(thread.needactionMessages)) { + thread.needactionMessages.unshift(message); + } } - } + }); } else { const startNeedactionIndex = after === undefined @@ -329,13 +332,18 @@ export class ThreadService { } if (ids.length) { const previews = await this.orm.call("discuss.channel", "channel_fetch_preview", [ids]); - for (const preview of previews) { - const thread = this.store.Thread.get({ model: "discuss.channel", id: preview.id }); - const message = this.store.Message.insert(preview.last_message, { html: true }); - if (message.isNeedaction) { - thread.needactionMessages.add(message); + Record.MAKE_UPDATE(() => { + for (const preview of previews) { + const thread = this.store.Thread.get({ + model: "discuss.channel", + id: preview.id, + }); + const message = this.store.Message.insert(preview.last_message, { html: true }); + if (message.isNeedaction) { + thread.needactionMessages.add(message); + } } - } + }); } });