From 2292979b989ae652d5fb84218da0bbb7fe321d74 Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Wed, 15 Dec 2021 12:37:33 +0000 Subject: [PATCH] [FIX] mail: notify guest when joining the channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this PR, the guest that just connect wouldn't receive the longpolling message before the current one expire. task-2664831 closes odoo/odoo#82170 X-original-commit: 0006123dba46d32d062a581e9a16f433f3ce05f3 Signed-off-by: Sébastien Theys (seb) --- addons/mail/models/mail_channel.py | 5 +++++ .../messaging_notification_handler.js | 4 ++-- addons/mail/tests/test_rtc.py | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 41fdd0f1535..4f1a78785e9 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -360,6 +360,11 @@ class Channel(models.Model): 'id': channel_partner.guest_id.id, 'name': channel_partner.guest_id.name, }) + guest = channel_partner.guest_id + if guest: + self.env['bus.bus']._sendone(guest, 'mail.channel/joined', { + 'channel': channel_partner.channel_id.sudo().channel_info()[0], + }) self.env['bus.bus']._sendone(channel, 'mail.channel/insert', { 'id': channel.id, 'guestMembers': [('insert', guest_members_data)], 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 5bcaffdecb0..0da52cce477 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 @@ -182,11 +182,11 @@ registerModel({ * @private * @param {Object} payload * @param {Thread} payload.channel - * @param {integer} payload.invited_by_user_id + * @param {integer} [payload.invited_by_user_id] */ _handleNotificationChannelJoined({ channel: channelData, invited_by_user_id: invitedByUserId }) { const channel = this.messaging.models['Thread'].insert(this.messaging.models['Thread'].convertData(channelData)); - if (invitedByUserId !== this.messaging.currentUser.id) { + if (this.messaging.currentUser && invitedByUserId !== this.messaging.currentUser.id) { // Current user was invited by someone else. this.env.services['notification'].notify({ message: _.str.sprintf( diff --git a/addons/mail/tests/test_rtc.py b/addons/mail/tests/test_rtc.py index 7200624beb8..16a1df69fb8 100644 --- a/addons/mail/tests/test_rtc.py +++ b/addons/mail/tests/test_rtc.py @@ -451,6 +451,7 @@ class TestChannelInternals(MailCommon): (self.cr.dbname, 'res.partner', self.user_employee.partner_id.id), # update of last interest (not asserted below) (self.cr.dbname, 'res.partner', test_user.partner_id.id), # update of last interest (not asserted below) (self.cr.dbname, 'mail.channel', channel.id), # new member (guest) (not asserted below) + (self.cr.dbname, 'mail.guest', test_guest.id), # channel joined for guest (not asserted below) ], [ {