[IMP] Added the possibility to override the fetch_messages of a Thread by giving it the messages to display (used in the wall that fetches pushed messages). Also moved get_pushed_messages from mail.message to mail.thread to have a consistent API.

bzr revid: tde@openerp.com-20120223174936-3qnwj3t7z3ss0tr3
This commit is contained in:
Thibault Delavallée 2012-02-23 18:49:36 +01:00
parent 62adec0478
commit 90b9ad4556
3 changed files with 22 additions and 18 deletions

View File

@ -204,18 +204,6 @@ class mail_message(osv.osv):
msg_id = super(mail_message, self).create(cr, uid, vals, context)
return msg_id
def get_pushed_messages(self, cr, uid, ids, filter_search=False, context=None):
"""OpenSocial: wall: get messages to display (=pushed notifications)
:param filter_search: TODO
:return: list of mail.messages, unsorted
"""
notification_obj = self.pool.get('mail.notification')
notification_ids = notification_obj.search(cr, uid, [('user_id', '=', uid)], context=context)
notifications = notification_obj.browse(cr, uid, notification_ids, context=context)
msg_ids = [notification.message_id.id for notification in notifications]
msgs = self.read(cr, uid, msg_ids, context=context)
return msgs
#------------------------------------------------------
# E-Mail api
#------------------------------------------------------

View File

@ -284,13 +284,25 @@ class mail_thread(osv.osv):
limit=limit, offset=offset, context=context)
return msg_ids
def message_load(self, cr, uid, ids, limit=50, offset=0, context=None):
def message_load(self, cr, uid, ids, limit=5, offset=0, context=None):
""" OpenSocial feature: return thread messages
loading messages: search in mail.messages where res_id = ids, (res_)model = current model
"""
msg_ids = self.message_load_ids(cr, uid, ids, limit=limit, offset=offset, context=context)
return self.pool.get('mail.message').read(cr, uid, msg_ids, context=context)
def get_pushed_messages(self, cr, uid, ids, filter_search=False, limit=5, offset=0, context=None):
"""OpenSocial: wall: get messages to display (=pushed notifications)
:param filter_search: TODO
:return: list of mail.messages, unsorted
"""
notification_obj = self.pool.get('mail.notification')
notification_ids = notification_obj.search(cr, uid, [('user_id', '=', uid)], limit=limit, offset=offset, context=context)
notifications = notification_obj.browse(cr, uid, notification_ids, context=context)
msg_ids = [notification.message_id.id for notification in notifications]
msgs = self.pool.get('mail.message').read(cr, uid, msg_ids, context=context)
return msgs
#------------------------------------------------------
# Email specific
#------------------------------------------------------

View File

@ -18,6 +18,7 @@ openerp.mail = function(session) {
this.res_model = params['res_model'];
this.res_id = params['res_id'];
this.uid = params['uid'];
this.records = params['records'] || false;
/* DataSets */
this.ds = new session.web.DataSet(this, this.res_model);
this.ds_users = new session.web.DataSet(this, 'res.users');
@ -43,7 +44,8 @@ openerp.mail = function(session) {
});
/* display user, fetch comments */
this.display_current_user();
this.fetch_comments();
if (this.records == false) this.fetch_comments();
else this.display_comments(this.records);
},
stop: function () {
@ -228,7 +230,7 @@ openerp.mail = function(session) {
this._super(parent);
this.filter_search = params['filter_search'];
/* DataSets */
this.ds_msg = new session.web.DataSet(this, 'mail.message');
this.ds_thread = new session.web.DataSet(this, 'mail.thread');
this.ds_users = new session.web.DataSet(this, 'res.users');
},
@ -244,7 +246,7 @@ openerp.mail = function(session) {
},
fetch_comments: function () {
var load_res = this.ds_msg.call('get_pushed_messages', [[this.session.uid]]).then(
var load_res = this.ds_thread.call('get_pushed_messages', [[this.session.uid]]).then(
this.proxy('display_comments'));
return load_res;
},
@ -261,7 +263,9 @@ openerp.mail = function(session) {
'record_id': id,
});
$('<div class="oe_mail_wall_thread">').html(render_res).appendTo(self.$element.find('div.oe_mail_wall_threads'));
self.thread_display = new mail.ThreadDisplay(self, {'res_model': model, 'res_id': parseInt(id), 'uid': self.session.uid});
self.thread_display = new mail.ThreadDisplay(self,
{'res_model': model, 'res_id': parseInt(id), 'uid': self.session.uid, 'records': record_id}
);
self.thread_display.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last'));
});
});