diff --git a/addons/mail/static/src/core/common/chat_window_service.js b/addons/mail/static/src/core/common/chat_window_service.js index eb64efbec48..27d1453e3a2 100644 --- a/addons/mail/static/src/core/common/chat_window_service.js +++ b/addons/mail/static/src/core/common/chat_window_service.js @@ -109,7 +109,8 @@ export class ChatWindowService { chatWindow.thread.state = "folded"; } - async close(chatWindow, { escape = false } = {}) { + async close(chatWindow, options = {}) { + const { escape = false } = options; if (!chatWindow.hidden && this.maxVisible < this.store.discuss.chatWindows.length) { const swaped = this.hidden[0]; swaped.hidden = false; @@ -126,10 +127,10 @@ export class ChatWindowService { if (escape && this.store.discuss.chatWindows.length > 0) { this.focus(this.store.discuss.chatWindows[index - 1]); } - await this._onClose(chatWindow); + await this._onClose(chatWindow, options); chatWindow.delete(); } - async _onClose(chatWindow) {} + async _onClose(chatWindow, options) {} } export const chatWindowService = { diff --git a/addons/mail/static/src/core/web/chat_window_service_patch.js b/addons/mail/static/src/core/web/chat_window_service_patch.js index 67d03688a67..f6cbfe27e70 100644 --- a/addons/mail/static/src/core/web/chat_window_service_patch.js +++ b/addons/mail/static/src/core/web/chat_window_service_patch.js @@ -5,7 +5,7 @@ import { ChatWindowService } from "@mail/core/common/chat_window_service"; import { patch } from "@web/core/utils/patch"; patch(ChatWindowService.prototype, { - async _onClose(chatWindow) { + async _onClose(chatWindow, options) { if (this.ui.isSmall && !this.store.discuss.isActive) { // If we are in mobile and discuss is not open, it means the // chat window was opened from the messaging menu. In that @@ -15,6 +15,6 @@ patch(ChatWindowService.prototype, { // ensure messaging menu is opened before chat window is closed await Promise.resolve(); } - await super._onClose(...arguments); + await super._onClose(chatWindow, options); }, }); diff --git a/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js b/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js index 2017a8173ca..858046bfc37 100644 --- a/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js +++ b/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js @@ -5,9 +5,12 @@ import { ChatWindowService } from "@mail/core/common/chat_window_service"; import { patch } from "@web/core/utils/patch"; patch(ChatWindowService.prototype, { - async _onClose(chatWindow) { + async _onClose(chatWindow, options) { + const { notifyState = true } = options; await super._onClose(...arguments); - this.notifyState(chatWindow); + if (notifyState) { + this.notifyState(chatWindow); + } }, hide(chatWindow) { super.hide(...arguments); diff --git a/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js b/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js index f1ca5801cad..74c5b3e91e7 100644 --- a/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js +++ b/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js @@ -83,7 +83,7 @@ export class DiscussCoreWeb { this.store.ChatWindow.insert({ thread: chat }); } }); - this.busService.subscribe("mail.record/insert", async (payload) => { + this.busService.subscribe("mail.record/insert", (payload) => { if (payload.Thread) { const data = payload.Thread; const thread = this.store.Thread.get(data); @@ -94,7 +94,7 @@ export class DiscussCoreWeb { chatWindow.thread?.eq(thread) ); if (chatWindow) { - await this.chatWindowService.close(chatWindow); + this.chatWindowService.close(chatWindow, { notifyState: false }); } } else { this.store.ChatWindow.insert({