From 8252f8123d03ed92c10bc2de8c1d0ca03f9be52c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 22 Jan 2021 15:05:50 +0000 Subject: [PATCH] [FIX] mail: properly return last message id for channel in mobile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This mobile specific code does not work correctly because `if channel in channel_previews` always returns false due to the dict having channel ids as key and not channels. A fix could be to look for id instead of record in the dict, but at the same time this is dead code, there is no need for mobile specific channel info. task-2412157 closes odoo/odoo#64945 X-original-commit: a27907e27fb99a523c7b2d58544c36073640511c Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Sébastien Theys (seb) --- addons/mail/models/mail_channel.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 237edf8ef50..bee474a3ce7 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -655,13 +655,7 @@ class Channel(models.Model): direct_channel_partners = all_partner_channel.filtered(lambda pc: channel_dict[pc.channel_id.id].channel_type == 'chat') direct_partners = direct_channel_partners.mapped('partner_id') partner_infos = self._get_channel_partner_info(all_partners, direct_partners) - - # add last message preview (only used in mobile) - addPreview = self._context.get('isMobile', False) - if addPreview: - channel_previews = {channel_preview['id']: channel_preview for channel_preview in self.channel_fetch_preview()} - else: - channel_last_message_ids = dict((r['id'], r['message_id']) for r in self._channel_last_message_ids()) + channel_last_message_ids = dict((r['id'], r['message_id']) for r in self._channel_last_message_ids()) for channel in self: info = { @@ -682,14 +676,7 @@ class Channel(models.Model): info['info'] = extra_info # add last message preview (only used in mobile) - if addPreview: - if channel in channel_previews: - info['last_message'] = channel_previews[channel] - info['last_message_id'] = channel_previews[channel]['last_message']['id'] - else: - info['last_message_id'] = False - else: - info['last_message_id'] = channel_last_message_ids.get(channel.id, False) + info['last_message_id'] = channel_last_message_ids.get(channel.id, False) # listeners of the channel channel_partners = all_partner_channel.filtered(lambda pc: channel.id == pc.channel_id.id)