[FIX] mail: properly return last message id for channel in mobile

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) <aku@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2021-01-22 15:05:50 +00:00
parent dbea01090f
commit 8252f8123d
+2 -15
View File
@@ -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)