Skip to content
Snippets Groups Projects
Commit 9c9032e6 authored by David Beguin's avatar David Beguin Committed by Thibault Delavallée
Browse files

[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: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 5a3c4f07
Branches
Tags
No related merge requests found
......@@ -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)
......
......@@ -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();
});
},
......
......@@ -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>
......
......@@ -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
......@@ -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).
......
......@@ -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">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment