Make group chat really work

bzr revid: nicolas.vanhoren@openerp.com-20130902160811-fkdleeurq1g9msi2
This commit is contained in:
niv-openerp 2013-09-02 18:08:11 +02:00
parent b4b74f9a20
commit ee19c62e0a
4 changed files with 44 additions and 22 deletions

View File

@ -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

View File

@ -183,7 +183,6 @@
}
.oe_im_chatview_online {
display: none;
margin-top: -4px;
width: 11px;
height: 11px;

View File

@ -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) {

View File

@ -3,13 +3,12 @@
<templates>
<t t-name="im_common.conversation">
<div class="oe_im_chatview_header">
<img t-att-src="to_url('/im/static/src/img/green.png')" class="oe_im_chatview_online"/>
<t t-esc="widget.users[0].get('name')"/>
<span class="oe_im_chatview_users"/>
<scan class="oe_im_chatview_nbr_messages" />
<button class="oe_im_chatview_close">×</button>
</div>
<div class="oe_im_chatview_disconnected">
<t t-esc='widget.users[0].get("name") + _t(" is offline. He/She will receive your messages on his/her next connection.")'/>
All users are offline. They will receive your messages on their next connection.
</div>
<div class="oe_im_chatview_content">
<div></div>
@ -19,6 +18,13 @@
</div>
</t>
<t t-name="im_common.conversation.header">
<span t-foreach="widget.get('users')" t-as="user">
<img t-if="user.get('im_status')" t-att-src="to_url('/im/static/src/img/green.png')" class="oe_im_chatview_online"/>
<t t-esc="user.get('name')"/>
</span>
</t>
<t t-name="im_common.conversation_bubble">
<div class="oe_im_chatview_bubble">
<div class="oe_im_chatview_clip">