[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.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user