diff options
| author | David Beguin <dbe@odoo.com> | 2018-12-03 15:26:18 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2018-12-05 14:37:10 +0000 |
| commit | 8c8f219b4764173fb1ac924d8a46d9dcdbb85d57 (patch) | |
| tree | bb7a517120e446671ef7676beaa017df42c98e3b /addons | |
| parent | 9281ae81f90cb58cdeb9b3e09ae2a1f1faca0d2c (diff) | |
[IMP] im_livechat : uses anonymous name only if visitor is anonymous
Before, if the visitor was logged in, anonymous name = user.name.
But if we use anonymous name field even if visitor is not anonymous,
we cannot know, in stat e.g., if the session was really made with
an anonymous visitor or not as the field is always filled in.
Now, if the visitor is not anonymous, we use directly the user.name
but we do not fill in the anonymous name. So that if anonymous name
is null, we know afterwards that the session was made we a real
anonymous visitor.
Since the anonymous name is empty if visitor is logged in,
we cannot use anonymous_name anymore to get the title of the session window.
Task ID : 1895998
Closes PR #28283
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/im_livechat/controllers/main.py | 12 | ||||
| -rw-r--r-- | addons/im_livechat/models/im_livechat_channel.py | 15 | ||||
| -rw-r--r-- | addons/im_livechat/models/mail_channel.py | 14 | ||||
| -rw-r--r-- | addons/mail/static/src/js/models/threads/livechat.js | 5 |
4 files changed, 27 insertions, 19 deletions
diff --git a/addons/im_livechat/controllers/main.py b/addons/im_livechat/controllers/main.py index 4ba6a731581..904aba2689b 100644 --- a/addons/im_livechat/controllers/main.py +++ b/addons/im_livechat/controllers/main.py @@ -69,13 +69,15 @@ class LivechatController(http.Controller): @http.route('/im_livechat/get_session', type="json", auth='public') def get_session(self, channel_id, anonymous_name, **kwargs): - # if geoip, add the country name to the anonymous name - if request.session.geoip: - anonymous_name = anonymous_name + " ("+request.session.geoip.get('country_name', "")+")" + user_id = None # if the user is identifiy (eg: portal user on the frontend), don't use the anonymous name. The user will be added to session. if request.session.uid: - anonymous_name = request.env.user.name - return request.env["im_livechat.channel"].with_context(lang=False).get_mail_channel(channel_id, anonymous_name) + user_id = request.env.user.id + # if geoip, add the country name to the anonymous name + elif request.session.geoip: + anonymous_name = anonymous_name + " ("+request.session.geoip.get('country_name', "")+")" + return request.env["im_livechat.channel"].with_context(lang=False).get_mail_channel(channel_id, anonymous_name, user_id) + @http.route('/im_livechat/feedback', type='json', auth='public') def feedback(self, uuid, rate, reason=None, **kwargs): diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index 8ff9f864ac3..33dedbd62be 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -132,22 +132,23 @@ class ImLivechatChannel(models.Model): return self.sudo().user_ids.filtered(lambda user: user.im_status == 'online') @api.model - def get_mail_channel(self, livechat_channel_id, anonymous_name): + def get_mail_channel(self, livechat_channel_id, anonymous_name, user_id=None): """ Return a mail.channel given a livechat channel. It creates one with a connected operator, or return false otherwise :param livechat_channel_id : the identifier if the im_livechat.channel :param anonymous_name : the name of the anonymous person of the channel + :param user_id : the id of the logged in visitor, if any :type livechat_channel_id : int :type anonymous_name : str :return : channel header :rtype : dict """ # get the avalable user of the channel - users = self.sudo().browse(livechat_channel_id).get_available_users() - if len(users) == 0: + operators = self.sudo().browse(livechat_channel_id).get_available_users() + if len(operators) == 0: return False # choose the res.users operator and get its partner id - user = random.choice(users) - operator_partner_id = user.partner_id.id + operator = random.choice(operators) + operator_partner_id = random.choice(operators).partner_id.id # partner to add to the mail.channel channel_partner_to_add = [(4, operator_partner_id)] if self.env.user and self.env.user.active: # valid session user (not public) @@ -156,9 +157,9 @@ class ImLivechatChannel(models.Model): mail_channel = self.env["mail.channel"].with_context(mail_create_nosubscribe=False).sudo().create({ 'channel_partner_ids': channel_partner_to_add, 'livechat_channel_id': livechat_channel_id, - 'anonymous_name': anonymous_name, + 'anonymous_name': False if user_id else anonymous_name, 'channel_type': 'livechat', - 'name': ', '.join([anonymous_name, user.name]), + 'name': ', '.join([self.env['res.users'].browse(user_id).name if user_id else anonymous_name, operator.name]), 'public': 'private', 'email_send': False, }) diff --git a/addons/im_livechat/models/mail_channel.py b/addons/im_livechat/models/mail_channel.py index 014a83b0f2d..1e0d99d42af 100644 --- a/addons/im_livechat/models/mail_channel.py +++ b/addons/im_livechat/models/mail_channel.py @@ -68,11 +68,10 @@ class MailChannel(models.Model): channel_info['operator_pid'] = partner_name channel_infos_dict = dict((c['id'], c) for c in channel_infos) for channel in self: - # add the anonymous name - if channel.anonymous_name: - channel_infos_dict[channel.id]['anonymous_name'] = channel.anonymous_name # add the last message date if channel.channel_type == 'livechat': + # add the anonymous or partner name + channel_infos_dict[channel.id]['correspondent_name'] = channel._channel_get_livechat_partner_name() last_msg = self.env['mail.message'].search([("channel_ids", "in", [channel.id])], limit=1) if last_msg: channel_infos_dict[channel.id]['last_message_date'] = last_msg.date @@ -85,6 +84,15 @@ class MailChannel(models.Model): values['channel_livechat'] = self.search([('channel_type', '=', 'livechat'), ('id', 'in', pinned_channels.ids)]).channel_info() return values + def _channel_get_livechat_partner_name(self): + if self.livechat_operator_id in self.channel_partner_ids: + partners = self.channel_partner_ids - self.livechat_operator_id + if partners: + return ', '.join(partners.mapped('name')) + if self.anonymous_name: + return self.anonymous_name + return _("Visitor") + @api.model def remove_empty_livechat_sessions(self): hours = 1 # never remove empty session created within the last hour diff --git a/addons/mail/static/src/js/models/threads/livechat.js b/addons/mail/static/src/js/models/threads/livechat.js index f4cb58ebad3..45cab5aef10 100644 --- a/addons/mail/static/src/js/models/threads/livechat.js +++ b/addons/mail/static/src/js/models/threads/livechat.js @@ -17,13 +17,10 @@ var Livechat = TwoUserChannel.extend({ * @override * @param {Object} params * @param {Object} params.data - * @param {string} params.data.anonymous_name name of the website user */ init: function (params) { this._super.apply(this, arguments); - - this._name = params.data.anonymous_name; - + this._name = params.data.correspondent_name; this._WEBSITE_USER_NAME = this._name; }, |
