[FIX] im_livechat: Traceback on Safari and Chrome mobile

Steps to reproduce the bug:

- Install website_livechat
- Go to login page on mobile with Safari
- Click on "Have a Question?"
- Close the chat by clicking on the arrow

Bug:

A traceback was raised

Ref:https://stackoverflow.com/questions/19359326/json-parse-fails-in-safari-when-a-string-value-contains-a-comma

opw:2243871

closes odoo/odoo#50715

X-original-commit: 99a5e7c2159f8db3e1ce65f9225f0ce18cc28d70
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2020-05-06 08:34:59 +00:00
parent aa0444e3de
commit 57abcab99b
3 changed files with 6 additions and 5 deletions
@@ -129,7 +129,7 @@ class ImLivechatChannel(models.Model):
'anonymous_name': False if user_id else anonymous_name,
'country_id': country_id,
'channel_type': 'livechat',
'name': ', '.join([visitor_user.display_name if visitor_user else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
'name': ' '.join([visitor_user.display_name if visitor_user else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
'public': 'private',
'email_send': False,
}
+2 -1
View File
@@ -83,7 +83,8 @@ class MailChannel(models.Model):
if channel.channel_type == 'livechat':
# add the operator id
if channel.livechat_operator_id:
channel_infos_dict[channel.id]['operator_pid'] = channel.livechat_operator_id.with_context(im_livechat_use_username=True).name_get()[0]
res = channel.livechat_operator_id.with_context(im_livechat_use_username=True).name_get()[0]
channel_infos_dict[channel.id]['operator_pid'] = (res[0], res[1].replace(',', ''))
# 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)
@@ -41,7 +41,7 @@ class TestLivechatBasicFlowHttpCase(tests.HttpCase, TestLivechatCommon):
channel_1 = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor.id), ('livechat_active', '=', True)], limit=1)
# Check Channel naming
self.assertEqual(channel_1.name, "%s, %s" % (self.visitor.display_name, self.operator.livechat_username))
self.assertEqual(channel_1.name, "%s %s" % (self.visitor.display_name, self.operator.livechat_username))
channel_1.unlink()
# Remove livechat_username
@@ -53,7 +53,7 @@ class TestLivechatBasicFlowHttpCase(tests.HttpCase, TestLivechatCommon):
channel_2 = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor.id), ('livechat_active', '=', True)], limit=1)
# Check Channel naming
self.assertEqual(channel_2.name, "%s, %s" % (self.visitor.display_name, self.operator.name))
self.assertEqual(channel_2.name, "%s %s" % (self.visitor.display_name, self.operator.name))
def test_basic_flow_with_rating(self):
channel = self._common_basic_flow()
@@ -86,7 +86,7 @@ class TestLivechatBasicFlowHttpCase(tests.HttpCase, TestLivechatCommon):
# Check Channel and Visitor naming
self.assertEqual(self.visitor.display_name, "%s #%s" % (_("Website Visitor"), self.visitor.id))
self.assertEqual(channel.name, "%s, %s" % (self.visitor.display_name, self.operator.livechat_username))
self.assertEqual(channel.name, "%s %s" % (self.visitor.display_name, self.operator.livechat_username))
# Post Message from visitor
self._send_message(channel, self.visitor.display_name, "Message from Visitor")