From 54ad2f57ce7989990c9850bf245567af89d7bff2 Mon Sep 17 00:00:00 2001 From: XavierDo Date: Tue, 11 Dec 2018 16:30:12 +0000 Subject: [PATCH] [FIX] mail: avoid to post multiple join message on channel When a new user is subscribed to a channel, (multi-user, without emails) a message is posted on this channel. The mechanic used for that is unfortunately not very reliable Javascript will call channel_join_and_get_info every time a channel is added (client side) even if the user is already in the channel. This fix simply check that the action_follow actually add the user to the channel before sending the message. We should avoid to call channel_join_and_get_info in this case and only call channel_info but this fix will temporary fix the issue. closes odoo/odoo#29441 --- addons/mail/models/mail_channel.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 2c02be5997b..13cbb4644a1 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -280,6 +280,7 @@ class Channel(models.Model): channel_partner = self.mapped('channel_last_seen_partner_ids').filtered(lambda cp: cp.partner_id == self.env.user.partner_id) if not channel_partner: return self.write({'channel_last_seen_partner_ids': [(0, 0, {'partner_id': self.env.user.partner_id.id})]}) + return False @api.multi def action_unfollow(self): @@ -798,12 +799,12 @@ class Channel(models.Model): @api.multi def channel_join_and_get_info(self): self.ensure_one() - if self.channel_type == 'channel' and not self.email_send: + added = self.action_follow() + if added and self.channel_type == 'channel' and not self.email_send: notification = _('
joined #%s
') % (self.id, self.name,) self.message_post(body=notification, message_type="notification", subtype="mail.mt_comment") - self.action_follow() - if self.moderation_guidelines: + if added and self.moderation_guidelines: self._send_guidelines(self.env.user.partner_id) channel_info = self.channel_info('join')[0]