diff --git a/addons/im_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/im_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js index a418b4c331d..dd9d08b606c 100644 --- a/addons/im_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js +++ b/addons/im_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js @@ -17,10 +17,13 @@ registerInstancePatchModel('mail.messaging_notification_handler', 'im_livechat/s */ _handleNotificationChannelTypingStatus(data) { const { channelId, partner_id } = data; - const channel = this.env.models['mail.thread'].insert({ + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ id: channelId, model: 'mail.channel', }); + if (!channel) { + return; + } let partnerId; if (partner_id === this.env.messaging.publicPartner.id) { // Some shenanigans that this is a typing notification diff --git a/addons/mail/static/src/models/message/message.js b/addons/mail/static/src/models/message/message.js index d38b50a3083..582745e28f2 100644 --- a/addons/mail/static/src/models/message/message.js +++ b/addons/mail/static/src/models/message/message.js @@ -63,16 +63,14 @@ function factory(dependencies) { data2.body = data.body; } if ('channel_ids' in data && data.channel_ids) { - // AKU FIXME: side-effect of calling convert... - const channelList = []; - for (const channelId of data.channel_ids) { - const channel = this.env.models['mail.thread'].insert({ - id: channelId, - model: 'mail.channel', - }); - channelList.push(channel); - } - data2.serverChannels = [['replace', channelList]]; + const channels = data.channel_ids + .map(channelId => + this.env.models['mail.thread'].findFromIdentifyingData({ + id: channelId, + model: 'mail.channel', + }) + ).filter(channel => !!channel); + data2.serverChannels = [['replace', channels]]; } if ('date' in data && data.date) { data2.date = moment(str_to_datetime(data.date)); diff --git a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js index 7bd0e16d6f2..6764f28ceb4 100644 --- a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js @@ -144,9 +144,10 @@ function factory(dependencies) { last_message_id, partner_id, }) { - const channel = this.env.models['mail.thread'].find(thread => - thread.id === channelId && thread.model === 'mail.channel' - ); + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ + id: channelId, + model: 'mail.channel', + }); if (!channel) { // for example seen from another browser, the current one has no // knowledge of the channel @@ -198,10 +199,10 @@ function factory(dependencies) { const message = this.env.models['mail.message'].insert(convertedData); // join the corresponding channel if necessary - const channel = this.env.models['mail.thread'].find(thread => - thread.id === channelId && - thread.model === 'mail.channel' - ); + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ + id: channelId, + model: 'mail.channel', + }); if (!channel || !channel.isPinned) { this.env.models['mail.thread'].joinChannel(channelId); } @@ -275,9 +276,10 @@ function factory(dependencies) { last_message_id, partner_id, }) { - const channel = this.env.models['mail.thread'].find(thread => - thread.id === channelId && thread.model === 'mail.channel' - ); + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ + id: channelId, + model: 'mail.channel', + }); if (!channel) { // for example seen from another browser, the current one has no // knowledge of the channel @@ -327,10 +329,13 @@ function factory(dependencies) { is_typing, partner_id, }) { - const channel = this.env.models['mail.thread'].insert({ + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ id: channelId, model: 'mail.channel', }); + if (!channel) { + return; + } const partner = this.env.models['mail.partner'].insert({ id: partner_id }); if (partner === this.env.messaging.currentPartner) { // Ignore management of current partner is typing notification. @@ -444,10 +449,7 @@ function factory(dependencies) { _handleNotificationPartnerChannel(data) { const convertedData = this.env.models['mail.thread'].convertData(data); - let channel = this.env.models['mail.thread'].find(thread => - thread.id === convertedData.id && - thread.model === 'mail.channel' - ); + let channel = this.env.models['mail.thread'].findFromIdentifyingData(convertedData); const wasCurrentPartnerMember = ( channel && channel.members.includes(this.env.messaging.currentPartner)