diff --git a/addons/im/im.py b/addons/im/im.py index 268ab57496f..f91017e1712 100644 --- a/addons/im/im.py +++ b/addons/im/im.py @@ -232,6 +232,10 @@ class im_session(osv.osv): 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) + def remove_me_from_session(self, cr, uid, session_id, uuid=None, context=None): + my_id = self.pool.get("im.user").get_my_id(cr, uid, uuid, context=context) + self.write(cr, openerp.SUPERUSER_ID, session_id, {"user_ids": [(3, my_id)]}, context=context) + class im_user(osv.osv): _name = "im.user" diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 2d7dcd1cae5..e0692edca2b 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -295,7 +295,7 @@ function declare($, _, openerp) { className: "openerp_style oe_im_chatview", events: { "keydown input": "keydown", - "click .oe_im_chatview_close": "destroy", + "click .oe_im_chatview_close": "close", "click .oe_im_chatview_header": "show_hide" }, init: function(parent, c_manager, session_id, options) { @@ -467,6 +467,20 @@ function declare($, _, openerp) { if (! this.shown) this.show_hide(); }, + close: function() { + var def = $.when(); + if (this.get("users").length > 1) { + def = im_common.connection.model("im.session").call("remove_me_from_session", + [this.session_id, this.c_manager.me.get("uuid")]).then(_.bind(function() { + return this.send_message(JSON.stringify({"type": "session_modified", "action": "removed", + "user_id": this.c_manager.me.get("id")}), true) + }, this)) + } + + return def.then(_.bind(function() { + this.destroy(); + }, this)); + }, destroy: function() { _.each(this.get("users"), function(user) { user.remove_watcher();