diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index d6494e88c73..b568dfa787e 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -326,7 +326,7 @@ class Channel(models.Model): }) return result - def add_members(self, partner_ids=None, guest_ids=None, invite_to_rtc_call=False, post_joined_message=True): + def add_members(self, partner_ids=None, guest_ids=None, invite_to_rtc_call=False, open_chat_window=False, post_joined_message=True): """ Adds the given partner_ids and guest_ids as member of self channels. """ self.check_access_rights('write') self.check_access_rule('write') @@ -377,6 +377,7 @@ class Channel(models.Model): notifications.append((channel_partner.partner_id, 'mail.channel/joined', { 'channel': channel_partner.channel_id.with_user(user).with_context(allowed_company_ids=user.company_ids.ids).sudo().channel_info()[0], 'invited_by_user_id': self.env.user.id, + 'open_chat_window': open_chat_window, })) if post_joined_message: diff --git a/addons/mail/static/src/models/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler.js index 16d210c2d5d..370c3f2018c 100644 --- a/addons/mail/static/src/models/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler.js @@ -183,8 +183,9 @@ registerModel({ * @param {Object} payload * @param {Thread} payload.channel * @param {integer} [payload.invited_by_user_id] + * @param {boolean} [payload.open_chat_window] if true, will pin the channel */ - _handleNotificationChannelJoined({ channel: channelData, invited_by_user_id: invitedByUserId }) { + _handleNotificationChannelJoined({ channel: channelData, invited_by_user_id: invitedByUserId, open_chat_window: openChatWindow }) { const channel = this.messaging.models['Thread'].insert(this.messaging.models['Thread'].convertData(channelData)); if (this.messaging.currentUser && invitedByUserId !== this.messaging.currentUser.id) { // Current user was invited by someone else. @@ -196,6 +197,13 @@ registerModel({ type: 'info', }); } + + if (openChatWindow) { + // open chat upon being invited (if it was not already opened or folded) + if (channel.channel_type !== 'channel' && !this.messaging.device.isMobile && !channel.chatWindow) { + this.messaging.chatWindowManager.openThread(channel); + } + } }, /** * @private