[FIX] mail, im_livechat: no loose of livechats on page refresh

Before this commit, when livechat operators had chats in the
Discuss app and reload their page, they could loose some
pinned livechats.

This problem only occurred on livechat conversations when both
users are authenticated. Any two-user channels should always
be pinned by default, which is the case for internal chats.
This logic was applied on channels with type `chat`, but this
is ignored with livechats because they are channels of type
`livechat`.

This commit fixes the issue by defining internal chats and
livechats as `chat`. Any chat conversations are automatically
pinned when a message is posted, including livechats.

Note that before this commit, the livechats were visually
pinned in the Discuss app, although the server did not consider
them as pinned. The client-side code always assume conversations
are pinned, which is why a page refresh looks like a loose of
previously pinned conversations.

opw-1919327

closes odoo/odoo#30200
This commit is contained in:
Alexandre Kühn
2019-01-15 12:17:24 +00:00
parent dc12f7e06c
commit abeb75ae60
2 changed files with 15 additions and 1 deletions
@@ -36,6 +36,13 @@ class MailChannel(models.Model):
channel_type = fields.Selection(selection_add=[('livechat', 'Livechat Conversation')])
livechat_channel_id = fields.Many2one('im_livechat.channel', 'Channel')
@api.multi
def _compute_is_chat(self):
super(MailChannel, self)._compute_is_chat()
for record in self:
if record.channel_type == 'livechat':
record.is_chat = True
@api.multi
def _channel_message_notifications(self, message):
""" When a anonymous user create a mail.channel, the operator is not notify (to avoid massive polling when
+8 -1
View File
@@ -78,6 +78,7 @@ class Channel(models.Model):
('chat', 'Chat Discussion'),
('channel', 'Channel')],
'Channel Type', default='channel')
is_chat = fields.Boolean(string='Is a chat', compute='_compute_is_chat', default=False)
description = fields.Text('Description')
uuid = fields.Char('UUID', size=50, index=True, default=lambda self: str(uuid4()), copy=False)
email_send = fields.Boolean('Send messages by email', default=False)
@@ -178,6 +179,12 @@ class Channel(models.Model):
for record in self:
record.is_member = record in membership_ids
@api.multi
def _compute_is_chat(self):
for record in self:
if record.channel_type == 'chat':
record.is_chat = True
@api.onchange('public')
def _onchange_public(self):
if self.public == 'public':
@@ -384,7 +391,7 @@ class Channel(models.Model):
if moderation_status == 'rejected':
return self.env['mail.message']
self.filtered(lambda channel: channel.channel_type == 'chat').mapped('channel_last_seen_partner_ids').write({'is_pinned': True})
self.filtered(lambda channel: channel.is_chat).mapped('channel_last_seen_partner_ids').write({'is_pinned': True})
message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(message_type=message_type, moderation_status=moderation_status, **kwargs)