[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
This commit is contained in:
Aurélien Warnon
2022-04-01 18:49:56 +02:00
parent 89eb064977
commit de324e682b
2 changed files with 11 additions and 2 deletions
+2 -1
View File
@@ -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:
@@ -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