Implemented message to specific user
bzr revid: nicolas.vanhoren@openerp.com-20121127135155-7ndbfraqw0g7rn78
This commit is contained in:
+7
-5
@@ -106,21 +106,23 @@ class im_message(osv.osv):
|
||||
_name = 'im.message'
|
||||
_columns = {
|
||||
'message': fields.char(string="Message", size=200, required=True),
|
||||
'from': fields.many2one("res.users", "From", required= True, ondelete='cascade'),
|
||||
'to': fields.many2one("res.users", "From", required=True, select=True, ondelete='cascade'),
|
||||
}
|
||||
|
||||
def get_messages(self, cr, uid, last=None, context=None):
|
||||
if not last:
|
||||
tmp = self.search(cr, uid, [], order="id desc", limit=1, context=context)
|
||||
last = tmp[0] if len(tmp) else 0
|
||||
res = self.search(cr, uid, [['id', '>', last]], order="id", context=context)
|
||||
tmp = self.search(cr, uid, [['to', '=', uid]], order="id desc", limit=1, context=context)
|
||||
last = tmp[0] if len(tmp) >= 1 else -1
|
||||
res = self.search(cr, uid, [['id', '>', last], ['to', '=', uid]], order="id", context=context)
|
||||
res = self.read(cr, uid, res, ["id", "message"], context=context)
|
||||
lst = [x["message"] for x in res]
|
||||
if len(lst) > 0:
|
||||
last = res[-1]["id"]
|
||||
return {"res": lst, "last": last, "dbname": cr.dbname}
|
||||
|
||||
def post(self, cr, uid, message, context=None):
|
||||
self.create(cr, uid, {"message": message}, context=context)
|
||||
def post(self, cr, uid, message, to_user_id, context=None):
|
||||
self.create(cr, uid, {"message": message, 'from': uid, 'to': to_user_id}, context=context)
|
||||
cr.commit()
|
||||
cr.execute("notify received_message")
|
||||
cr.commit()
|
||||
|
||||
@@ -73,10 +73,6 @@ openerp.web_im = function(instance) {
|
||||
});
|
||||
});
|
||||
},
|
||||
send_message: function(user_rec, mes) {
|
||||
var model = new instance.web.Model("im.message");
|
||||
model.call("post", [mes], {context: new instance.web.CompoundContext()});
|
||||
},
|
||||
switch_display: function() {
|
||||
var fct = _.bind(function() {
|
||||
this.set("right_offset", $(window).width() - this.$el.offset().left);
|
||||
@@ -156,7 +152,8 @@ openerp.web_im = function(instance) {
|
||||
}
|
||||
var mes = this.$("input").val();
|
||||
this.$("input").val("");
|
||||
this.im.send_message(this.user_rec, mes);
|
||||
var model = new instance.web.Model("im.message");
|
||||
model.call("post", [mes, this.user_rec.id], {context: new instance.web.CompoundContext()});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user