diff options
| author | David Beguin <dbe@odoo.com> | 2019-11-28 16:03:08 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-02-10 11:46:05 +0000 |
| commit | 9c9032e664fa2e5f53c7978dc17f8f18dc8ad9a6 (patch) | |
| tree | ae00940f3942512bb06d3a07deddce255e9e6f30 /addons | |
| parent | 5a3c4f074281e0aa0e2eff0e623ac7f9b7925a33 (diff) | |
[IMP] (im/website)_livechat : hide and clean empty livechat sessions
Purpose
=======
Whenever a visitor start a livechat session but finally close the session
without sending any messages, the livechat session is empty and stay in DB.
Livechat session counter counts all the sessions (with and without message)
but when opening the sessions tree view, the view is filtered by default on
session with messages. There is no reason to see the empty sessions as it
does not give any information (except "the visitor hesitated to start
livechat and finally did not" which is quite useless info)
The goal is to keep only sessions with messages.
When the visitor is closing the livechat window, if the session is empty,
the session should be deleted. But what happens if a visitor start a livechat
session, send no message and just leave the website without closing the
livechat window ? --> empty live chat session will remains in database.
The ir_autovacuum already handle the deletion of empty sessions to main a
clean DB.
Specifications
==============
- Apply 'with messages' domain on session count in the livechat channel view
- Apply 'with messages' domain on session count in the lead view
- Apply 'with messages' domain on livechat session view
- Remove With message filter
- Remove Without message filter
- If send message on a deleted session :
just tell the visitor that operator is not available anymore
AND delete livechat session cookie (as he waited 1 day to send a message)
Empty sessions becomes invisible : not possible for users to see empty session
(in count or in views) and cron is cleaning empty sessions every day.
This commit also adapts visitor session count and view accordingly.
Task ID: 2146962
PR #41065
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons')
6 files changed, 30 insertions, 13 deletions
diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index 16ff4690748..cb3512ee196 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -74,8 +74,10 @@ class ImLivechatChannel(models.Model): @api.depends('channel_ids') def _compute_nbr_channel(self): - data = self.env['mail.channel'].read_group([('livechat_channel_id', 'in', self._ids)], ['__count'], ['livechat_channel_id'], lazy=False) - channel_count = {x['livechat_channel_id'][0]: x['__count'] for x in data} + channels = self.env['mail.channel'].search([('livechat_channel_id', 'in', self.ids)]) + channel_count = dict.fromkeys(self.ids, 0) + for channel in channels.filtered(lambda c: c.channel_message_ids): + channel_count[channel.livechat_channel_id.id] += 1 for record in self: record.nbr_channel = channel_count.get(record.id, 0) diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index 72b53d7abb4..86ba2e76bd3 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -239,7 +239,11 @@ var LivechatButton = Widget.extend({ } def.then(function (livechatData) { if (!livechatData || !livechatData.operator_pid) { - alert(_t("None of our collaborators seem to be available, please try again later.")); + self.displayNotification({ + title: _t("Collaborators offline"), + message: _t("None of our collaborators seem to be available, please try again later."), + sticky: true + }); } else { self._livechat = new WebsiteLivechat({ parent: self, @@ -328,7 +332,15 @@ var LivechatButton = Widget.extend({ var self = this; return session .rpc('/mail/chat_post', {uuid: this._livechat.getUUID(), message_content: message.content}) - .then(function () { + .then(function (messageId) { + if (!messageId) { + self.displayNotification({ + title: _t("Session Expired"), + message: _t("You took to long to send a message. Please refresh the page and try again."), + sticky: true + }); + self._closeChat(); + } self._chatWindow.scrollToBottom(); }); }, diff --git a/addons/im_livechat/views/mail_channel_views.xml b/addons/im_livechat/views/mail_channel_views.xml index a53ee2bc5d4..a9e03b819b3 100644 --- a/addons/im_livechat/views/mail_channel_views.xml +++ b/addons/im_livechat/views/mail_channel_views.xml @@ -8,8 +8,6 @@ <field name="arch" type="xml"> <search string="Search history"> <field name="name"/> - <filter string="With Messages" name="session_not_empty" domain="[('channel_message_ids', '!=', False)]"/> - <filter string="Empty Sessions" name="session_empty" domain="[('channel_message_ids', '=', False)]"/> <group expand="0" string="Group By..."> <filter name="group_by_channel" string="Channel" domain="[]" context="{'group_by':'livechat_channel_id'}"/> <separator orientation="vertical"/> @@ -131,11 +129,10 @@ <field name="name">Sessions</field> <field name="res_model">mail.channel</field> <field name="view_mode">tree,form</field> - <field name="domain">[('livechat_channel_id', 'in', [active_id])]</field> + <field name="domain">[('livechat_channel_id', 'in', [active_id]), ('channel_message_ids', '!=', False)]</field> <field name="context">{ 'search_default_livechat_channel_id': [active_id], 'default_livechat_channel_id': active_id, - 'search_default_session_not_empty': 1, }</field> <field name="search_view_id" ref="mail_channel_view_search"/> </record> diff --git a/addons/website_crm_livechat/models/crm_lead.py b/addons/website_crm_livechat/models/crm_lead.py index b28dcaf7f1e..1b31eaa3a3f 100644 --- a/addons/website_crm_livechat/models/crm_lead.py +++ b/addons/website_crm_livechat/models/crm_lead.py @@ -17,5 +17,5 @@ class Lead(models.Model): def action_redirect_to_livechat_sessions(self): visitors = self.visitor_ids action = self.env.ref('website_livechat.website_visitor_livechat_session_action').read()[0] - action['domain'] = [('livechat_visitor_id', 'in', visitors.ids)] + action['domain'] = [('livechat_visitor_id', 'in', visitors.ids), ('channel_message_ids', '!=', False)] return action diff --git a/addons/website_livechat/models/website_visitor.py b/addons/website_livechat/models/website_visitor.py index fd968f79671..63fdc570ea5 100644 --- a/addons/website_livechat/models/website_visitor.py +++ b/addons/website_livechat/models/website_visitor.py @@ -29,10 +29,12 @@ class WebsiteVisitor(models.Model): @api.depends('mail_channel_ids') def _compute_session_count(self): - sessions = self.env['mail.channel'].read_group([('livechat_visitor_id', 'in', self.ids)], ['livechat_visitor_id'], ['livechat_visitor_id']) - sessions_count = {session['livechat_visitor_id'][0]: session['livechat_visitor_id_count'] for session in sessions} + sessions = self.env['mail.channel'].search([('livechat_visitor_id', 'in', self.ids)]) + session_count = dict.fromkeys(self.ids, 0) + for session in sessions.filtered(lambda c: c.channel_message_ids): + session_count[session.livechat_visitor_id.id] += 1 for visitor in self: - visitor.session_count = sessions_count.get(visitor.id, 0) + visitor.session_count = session_count.get(visitor.id, 0) def action_send_chat_request(self): """ Send a chat request to website_visitor(s). diff --git a/addons/website_livechat/views/website_visitor_views.xml b/addons/website_livechat/views/website_visitor_views.xml index 2626b8f2c27..9fe94e7552e 100644 --- a/addons/website_livechat/views/website_visitor_views.xml +++ b/addons/website_livechat/views/website_visitor_views.xml @@ -5,7 +5,11 @@ <field name="res_model">mail.channel</field> <field name="view_mode">tree,form</field> <field name="view_id" ref="im_livechat.mail_channel_view_tree"/> - <field name="domain">[('livechat_visitor_id', '=', active_id)]</field> + <field name="domain">[('livechat_visitor_id', '=', active_id), ('channel_message_ids', '!=', False)]</field> + <field name="context">{ + 'search_default_livechat_visitor_id': [active_id], + 'default_livechat_visitor_id': active_id, + }</field> </record> <record id="website_visitor_livechat_session_action_tree" model="ir.actions.act_window.view"> |
