diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-09-02 19:29:23 +0200 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-09-02 19:29:23 +0200 |
| commit | d8bbbdf7c576d1892c6a0487876fe8a12e0ceb41 (patch) | |
| tree | 49eebcec2d50ec4f9a67f97a84d90af6a9e91bb5 /addons/im/static/src/js | |
| parent | 1a82946928760ba9b37a12ab76c26851a9d60cab (diff) | |
wip
bzr revid: nicolas.vanhoren@openerp.com-20130902172923-n0ofkb51orxfrq75
Diffstat (limited to 'addons/im/static/src/js')
| -rw-r--r-- | addons/im/static/src/js/im.js | 9 | ||||
| -rw-r--r-- | addons/im/static/src/js/im_common.js | 32 |
2 files changed, 27 insertions, 14 deletions
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(); |
