[IMP]mail, openchatter: read/unread

bzr revid: chm@openerp.com-20121016082718-j0vlptofi2w0hikw
This commit is contained in:
Christophe Matthieu
2012-10-16 10:27:18 +02:00
parent 29183b9161
commit 7084273c5c
5 changed files with 32 additions and 35 deletions
+25 -29
View File
@@ -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):
+1 -1
View File
@@ -59,7 +59,7 @@
<field name="partner_ids"/>
<filter string="Unread"
name="unread_message" help="Show unread message"
domain="[('unread', '=', True)]"/>
domain="[('read', '=', 'unread')]"/>
<filter string="Comments"
name="comments" help="Comments"
domain="[('type', '=', 'comment')]"/>
+1 -1
View File
@@ -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):
+2 -1
View File
@@ -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,
+3 -3
View File
@@ -180,14 +180,14 @@
</div>
<!-- default layout -->
<li t-name="mail.thread.message" t-attf-class="oe_mail oe_mail_thread_msg #{widget.datasets.unread?'oe_mail_unread':'oe_mail_read'}">
<li t-name="mail.thread.message" t-attf-class="oe_mail oe_mail_thread_msg #{!widget.datasets.read ? 'oe_mail_undefined_read' : (widget.datasets.read=='read'?'oe_mail_read':'oe_mail_unread')}">
<div t-attf-class="oe_mail_msg_#{widget.datasets.type} oe_semantic_html_override">
<!-- message actions (read/unread, reply, delete...) -->
<ul class="oe_header">
<li class="placeholder-mail-vote"><t t-call="mail.thread.message.vote"/></li>
<li class="placeholder-mail-star"><t t-call="mail.thread.message.star"/></li>
<li t-if="!widget.options.thread.display_on_flat" title="Read" class="oe_read"><a class="oe_read oe_e">W</a></li>
<li t-if="!widget.options.thread.display_on_flat" title="Set back to unread" class="oe_unread"><a class="oe_unread oe_e">h</a></li>
<li t-if="!widget.options.thread.display_on_flat and widget.datasets.read=='unread'" title="Read" class="oe_read"><a class="oe_read oe_e">W</a></li>
<li t-if="!widget.options.thread.display_on_flat and widget.datasets.read=='read'" title="Set back to unread" class="oe_unread"><a class="oe_unread oe_e">h</a></li>
<li title="Quick reply"><a class="oe_reply oe_e">)</a></li>
<t t-if="(widget.datasets.is_author and widget.options.message.show_dd_delete) or widget.datasets.type == 'email'">
<li>