From 06fd9e3aa31d0c6493b22b5b910cb101bf922189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Fri, 17 Apr 2015 11:04:45 +0200 Subject: [PATCH] [FIX] im_livechat : the default welcome message should come from the operator Now the livechat supports identified users. So multiple user can be in the user_ids of a session. The author of the 'welcome message' is more difficult to identify. If portal user connected, the 'welcome message' author was this portal user instead of the operator. Required to pass operator id in the context to avoid the same mistake with an operator as 'client' and operator as real operator. --- addons/im_livechat/im_livechat.py | 7 ++++++- addons/im_livechat/static/src/js/im_livechat.js | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/im_livechat/im_livechat.py b/addons/im_livechat/im_livechat.py index 91c02810591..3585e7c0f3d 100644 --- a/addons/im_livechat/im_livechat.py +++ b/addons/im_livechat/im_livechat.py @@ -177,6 +177,8 @@ class im_livechat_channel(osv.Model): # create the session, and add the link with the given channel Session = self.pool["im_chat.session"] newid = Session.create(cr, SUPERUSER_ID, {'user_ids': user_to_add, 'channel_id': channel_id, 'anonymous_name' : anonymous_name}, context=context) + # update context to identify the operator + context['im_livechat_operator_id'] = user_id return Session.session_info(cr, SUPERUSER_ID, [newid], context=context) def test_channel(self, cr, uid, channel, context=None): @@ -289,8 +291,11 @@ class im_chat_session(osv.Model): """ add the anonymous user in the user of the session """ for session in self.browse(cr, uid, ids, context=context): users_infos = super(im_chat_session, self).users_infos(cr, uid, ids, context=context) + # identify the operator for the 'welcome message' + for user_profile in users_infos: + user_profile['is_operator'] = bool(user_profile['id'] == context.get('im_livechat_operator_id')) if session.anonymous_name: - users_infos.append({'id' : False, 'name' : session.anonymous_name, 'im_status' : 'online'}) + users_infos.append({'id' : False, 'name' : session.anonymous_name, 'im_status' : 'online', 'is_operator' : False}) return users_infos def quit_user(self, cr, uid, uuid, context=None): diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index 8b40de081f0..e4a4510b58f 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -209,12 +209,13 @@ if(this.session.users.length > 0){ if (self.options.defaultMessage) { setTimeout(function(){ + var operator = _.last(_.filter(self.session.users, function(user){return user.is_operator})); self.conv.received_message({ id : 1, type: "message", message: self.options.defaultMessage, create_date: openerp.datetime_to_str(new Date()), - from_id: [self.session.users[0].id, self.session.users[0].name], + from_id: [operator.id, operator.name], to_id: [0, self.session.uuid] }); }, 1000);