[FIX] mail, im_livechat: ignore notifications for unknown channels
Inserting channels and handling notifications for channels that have not been properly initialized through the `channel_info` leads to issues due to incomplete data that is not properly handled, such as bad correspondent, missing uuid, inconsistent name, etc. Moreover it doesn't make sense functionally to handle notifications such as typing status if the channel isn't going to be displayed. PR: #56243 Part of task-2323670 X-original-commit: 75070665060d64fe7b532aac4fc8e8410381b083
This commit is contained in:
+4
-1
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
+17
-15
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user