From 870eb515eb7ca991814f4923ef223d5d4b417dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 20 Apr 2022 10:51:19 +0000 Subject: [PATCH] [IMP] mail, *: remove uuid from channel_pin * = im_livechat, website_livechat Unnecessary param. task-2827807 Part-of: odoo/odoo#89115 --- addons/im_livechat/models/chatbot_script_step.py | 2 +- addons/mail/models/mail_channel.py | 11 ++--------- addons/mail/static/src/models/thread.js | 8 ++++---- addons/mail/static/tests/helpers/mock_server.js | 10 +++++----- addons/website_livechat/models/mail_channel.py | 4 ++-- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/addons/im_livechat/models/chatbot_script_step.py b/addons/im_livechat/models/chatbot_script_step.py index e6c31a27209..1e267cd6183 100644 --- a/addons/im_livechat/models/chatbot_script_step.py +++ b/addons/im_livechat/models/chatbot_script_step.py @@ -350,7 +350,7 @@ class ChatbotScriptStep(models.Model): Markup('
%s
') % _('%s has joined', human_operator.partner_id.name)) mail_channel._broadcast(human_operator.partner_id.ids) - mail_channel.channel_pin(mail_channel.uuid, pinned=True) + mail_channel.channel_pin(pinned=True) return posted_message diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 028315f1128..1a300b70b8a 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -964,14 +964,7 @@ class Channel(models.Model): 'serverFoldState': state, }) - @api.model - def channel_pin(self, uuid, pinned=False): - # add the person in the channel, and pin it (or unpin it) - channel = self.search([('uuid', '=', uuid)]) - channel._execute_channel_pin(pinned) - - def _execute_channel_pin(self, pinned=False): - """ Hook for website_livechat channel unpin and cleaning """ + def channel_pin(self, pinned=False): self.ensure_one() channel_partners = self.env['mail.channel.partner'].search( [('partner_id', '=', self.env.user.partner_id.id), ('channel_id', '=', self.id), ('is_pinned', '!=', pinned)]) @@ -1267,7 +1260,7 @@ class Channel(models.Model): if self.channel_type in ('channel', 'group'): self.action_unfollow() else: - self.channel_pin(self.uuid, False) + self.channel_pin(False) def execute_command_who(self, **kwargs): partner = self.env.user.partner_id diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index 6e65365e9d6..4f7f1a95d2b 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -439,15 +439,15 @@ registerModel({ * Performs the `channel_pin` RPC on `mail.channel`. * * @param {Object} param0 + * @param {number} param0.channelId * @param {boolean} [param0.pinned=false] - * @param {string} param0.uuid */ - async performRpcChannelPin({ pinned = false, uuid }) { + async performRpcChannelPin({ channelId, pinned = false }) { return this.env.services.rpc({ model: 'mail.channel', method: 'channel_pin', + args: [[channelId]], kwargs: { - uuid, pinned, }, }, { shadow: true }); @@ -892,8 +892,8 @@ registerModel({ return; } await this.messaging.models['Thread'].performRpcChannelPin({ + channelId: this.id, pinned: this.isPendingPinned, - uuid: this.uuid, }); }, /** diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index 1c80ef2f29e..a0cbe934417 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -194,9 +194,9 @@ MockServer.include({ return this._mockMailChannelAddMembers(ids, partner_ids); } if (args.model === 'mail.channel' && args.method === 'channel_pin') { - const uuid = args.args[0] || args.kwargs.uuid; + const ids = args.args[0]; const pinned = args.args[1] || args.kwargs.pinned; - return this._mockMailChannelChannelPin(uuid, pinned); + return this._mockMailChannelChannelPin(ids, pinned); } if (args.model === 'mail.channel' && args.method === 'channel_rename') { const ids = args.args[0]; @@ -986,11 +986,11 @@ MockServer.include({ * Simulates the `channel_pin` method of `mail.channel`. * * @private - * @param {string} uuid + * @param {number[]} ids * @param {boolean} [pinned=false] */ - async _mockMailChannelChannelPin(uuid, pinned = false) { - const channel = this._getRecords('mail.channel', [['uuid', '=', uuid]])[0]; + async _mockMailChannelChannelPin(ids, pinned = false) { + const [channel] = this._getRecords('mail.channel', [['id', 'in', ids]]); const [memberOfCurrentUser] = this._getRecords('mail.channel.partner', [['channel_id', '=', channel.id], ['partner_id', '=', this.currentPartnerId], ['is_pinned', '!=', pinned]]); if (memberOfCurrentUser) { this._mockWrite('mail.channel.partner', [ diff --git a/addons/website_livechat/models/mail_channel.py b/addons/website_livechat/models/mail_channel.py index 25586b1ae5a..16a6b983141 100644 --- a/addons/website_livechat/models/mail_channel.py +++ b/addons/website_livechat/models/mail_channel.py @@ -10,7 +10,7 @@ class MailChannel(models.Model): livechat_visitor_id = fields.Many2one('website.visitor', string='Visitor') - def _execute_channel_pin(self, pinned=False): + def channel_pin(self, pinned=False): """ Override to clean an empty livechat channel. This is typically called when the operator send a chat request to a website.visitor but don't speak to him and closes the chatter. @@ -18,7 +18,7 @@ class MailChannel(models.Model): If active empty livechat channel, delete mail_channel as not useful to keep empty chat """ - super(MailChannel, self)._execute_channel_pin(pinned) + super().channel_pin(pinned=pinned) if self.livechat_active and not self.message_ids: self.unlink()