From de324e682bfc051c39e4e3cc3aa432f2a313ae47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Fri, 18 Mar 2022 10:40:51 +0000 Subject: [PATCH] [IMP] mail: allow opening the chat window when inviting members to a channel Currently, when inviting members to a mail.channel using the "add_members" method, it is not possible to signal to web client to automatically open that conversation in a chat window. This commit adds a parameter to that method to allow that behavior, and also slightly adapts the notification handling to open the chat window accordingly on the web client side. This is necessary for the upcoming chatbot, where we want to invite operators to the channel and make them see the new conversation immediately. Task-2030386 Part-of: odoo/odoo#84000 --- addons/mail/models/mail_channel.py | 3 ++- .../src/models/messaging_notification_handler.js | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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