From b4b74f9a208efcffcb0c2e9b8c9c6df7253ded3b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 2 Sep 2013 17:14:04 +0200 Subject: [PATCH 1/6] Bases of the group chat work bzr revid: nicolas.vanhoren@openerp.com-20130902151404-gyy9ydjqu5xucpf5 --- addons/im/im.py | 7 +++++++ addons/im/static/src/js/im.js | 15 ++++++++++++++- addons/im/static/src/js/im_common.js | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/im/im.py b/addons/im/im.py index c47d0d9be7e..f1801fe7285 100644 --- a/addons/im/im.py +++ b/addons/im/im.py @@ -222,6 +222,13 @@ class im_session(osv.osv): }, context=context) return self.read(cr, uid, session_id, context=context) + def add_to_session(self, cr, uid, session_id, user_id, uuid=None, context=None): + my_id = self.pool.get("im.user").get_my_id(cr, uid, uuid, context=context) + session = self.read(cr, uid, session_id, context=context) + if my_id not in session.get("user_ids"): + raise Exception("Not allowed to modify a session when you are not in it.") + self.write(cr, uid, session_id, {"user_ids": [(4, user_id)]}, context=context) + class im_user(osv.osv): _name = "im.user" diff --git a/addons/im/static/src/js/im.js b/addons/im/static/src/js/im.js index cad3c6dff0b..f26b8f5c4a2 100644 --- a/addons/im/static/src/js/im.js +++ b/addons/im/static/src/js/im.js @@ -70,7 +70,15 @@ var self = this; - return this.c_manager.start_polling(); + return this.c_manager.start_polling().then(function() { + self.c_manager.on("new_conversation", self, function(conv) { + conv.$el.droppable({ + drop: function(event, ui) { + self.add_user(conv, ui.draggable.data("user")); + } + }); + }); + }); }, calc_box: function() { var $topbar = instance.client.$(".oe_topbar"); @@ -133,6 +141,9 @@ self.c_manager.activate_session(session.id, true); }); }, + add_user: function(conversation, user) { + conversation.add_user(user); + }, }); instance.im.UserWidget = instance.web.Widget.extend({ @@ -146,6 +157,8 @@ this.user.add_watcher(); }, start: function() { + this.$el.data("user", this.user); + this.$el.draggable({helper: "clone"}); var change_status = function() { this.$(".oe_im_user_online").toggle(this.user.get("im_status") === true); }; diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 6d88764b1d8..c5508a3b69a 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -223,6 +223,7 @@ function declare($, _, openerp) { }); this.conversations.push(conv); this.calc_positions(); + this.trigger("new_conversation", conv); }, this)); } if (focus) { @@ -393,6 +394,19 @@ function declare($, _, openerp) { _go_bottom: function() { this.$(".oe_im_chatview_content").scrollTop($(this.$(".oe_im_chatview_content").children()[0]).height()); }, + add_user: function(user) { + if (user === this.me || _.contains(this.users, user)) + return; + im_common.connection.model("im.session").call("add_to_session", + [this.session_id, user.get("id"), this.c_manager.me.get("uuid")]).then(_.bind(function() { + if (_.contains(this.others, user)) { + this.others = _.without(this.others, user); + } else { + user.add_watcher(); + } + this.users.push(user); + }, this)); + }, focus: function() { this.$(".oe_im_chatview_input").focus(); if (! this.shown) From ee19c62e0ae57b3c9d3a920218ae99bcd2d1841f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 2 Sep 2013 18:08:11 +0200 Subject: [PATCH 2/6] Make group chat really work bzr revid: nicolas.vanhoren@openerp.com-20130902160811-fkdleeurq1g9msi2 --- addons/im/im.py | 5 +-- addons/im/static/src/css/im_common.css | 1 - addons/im/static/src/js/im_common.js | 48 +++++++++++++++++--------- addons/im/static/src/xml/im_common.xml | 12 +++++-- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/addons/im/im.py b/addons/im/im.py index f1801fe7285..15078a50fea 100644 --- a/addons/im/im.py +++ b/addons/im/im.py @@ -182,12 +182,13 @@ class im_message(osv.osv): users_status = users.read(cr, openerp.SUPERUSER_ID, users_watch, ["im_status"], context=context) return {"res": mess, "last": last, "dbname": cr.dbname, "users_status": users_status} - def post(self, cr, uid, message, to_session_id, uuid=None, context=None): + def post(self, cr, uid, message, to_session_id, uuid=None, technical=False, context=None): assert_uuid(uuid) my_id = self.pool.get('im.user').get_my_id(cr, uid, uuid) session = self.pool.get('im.session').browse(cr, uid, to_session_id, context) to_ids = [x.id for x in session.user_ids if x.id != my_id] - self.create(cr, openerp.SUPERUSER_ID, {"message": message, 'from_id': my_id, 'to_id': [(6, 0, to_ids)], 'session_id': to_session_id}, context=context) + self.create(cr, openerp.SUPERUSER_ID, {"message": message, 'from_id': my_id, + 'to_id': [(6, 0, to_ids)], 'session_id': to_session_id, technical=technical}, context=context) notify_channel(cr, "im_channel", {'type': 'message', 'receivers': [my_id] + to_ids}) return False diff --git a/addons/im/static/src/css/im_common.css b/addons/im/static/src/css/im_common.css index f3877af1686..30275833b2d 100644 --- a/addons/im/static/src/css/im_common.css +++ b/addons/im/static/src/css/im_common.css @@ -183,7 +183,6 @@ } .oe_im_chatview_online { - display: none; margin-top: -4px; width: 11px; height: 11px; diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index c5508a3b69a..708c9cd25f0 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -281,29 +281,45 @@ function declare($, _, openerp) { this.shown = true; this.set("pending", 0); this.inputPlaceholder = this.options.defaultInputPlaceholder; - this.users = []; + this.set("users", []); + this.set("disconnected", false); this.others = []; }, start: function() { var self = this; + + self.$().append(openerp.qweb.render("im_common.conversation", {widget: self})); + + var change_status = function() { + var disconnected = _.every(this.get("users"), function(u) { return u.get("im_status") === false; }); + self.set("disconnected", disconnected); + this.$(".oe_im_chatview_users").html(openerp.qweb.render("im_common.conversation.header", + {widget: self, to_url: _.bind(im_common.connection.url, im_common.connection)})); + }; + this.on("change:users", this, function(unused, ev) { + _.each(ev.oldValue, function(user) { + user.off("change:im_status", self, change_status); + }); + _.each(ev.newValue, function(user) { + user.on("change:im_status", self, change_status); + }); + change_status.call(self); + }); + this.on("change:disconnected", this, function() { + self.$().toggleClass("oe_im_chatview_disconnected_status", this.get("disconnected")); + self._go_bottom(); + }); + var user_ids; return im_common.connection.model("im.session").call("read", [self.session_id]).then(function(session) { user_ids = _.without(session.user_ids, self.c_manager.me.get("id")); return self.c_manager.ensure_users(session.user_ids); }).then(function() { - self.users = _.map(user_ids, function(id) {return self.c_manager.get_user(id);}); - _.each(self.users, function(user) { + var users = _.map(user_ids, function(id) {return self.c_manager.get_user(id);}); + _.each(users, function(user) { user.add_watcher(); }); - // TODO: correctly display status - self.$().append(openerp.qweb.render("im_common.conversation", {widget: self, to_url: _.bind(im_common.connection.url, im_common.connection)})); - var change_status = function() { - self.$().toggleClass("oe_im_chatview_disconnected_status", self.users[0].get("im_status") === false); - self.$(".oe_im_chatview_online").toggle(self.users[0].get("im_status") === true); - self._go_bottom(); - }; - self.users[0].on("change:im_status", self, change_status); - change_status.call(self); + self.set("users", users); self.on("change:right_position", self, self.calc_pos); self.on("change:bottom_position", self, self.calc_pos); @@ -345,7 +361,7 @@ function declare($, _, openerp) { } this.c_manager.ensure_users([message.from_id[0]]).then(_.bind(function() { var user = this.c_manager.get_user(message.from_id[0]); - if (! _.contains(this.users, user) && ! _.contains(this.others, user)) { + if (! _.contains(this.get("users"), user) && ! _.contains(this.others, user)) { this.others.push(user); user.add_watcher(); } @@ -395,7 +411,7 @@ function declare($, _, openerp) { this.$(".oe_im_chatview_content").scrollTop($(this.$(".oe_im_chatview_content").children()[0]).height()); }, add_user: function(user) { - if (user === this.me || _.contains(this.users, user)) + if (user === this.me || _.contains(this.get("users"), user)) return; im_common.connection.model("im.session").call("add_to_session", [this.session_id, user.get("id"), this.c_manager.me.get("uuid")]).then(_.bind(function() { @@ -404,7 +420,7 @@ function declare($, _, openerp) { } else { user.add_watcher(); } - this.users.push(user); + this.set("users", this.get("users").concat([user])); }, this)); }, focus: function() { @@ -413,7 +429,7 @@ function declare($, _, openerp) { this.show_hide(); }, destroy: function() { - _.each(this.users, function(user) { + _.each(this.get("users"), function(user) { user.remove_watcher(); }) _.each(this.others, function(user) { diff --git a/addons/im/static/src/xml/im_common.xml b/addons/im/static/src/xml/im_common.xml index 0cf788aab49..fac6a57b146 100644 --- a/addons/im/static/src/xml/im_common.xml +++ b/addons/im/static/src/xml/im_common.xml @@ -3,13 +3,12 @@
- - +
- + All users are offline. They will receive your messages on their next connection.
@@ -19,6 +18,13 @@
+ + + + + + +
From 13a4d995680cae09cd2ce8923f7c87fb65e45227 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 2 Sep 2013 18:15:17 +0200 Subject: [PATCH 3/6] Fixed small bug in live support bzr revid: nicolas.vanhoren@openerp.com-20130902161517-2ljcr13d96sz0q9r --- addons/im_livechat/static/ext/static/js/livesupport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/im_livechat/static/ext/static/js/livesupport.js b/addons/im_livechat/static/ext/static/js/livesupport.js index 5ccdbd66cb7..b8bad166fa8 100644 --- a/addons/im_livechat/static/ext/static/js/livesupport.js +++ b/addons/im_livechat/static/ext/static/js/livesupport.js @@ -110,7 +110,7 @@ define(["openerp", "im_common", "underscore", "require", "jquery", conv.received_message({ message: self.options.defaultMessage, date: openerp.datetime_to_str(new Date()), - from_id: [conv.users[0].get("id"), "Unknown"] + from_id: [conv.get("users")[0].get("id"), "Unknown"] }); } }); From 1a82946928760ba9b37a12ab76c26851a9d60cab Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 2 Sep 2013 19:02:52 +0200 Subject: [PATCH 4/6] Now correctly send technical message. bzr revid: nicolas.vanhoren@openerp.com-20130902170252-nmp5kw1023jx65ij --- addons/im/im.py | 6 +-- addons/im/static/src/js/im.js | 3 +- addons/im/static/src/js/im_common.js | 80 ++++++++++++++++++---------- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/addons/im/im.py b/addons/im/im.py index 15078a50fea..2ca3a7d2444 100644 --- a/addons/im/im.py +++ b/addons/im/im.py @@ -169,7 +169,7 @@ class im_message(osv.osv): # how fun it is to always need to reorder results from read mess_ids = self.search(cr, openerp.SUPERUSER_ID, ["&", ['id', '>', last], "|", ['from_id', '=', my_id], ['to_id', 'in', [my_id]]], order="id", context=context) - mess = self.read(cr, openerp.SUPERUSER_ID, mess_ids, ["id", "message", "from_id", "session_id", "date"], context=context) + mess = self.read(cr, openerp.SUPERUSER_ID, mess_ids, ["id", "message", "from_id", "session_id", "date", "technical"], context=context) index = {} for i in xrange(len(mess)): index[mess[i]["id"]] = mess[i] @@ -182,13 +182,13 @@ class im_message(osv.osv): users_status = users.read(cr, openerp.SUPERUSER_ID, users_watch, ["im_status"], context=context) return {"res": mess, "last": last, "dbname": cr.dbname, "users_status": users_status} - def post(self, cr, uid, message, to_session_id, uuid=None, technical=False, context=None): + def post(self, cr, uid, message, to_session_id, technical=False, uuid=None, context=None): assert_uuid(uuid) my_id = self.pool.get('im.user').get_my_id(cr, uid, uuid) session = self.pool.get('im.session').browse(cr, uid, to_session_id, context) to_ids = [x.id for x in session.user_ids if x.id != my_id] self.create(cr, openerp.SUPERUSER_ID, {"message": message, 'from_id': my_id, - 'to_id': [(6, 0, to_ids)], 'session_id': to_session_id, technical=technical}, context=context) + 'to_id': [(6, 0, to_ids)], 'session_id': to_session_id, 'technical': technical}, context=context) notify_channel(cr, "im_channel", {'type': 'message', 'receivers': [my_id] + to_ids}) return False diff --git a/addons/im/static/src/js/im.js b/addons/im/static/src/js/im.js index f26b8f5c4a2..085903cbde5 100644 --- a/addons/im/static/src/js/im.js +++ b/addons/im/static/src/js/im.js @@ -18,7 +18,8 @@ im_common.notification = function(message) { instance.client.do_warn(message); }; - im_common.connection = openerp.session; + // TODO: allow to use a different host for the chat + im_common.connection = new openerp.Session(self, null, {session_id: openerp.session.session_id}); var im = new instance.im.InstantMessaging(self); im.appendTo(instance.client.$el); diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 708c9cd25f0..850218a257b 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -242,9 +242,14 @@ function declare($, _, openerp) { } var defs = []; _.each(messages, function(message) { - defs.push(self.activate_session(message.session_id[0]).then(function(conv) { - return conv.received_message(message); - })); + if (! message.technical) { + defs.push(self.activate_session(message.session_id[0]).then(function(conv) { + return conv.received_message(message); + })); + } else { + var json = JSON.parse(message.message); + defs.push($.when(im_common.technical_messages_handlers[json.type](self, message))); + } }); return $.when.apply($, defs); }, @@ -267,7 +272,7 @@ function declare($, _, openerp) { im_common.Conversation = openerp.Widget.extend({ className: "openerp_style oe_im_chatview", events: { - "keydown input": "send_message", + "keydown input": "keydown", "click .oe_im_chatview_close": "destroy", "click .oe_im_chatview_header": "show_hide" }, @@ -289,6 +294,7 @@ function declare($, _, openerp) { var self = this; self.$().append(openerp.qweb.render("im_common.conversation", {widget: self})); + this.$().hide(); var change_status = function() { var disconnected = _.every(this.get("users"), function(u) { return u.get("im_status") === false; }); @@ -304,34 +310,47 @@ function declare($, _, openerp) { user.on("change:im_status", self, change_status); }); change_status.call(self); + _.each(ev.oldValue, function(user) { + if (! _.contains(ev.newValue, user)) { + user.remove_watcher(); + } + }); + _.each(ev.newValue, function(user) { + if (! _.contains(ev.oldValue, user)) { + user.add_watcher(); + } + }); }); this.on("change:disconnected", this, function() { self.$().toggleClass("oe_im_chatview_disconnected_status", this.get("disconnected")); self._go_bottom(); }); + self.on("change:right_position", self, self.calc_pos); + self.on("change:bottom_position", self, self.calc_pos); + self.full_height = self.$().height(); + self.calc_pos(); + self.on("change:pending", self, _.bind(function() { + if (self.get("pending") === 0) { + self.$(".oe_im_chatview_nbr_messages").text(""); + } else { + self.$(".oe_im_chatview_nbr_messages").text("(" + self.get("pending") + ")"); + } + }, self)); + + return this.refresh_users().then(function() { + self.$().show(); + }); + }, + refresh_users: function() { + var self = this; var user_ids; return im_common.connection.model("im.session").call("read", [self.session_id]).then(function(session) { user_ids = _.without(session.user_ids, self.c_manager.me.get("id")); return self.c_manager.ensure_users(session.user_ids); }).then(function() { var users = _.map(user_ids, function(id) {return self.c_manager.get_user(id);}); - _.each(users, function(user) { - user.add_watcher(); - }); self.set("users", users); - - self.on("change:right_position", self, self.calc_pos); - self.on("change:bottom_position", self, self.calc_pos); - self.full_height = self.$().height(); - self.calc_pos(); - self.on("change:pending", self, _.bind(function() { - if (self.get("pending") === 0) { - self.$(".oe_im_chatview_nbr_messages").text(""); - } else { - self.$(".oe_im_chatview_nbr_messages").text("(" + self.get("pending") + ")"); - } - }, self)); }); }, show_hide: function() { @@ -368,7 +387,7 @@ function declare($, _, openerp) { this._add_bubble(user, message.message, openerp.str_to_datetime(message.date)); }, this)); }, - send_message: function(e) { + keydown: function(e) { if(e && e.which !== 13) { return; } @@ -377,9 +396,13 @@ function declare($, _, openerp) { return; } this.$("input").val(""); + this.send_message(mes); + }, + send_message: function(message, technical) { + technical = technical || false; var send_it = _.bind(function() { var model = im_common.connection.model("im.message"); - return model.call("post", [mes, this.session_id], {uuid: this.c_manager.me.get("uuid"), context: {}}); + return model.call("post", [message, this.session_id, technical], {uuid: this.c_manager.me.get("uuid"), context: {}}); }, this); var tries = 0; send_it().then(_.bind(function() {}, function(error, e) { @@ -415,12 +438,7 @@ function declare($, _, openerp) { return; im_common.connection.model("im.session").call("add_to_session", [this.session_id, user.get("id"), this.c_manager.me.get("uuid")]).then(_.bind(function() { - if (_.contains(this.others, user)) { - this.others = _.without(this.others, user); - } else { - user.add_watcher(); - } - this.set("users", this.get("users").concat([user])); + this.send_message(JSON.stringify({"type": "session_modified"}), true); }, this)); }, focus: function() { @@ -440,6 +458,14 @@ function declare($, _, openerp) { } }); + im_common.technical_messages_handlers = {}; + + im_common.technical_messages_handlers.session_modified = function(c_manager, message) { + c_manager.activate_session(message.session_id[0], true).then(function(conv) { + conv.refresh_users(); + }); + }; + return im_common; } From d8bbbdf7c576d1892c6a0487876fe8a12e0ceb41 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 2 Sep 2013 19:29:23 +0200 Subject: [PATCH 5/6] wip bzr revid: nicolas.vanhoren@openerp.com-20130902172923-n0ofkb51orxfrq75 --- addons/im/im.py | 20 +++++++++-------- addons/im/static/src/js/im.js | 9 ++------ addons/im/static/src/js/im_common.js | 32 ++++++++++++++++++++++------ addons/im_livechat/im_livechat.py | 2 +- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/addons/im/im.py b/addons/im/im.py index 2ca3a7d2444..268ab57496f 100644 --- a/addons/im/im.py +++ b/addons/im/im.py @@ -207,19 +207,21 @@ class im_session(osv.osv): } # Todo: reuse existing sessions if possible - def session_get(self, cr, uid, user_to, uuid=None, context=None): + def session_get(self, cr, uid, users_to, uuid=None, context=None): my_id = self.pool.get("im.user").get_my_id(cr, uid, uuid, context=context) + users = [my_id] + users_to + domain = [] + for user_to in users: + domain.append(('user_ids', 'in', [user_to])) + sids = self.search(cr, openerp.SUPERUSER_ID, domain, context=context, limit=1) session_id = None - if user_to: - # FP Note: does the ORM allows something better than this? == on many2many - sids = self.search(cr, openerp.SUPERUSER_ID, [('user_ids', 'in', [user_to]), ('user_ids', 'in', [my_id])], context=context, limit=1) - for session in self.browse(cr, uid, sids, context=context): - if len(session.user_ids) == 2: - session_id = session.id - break + for session in self.browse(cr, uid, sids, context=context): + if len(session.user_ids) == len(users): + session_id = session.id + break if not session_id: session_id = self.create(cr, openerp.SUPERUSER_ID, { - 'user_ids': [(6, 0, [user_to, my_id])] + 'user_ids': [(6, 0, users)] }, context=context) return self.read(cr, uid, session_id, context=context) diff --git a/addons/im/static/src/js/im.js b/addons/im/static/src/js/im.js index 085903cbde5..79248b647e4 100644 --- a/addons/im/static/src/js/im.js +++ b/addons/im/static/src/js/im.js @@ -55,6 +55,7 @@ this.set("current_search", ""); this.users = []; this.c_manager = new im_common.ConversationManager(this); + window.im_conversation_manager = this.c_manager; this.on("change:right_offset", this.c_manager, _.bind(function() { this.c_manager.set("right_offset", this.get("right_offset")); }, this)); @@ -106,7 +107,7 @@ _.each(users, function(user) { var widget = new instance.im.UserWidget(self, self.c_manager.get_user(user.id)); widget.appendTo(self.$(".oe_im_users")); - widget.on("activate_user", self, self.activate_user); + widget.on("activate_user", self, function(user) {self.c_manager.chat_with_users([user]);}); self.users.push(widget); }); _.each(old_users, function(user) { @@ -136,12 +137,6 @@ } this.shown = ! this.shown; }, - activate_user: function(user) { - var self = this; - im_common.connection.model("im.session").call("session_get", [user.get("id"), self.c_manager.me.get("uuid")]).then(function(session) { - self.c_manager.activate_session(session.id, true); - }); - }, add_user: function(conversation, user) { conversation.add_user(user); }, diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 850218a257b..14de2d6363e 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -141,12 +141,16 @@ function declare($, _, openerp) { no_cache[el] = el; }, this); var self = this; + var def; if (_.size(no_cache) === 0) - return $.when(); + def = $.when(); else - return im_common.connection.model("im.user").call("read", [_.values(no_cache), []]).then(function(users) { + def = im_common.connection.model("im.user").call("read", [_.values(no_cache), []]).then(function(users) { self.add_to_user_cache(users); }); + return def.then(function() { + return _.map(user_ids, function(id) { return self.get_user(id); }); + }); }, add_to_user_cache: function(user_recs) { _.each(user_recs, function(user_rec) { @@ -211,6 +215,21 @@ function declare($, _, openerp) { openerp.webclient.set_title_part("im_messages", this.get("waiting_messages") === 0 ? undefined : _.str.sprintf(_t("%d Messages"), this.get("waiting_messages"))); }, + chat_with_users: function(users) { + var self = this; + return im_common.connection.model("im.session").call("session_get", [_.map(users, function(user) {return user.get("id");}), + self.me.get("uuid")]).then(function(session) { + return self.activate_session(session.id, true); + }); + }, + chat_with_all_users: function() { + var self = this; + return im_common.connection.model("im.user").call("search", [[["uuid", "=", false]]]).then(function(user_ids) { + return self.ensure_users(_.without(user_ids, self.me.get("id"))); + }).then(function(users) { + return self.chat_with_users(users); + }); + }, activate_session: function(session_id, focus) { var conv = _.find(this.conversations, function(conv) {return conv.session_id == session_id;}); var def = $.when(); @@ -347,9 +366,8 @@ function declare($, _, openerp) { var user_ids; return im_common.connection.model("im.session").call("read", [self.session_id]).then(function(session) { user_ids = _.without(session.user_ids, self.c_manager.me.get("id")); - return self.c_manager.ensure_users(session.user_ids); - }).then(function() { - var users = _.map(user_ids, function(id) {return self.c_manager.get_user(id);}); + return self.c_manager.ensure_users(user_ids); + }).then(function(users) { self.set("users", users); }); }, @@ -378,8 +396,8 @@ function declare($, _, openerp) { } else { this.set("pending", this.get("pending") + 1); } - this.c_manager.ensure_users([message.from_id[0]]).then(_.bind(function() { - var user = this.c_manager.get_user(message.from_id[0]); + this.c_manager.ensure_users([message.from_id[0]]).then(_.bind(function(users) { + var user = users[0]; if (! _.contains(this.get("users"), user) && ! _.contains(this.others, user)) { this.others.push(user); user.add_watcher(); diff --git a/addons/im_livechat/im_livechat.py b/addons/im_livechat/im_livechat.py index c8060b3fe92..81d3d61c6b4 100644 --- a/addons/im_livechat/im_livechat.py +++ b/addons/im_livechat/im_livechat.py @@ -175,7 +175,7 @@ class im_livechat_channel(osv.osv): if len(users) == 0: return False user_id = random.choice(users).id - session = self.pool.get("im.session").session_get(cr, uid, user_id, uuid, context=context) + session = self.pool.get("im.session").session_get(cr, uid, [user_id], uuid, context=context) self.pool.get("im.session").write(cr, openerp.SUPERUSER_ID, session.get("id"), {'channel_id': channel_id}, context=context) return session.get("id") From 6c6169da1b495fe70625d616673bb05113a3659b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 2 Sep 2013 19:36:59 +0200 Subject: [PATCH 6/6] Added critical feature bzr revid: nicolas.vanhoren@openerp.com-20130902173659-r5tl8ds8djcjdrb2 --- addons/im/static/src/js/im.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/im/static/src/js/im.js b/addons/im/static/src/js/im.js index 79248b647e4..6fbf452f974 100644 --- a/addons/im/static/src/js/im.js +++ b/addons/im/static/src/js/im.js @@ -170,4 +170,8 @@ }, }); + im_common.technical_messages_handlers.force_kitten = function() { + openerp.webclient.to_kitten(); + }; + })(); \ No newline at end of file