diff options
| author | David Beguin <dbe@odoo.com> | 2019-11-29 10:29:44 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2020-02-12 16:06:22 +0000 |
| commit | 20a7ae2657c4b90512dc24dfaa5e17024e7b37c2 (patch) | |
| tree | d4023cfe0a4dd1917f509cbb388d6aa0e7e5d054 /addons/website_livechat/models | |
| parent | a7009100a601743a222b9eab8d7a2ebe9ea62575 (diff) | |
[REF] im_livechat, website_livechat : move close livechat session to base module
In order to be able to flag the livechat as inactive when the visitor left the
conversation, livechat_active field is moved to im_livechat module, as it is
not linked to website_visitor.
This commit is also a preparation for next one, which will implement the close
conversation right after the first click on x button in livechat window (at
visitor side). We needed the livechat_active flag to be available without
website installed.
Task ID: 2120210
PR #39939
Diffstat (limited to 'addons/website_livechat/models')
| -rw-r--r-- | addons/website_livechat/models/im_livechat_channel.py | 7 | ||||
| -rw-r--r-- | addons/website_livechat/models/mail_channel.py | 27 |
2 files changed, 11 insertions, 23 deletions
diff --git a/addons/website_livechat/models/im_livechat_channel.py b/addons/website_livechat/models/im_livechat_channel.py index fb1648a9808..6718fd3e48b 100644 --- a/addons/website_livechat/models/im_livechat_channel.py +++ b/addons/website_livechat/models/im_livechat_channel.py @@ -11,15 +11,12 @@ class ImLivechatChannel(models.Model): mail_channel_vals = super(ImLivechatChannel, self)._get_livechat_mail_channel_vals(anonymous_name, operator, user_id=user_id, country_id=country_id) visitor_sudo = self.env['website.visitor']._get_visitor_from_request() if visitor_sudo: - mail_channel_vals.update({ - 'livechat_visitor_id': visitor_sudo.id, - 'livechat_active': True - }) + mail_channel_vals['livechat_visitor_id'] = visitor_sudo.id if not user_id: mail_channel_vals['anonymous_name'] = visitor_sudo.display_name + (' (%s)' % visitor_sudo.country_id.name if visitor_sudo.country_id else '') # As chat requested by the visitor, delete the chat requested by an operator if any to avoid conflicts between two flows chat_request_channel = self.env['mail.channel'].sudo().search([('livechat_visitor_id', '=', visitor_sudo.id), ('livechat_active', '=', True)]) for mail_channel in chat_request_channel: - mail_channel.close_livechat_request_session(type='cancel', speaking_with=operator.name) + mail_channel._close_livechat_session(cancel=True, speaking_with=operator.name) return mail_channel_vals diff --git a/addons/website_livechat/models/mail_channel.py b/addons/website_livechat/models/mail_channel.py index 6f0ddee0fc7..804571bde42 100644 --- a/addons/website_livechat/models/mail_channel.py +++ b/addons/website_livechat/models/mail_channel.py @@ -8,7 +8,6 @@ class MailChannel(models.Model): _inherit = 'mail.channel' livechat_visitor_id = fields.Many2one('website.visitor', string='Visitor') - livechat_active = fields.Boolean('Is livechat ongoing?', help='Livechat session is not considered as active if the visitor left the conversation.') def _execute_channel_pin(self, pinned=False): """ Override to clean an empty livechat channel. @@ -53,23 +52,15 @@ class MailChannel(models.Model): recent_history = self.env['website.track'].search([('page_id', '!=', False), ('visitor_id', '=', visitor.id)], limit=3) return ' → '.join(visit.page_id.name + ' (' + visit.visit_datetime.strftime('%H:%M') + ')' for visit in reversed(recent_history)) - def close_livechat_request_session(self, type='leave', **kwargs): - """ Set deactivate the livechat channel and notify (the operator) the reason of closing the session.""" - self.ensure_one() - if self.livechat_active: - self.livechat_active = False - # avoid useless notification if the channel is empty - if not self.channel_message_ids: - return - # Notify that the visitor has left the conversation - name = _('The visitor') if not self.livechat_visitor_id else self.livechat_visitor_id.display_name - if type == 'cancel': - message = _('has started a conversation with %s. The chat request has been canceled.') % kwargs.get('speaking_with', 'an operator') - else: - message = _('has left the conversation.') - leave_message = '%s %s' % (name, message) - self.message_post(author_id=self.env.ref('base.user_root').sudo().partner_id.id, - body=leave_message, message_type='comment', subtype_xmlid='mail.mt_comment') + def _get_visitor_leave_message(self, operator=False, cancel=False): + name = _('The visitor') if not self.livechat_visitor_id else self.livechat_visitor_id.display_name + if cancel: + message = _("""%s has started a conversation with %s. + The chat request has been canceled.""") % (name, operator or _('an operator')) + else: + message = _('%s has left the conversation.') % name + + return message def message_post(self, **kwargs): """Override to mark the visitor as still connected. |
