From 0c03661b568ac1adffb81455088d4f7c4ee4b81d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 3 Sep 2013 15:59:40 +0200 Subject: [PATCH 1/3] Added url detection bzr revid: nicolas.vanhoren@openerp.com-20130903135940-3miafvmwtiiuc769 --- addons/im/static/src/js/im_common.js | 22 ++++++++++++++++++++-- addons/im/static/src/xml/im_common.xml | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 14de2d6363e..d196632607c 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -443,8 +443,8 @@ function declare($, _, openerp) { return new Array(size - str.length + 1).join('0') + str; }; date = "" + zpad(date.getHours(), 2) + ":" + zpad(date.getMinutes(), 2); - - this.last_bubble = $(openerp.qweb.render("im_common.conversation_bubble", {"items": items, "user": user, "time": date})); + var to_show = _.map(items, im_common.escape_keep_url); + this.last_bubble = $(openerp.qweb.render("im_common.conversation_bubble", {"items": to_show, "user": user, "time": date})); $(this.$(".oe_im_chatview_content").children()[0]).append(this.last_bubble); this._go_bottom(); }, @@ -484,6 +484,24 @@ function declare($, _, openerp) { }); }; + var url_regex = /(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/gi; + + im_common.escape_keep_url = function(str) { + var last = 0; + var txt = ""; + while (true) { + var result = url_regex.exec(str); + if (! result) + break; + txt += _.escape(str.slice(last, result.index)); + last = url_regex.lastIndex; + var url = _.escape(result[0]); + txt += '' + url + ''; + } + txt += str.slice(last, str.length); + return txt; + }; + return im_common; } diff --git a/addons/im/static/src/xml/im_common.xml b/addons/im/static/src/xml/im_common.xml index fac6a57b146..462e242befd 100644 --- a/addons/im/static/src/xml/im_common.xml +++ b/addons/im/static/src/xml/im_common.xml @@ -33,7 +33,7 @@
-
+
From acea8a695b97482114c052662a4731b60fff40fc Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 4 Sep 2013 11:57:46 +0200 Subject: [PATCH 2/3] Does not open window all the time when the session is modified bzr revid: nicolas.vanhoren@openerp.com-20130904095746-yyqq7wh1h38x2ndx --- addons/im/static/src/js/im_common.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index d196632607c..2d7dcd1cae5 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -254,22 +254,25 @@ function declare($, _, openerp) { }, received_messages: function(messages) { var self = this; - if (! this.get("window_focus") && messages.length >= 1) { - this.set("waiting_messages", this.get("waiting_messages") + messages.length); - this.ting.play(); - this.create_ting(); - } var defs = []; + var received = false; _.each(messages, function(message) { if (! message.technical) { defs.push(self.activate_session(message.session_id[0]).then(function(conv) { + received = true; return conv.received_message(message); })); } else { var json = JSON.parse(message.message); + message.json = json; defs.push($.when(im_common.technical_messages_handlers[json.type](self, message))); } }); + if (! this.get("window_focus") && received) { + this.set("waiting_messages", this.get("waiting_messages") + messages.length); + this.ting.play(); + this.create_ting(); + } return $.when.apply($, defs); }, calc_positions: function() { @@ -456,7 +459,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() { - this.send_message(JSON.stringify({"type": "session_modified"}), true); + this.send_message(JSON.stringify({"type": "session_modified", "action": "added", "user_id": user.get("id")}), true); }, this)); }, focus: function() { @@ -479,8 +482,15 @@ 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(); + var def = $.when(); + if (message.json.action === "added" && message.json.user_id === c_manager.me.get("id")) { + def = c_manager.activate_session(message.session_id[0], true); + } + return def.then(function() { + var conv = _.find(c_manager.conversations, function(conv) {return conv.session_id == message.session_id[0];}); + if (conv) + return conv.refresh_users(); + return undefined; }); }; From 85e52d1f86dfe60f1ca43fb81c7fb2c72d21cd95 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 4 Sep 2013 15:17:53 +0200 Subject: [PATCH 3/3] Now can disconnect from a group chat bzr revid: nicolas.vanhoren@openerp.com-20130904131753-bdp93e8vwtg4za7n --- addons/im/im.py | 4 ++++ addons/im/static/src/js/im_common.js | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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();