From 7084273c5cc620ecd0612864ff53ddd753338d3e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 16 Oct 2012 10:27:18 +0200 Subject: [PATCH] [IMP]mail, openchatter: read/unread bzr revid: chm@openerp.com-20121016082718-j0vlptofi2w0hikw --- addons/mail/mail_message.py | 54 +++++++++++++---------------- addons/mail/mail_message_view.xml | 2 +- addons/mail/mail_thread.py | 2 +- addons/mail/static/src/js/mail.js | 3 +- addons/mail/static/src/xml/mail.xml | 6 ++-- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index cf05cd1fc54..d945c93a815 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -67,27 +67,25 @@ class mail_message(osv.Model): pass return result - def _get_unread(self, cr, uid, ids, name, arg, context=None): - """ Compute if the message is unread by the current user. """ - res = dict((id, {'unread': False}) for id in ids) + def _get_read(self, cr, uid, ids, name, arg, context=None): + """ Compute if the message is read by the current user. """ + res = dict((id, {'read': False}) for id in ids) partner_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] notif_obj = self.pool.get('mail.notification') notif_ids = notif_obj.search(cr, uid, [ ('partner_id', 'in', [partner_id]), - ('message_id', 'in', ids), - ('read', '=', False) + ('message_id', 'in', ids) ], context=context) for notif in notif_obj.browse(cr, uid, notif_ids, context=context): - res[notif.message_id.id]['unread'] = True + res[notif.message_id.id] = notif.read and 'read' or 'unread' return res - def _search_unread(self, cr, uid, obj, name, domain, context=None): - """ Search for messages unread by the current user. Condition is - inversed because we search unread message on a read column. """ + def _search_read(self, cr, uid, obj, name, domain, context=None): + """ Search for messages read by the current user. """ if domain[0][2]: - read_cond = '(read = false or read is null)' + read_cond = "(read = False OR read IS NULL)" else: - read_cond = 'read = true' + read_cond = "read = True" partner_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] cr.execute("SELECT message_id FROM mail_notification "\ "WHERE partner_id = %%s AND %s" % read_cond, @@ -128,9 +126,9 @@ class mail_message(osv.Model): 'date': fields.datetime('Date'), 'message_id': fields.char('Message-Id', help='Message unique identifier', select=1, readonly=1), 'body': fields.html('Contents', help='Automatically sanitized HTML contents'), - 'unread': fields.function(_get_unread, fnct_search=_search_unread, - type='boolean', string='Unread', - help='Functional field to search for unread messages linked to uid'), + 'read': fields.function(_get_read, fnct_search=_search_read, + type='boolean', string='Read', + help='Functional field to search for read messages linked to uid'), 'subtype_id': fields.many2one('mail.message.subtype', 'Subtype'), 'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', string='Votes', help='Users that voted for this message'), @@ -141,7 +139,7 @@ class mail_message(osv.Model): def _needaction_domain_get(self, cr, uid, context=None): if self._needaction: - return [('unread', '=', True)] + return [('read', '=', 'unread')] return [] def _get_default_author(self, cr, uid, context=None): @@ -236,8 +234,6 @@ class mail_message(osv.Model): except (orm.except_orm, osv.except_osv): record_name = False - - return { 'id': msg.id, 'type': msg.type, @@ -256,7 +252,7 @@ class mail_message(osv.Model): 'vote_user_ids': vote_ids, 'has_voted': has_voted, 'has_stared': has_stared, - 'unread': msg.unread and msg.unread['unread'] or False + 'read': msg.read } def _message_read_expandable(self, cr, uid, tree, result, message_loaded_ids, domain, context, parent_id, limit): @@ -350,11 +346,6 @@ class mail_message(osv.Model): if context and context.get('message_loaded'): domain += [ ['id','not in',message_loaded_ids] ]; - print "" - print context - print domain - print "" - limit = limit or self._message_read_limit context = context or {} @@ -367,6 +358,11 @@ class mail_message(osv.Model): for msg in self.browse(cr, uid, ids, context=context): message_ids.append(msg.id) + result = [] + for msg in self.browse(cr, uid, message_ids, context=context): + record = self._message_dict_get(cr, uid, msg, context=context) + result.append( record ) + # key: ID, value: tree if not ids: ids = self.search(cr, uid, domain, context=context, limit=limit) @@ -395,15 +391,15 @@ class mail_message(osv.Model): except (orm.except_orm, osv.except_osv): parent = False - result = [] - for msg in self.browse(cr, uid, message_ids, context=context): - record = self._message_dict_get(cr, uid, msg, context=context) - result.append( record ) + result = [] + for msg in self.browse(cr, uid, message_ids, context=context): + record = self._message_dict_get(cr, uid, msg, context=context) + result.append( record ) + + result = self._message_read_expandable(cr, uid, tree, result, message_loaded_ids, domain, context, parent_id, limit) result = sorted(result, key=lambda k: k['id']) - result = self._message_read_expandable(cr, uid, tree, result, message_loaded_ids, domain, context, parent_id, limit) - return result def user_free_attachment(self, cr, uid, context=None): diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index a0335930b54..d59eb800261 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -59,7 +59,7 @@ + domain="[('read', '=', 'unread')]"/> diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 2d6f8382157..a0fb1deec55 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -714,7 +714,7 @@ class mail_thread(osv.AbstractModel): self.pool.get('ir.attachment').write(cr, 1, attachment_ids, { 'res_model': self._name, 'res_id': thread_id }, context=context) self.pool.get('mail.message').write(cr, 1, [added_message_id], {'attachment_ids': [(6, 0, [pid for pid in attachment_ids])]} ) - added_message = self.pool.get('mail.message').message_read(cr, uid, [added_message_id], [['id','=',added_message_id]],context=context) + added_message = self.pool.get('mail.message').message_read(cr, uid, [added_message_id]) return added_message def get_message_subtypes(self, cr, uid, ids, context=None): diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 1974d4004a0..295ab4a91a3 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -489,7 +489,7 @@ openerp.mail = function(session) { 'has_voted' : false, 'has_stared' : false, 'thread_level' : 0, - 'unread' : false, + 'read' : false, 'author_id' : [], 'attachment_ids' : [], }, param || {}); @@ -1110,6 +1110,7 @@ openerp.mail = function(session) { /* Send the records to his parent thread */ switch_new_message: function(records) { var self=this; + console.log(records); _(records).each(function(record){ self.browse_thread({ 'id': record.parent_id, diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 49857522250..c9551d91f6c 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -180,14 +180,14 @@ -
  • +