Thibault Delavallée (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-fix-unread-results-tde into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-fix-unread-results-tde/+merge/140913
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-fix-unread-results-tde/+merge/140913
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-fix-unread-results-tde.
=== modified file 'mail/mail_group.py'
--- mail/mail_group.py	2012-12-17 14:43:06 +0000
+++ mail/mail_group.py	2012-12-20 14:52:31 +0000
@@ -134,14 +134,16 @@
             params = {
                 'search_view_id': search_ref and search_ref[1] or False,
                 'domain': [('model', '=', 'mail.group'), ('res_id', '=', mail_group_id)],
-                'context': {'default_model': 'mail.group', 'default_res_id': mail_group_id, 'search_default_message_unread': True},
+                'context': {'default_model': 'mail.group',
+                            'default_res_id': mail_group_id,
+                            'search_default_message_unread': True},
                 'res_model': 'mail.message',
                 'thread_level': 1,
                 'header_description': vals.get('description'),
             }
             cobj = self.pool.get('ir.actions.client')
             newref = cobj.copy(cr, SUPERUSER_ID, ref[1], default={'params': str(params), 'name': vals['name']}, context=context)
-            mobj.write(cr, SUPERUSER_ID, menu_id, { 'action': 'ir.actions.client,' + str(newref), 'mail_group_id': mail_group_id}, context=context)
+            mobj.write(cr, SUPERUSER_ID, menu_id, {'action': 'ir.actions.client,' + str(newref), 'mail_group_id': mail_group_id}, context=context)
 
         if vals.get('group_ids'):
             self._subscribe_users(cr, uid, [mail_group_id], context=context)

=== modified file 'mail/mail_message.py'
--- mail/mail_message.py	2012-12-20 12:17:52 +0000
+++ mail/mail_message.py	2012-12-20 14:52:31 +0000
@@ -492,6 +492,7 @@
         message_unload_ids = message_unload_ids if message_unload_ids is not None else []
         if message_unload_ids:
             domain += [('id', 'not in', message_unload_ids)]
+        notification_obj = self.pool.get('mail.notification')
         limit = limit or self._message_read_limit
         message_tree = {}
         message_list = []
@@ -529,10 +530,17 @@
                 message_id_list.sort(key=lambda item: item['id'])
                 message_id_list.insert(0, self._message_read_dict(cr, uid, message_tree[key], context=context))
 
+        # create final ordered message_list based on parent_tree
         parent_list = parent_tree.items()
         parent_list = sorted(parent_list, key=lambda item: max([msg.get('id') for msg in item[1]]) if item[1] else item[0], reverse=True)
         message_list = [message for (key, msg_list) in parent_list for message in msg_list]
 
+        # if requested: mark messages as read
+        if context and context.get('mail_read_set_read'):
+            message_ids = [message.get('id') for message in message_list]
+            unread_notif_ids = notification_obj.search(cr, uid, [('read', '=', False), ('partner_id.user_ids', 'in', uid), ('message_id', 'in', message_ids)], context=context)
+            notification_obj.write(cr, uid, unread_notif_ids, {'read': True}, context=context)
+
         # get the child expandable messages for the tree
         self._message_read_dict_postprocess(cr, uid, message_list, message_tree, context=context)
         self._message_read_add_expandables(cr, uid, message_list, message_tree, parent_tree,
@@ -600,12 +608,14 @@
                 model_ids.setdefault(message.get('model'), {}).setdefault(message.get('res_id'), set()).add(message.get('id'))
 
         allowed_ids = self._find_allowed_doc_ids(cr, uid, model_ids, context=context)
-
         final_ids = author_ids | partner_ids | allowed_ids
+
         if count:
             return len(final_ids)
         else:
-            return list(final_ids)
+            # re-construct a list based on ids, because set did not keep the original order
+            id_list = [id for id in ids if id in final_ids]
+            return id_list
 
     def check_access_rule(self, cr, uid, ids, operation, context=None):
         """ Access rules of mail.message:

=== modified file 'mail/static/src/js/mail.js'
--- mail/static/src/js/mail.js	2012-12-17 09:35:01 +0000
+++ mail/static/src/js/mail.js	2012-12-20 14:52:31 +0000
@@ -1540,6 +1540,7 @@
                 'show_compose_message': this.view.is_action_enabled('edit'),
             });
             this.node.context = {
+                'mail_read_set_read': true,  // set messages as read in Chatter
                 'default_res_id': this.view.datarecord.id || false,
                 'default_model': this.view.model || false,
             };

=== modified file 'mail/tests/test_message_read.py'
--- mail/tests/test_message_read.py	2012-12-18 13:11:42 +0000
+++ mail/tests/test_message_read.py	2012-12-20 14:52:31 +0000
@@ -26,7 +26,8 @@
 
     def test_00_message_read(self):
         """ Tests for message_read and expandables. """
-        cr, uid, user_admin, group_pigs = self.cr, self.uid, self.user_admin, self.group_pigs
+        cr, uid, user_admin, user_raoul, group_pigs = self.cr, self.uid, self.user_admin, self.user_raoul, self.group_pigs
+        self.mail_group.message_subscribe_users(cr, uid, [group_pigs.id], [user_raoul.id])
         pigs_domain = [('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)]
 
         # Data: create a discussion in Pigs (3 threads, with respectively 0, 4 and 4 answers)
@@ -44,20 +45,32 @@
         msg_ids = [msg_id10, msg_id9, msg_id8, msg_id7, msg_id6, msg_id5, msg_id4, msg_id3, msg_id2, msg_id1, msg_id0]
         ordered_msg_ids = [msg_id2, msg_id4, msg_id6, msg_id8, msg_id10, msg_id1, msg_id3, msg_id5, msg_id7, msg_id9, msg_id0]
 
+        # Test: raoul received notifications
+        raoul_notification_ids = self.mail_notification.search(cr, user_raoul.id, [('read', '=', False), ('message_id', 'in', msg_ids), ('partner_id', '=', user_raoul.partner_id.id)])
+        self.assertEqual(len(raoul_notification_ids), 11, 'message_post: wrong number of produced notifications')
+
         # Test: read some specific ids
-        read_msg_list = self.mail_message.message_read(cr, uid, ids=msg_ids[2:4], domain=[('body', 'like', 'dummy')])
+        read_msg_list = self.mail_message.message_read(cr, user_raoul.id, ids=msg_ids[2:4], domain=[('body', 'like', 'dummy')], context={'mail_read_set_read': True})
         read_msg_ids = [msg.get('id') for msg in read_msg_list]
         self.assertEqual(msg_ids[2:4], read_msg_ids, 'message_read with direct ids should read only the requested ids')
 
+        # Test: raoul notifications are read
+        raoul_notification_ids = self.mail_notification.search(cr, user_raoul.id, [('read', '=', False), ('message_id', 'in', msg_ids), ('partner_id', '=', user_raoul.partner_id.id)])
+        self.assertEqual(len(raoul_notification_ids), 9, 'message_post: wrong number of produced and/or read notifications')
+
         # Test: read messages of Pigs through a domain, being thread or not threaded
-        read_msg_list = self.mail_message.message_read(cr, uid, domain=pigs_domain, limit=200)
+        read_msg_list = self.mail_message.message_read(cr, user_raoul.id, domain=pigs_domain, limit=200)
         read_msg_ids = [msg.get('id') for msg in read_msg_list]
         self.assertEqual(msg_ids, read_msg_ids, 'message_read flat with domain on Pigs should equal all messages of Pigs')
-        read_msg_list = self.mail_message.message_read(cr, uid, domain=pigs_domain, limit=200, thread_level=1)
+        read_msg_list = self.mail_message.message_read(cr, user_raoul.id, domain=pigs_domain, limit=200, thread_level=1)
         read_msg_ids = [msg.get('id') for msg in read_msg_list]
         self.assertEqual(ordered_msg_ids, read_msg_ids,
             'message_read threaded with domain on Pigs should equal all messages of Pigs, and sort them with newer thread first, last message last in thread')
 
+        # Test: raoul notifications did not change
+        raoul_notification_ids = self.mail_notification.search(cr, user_raoul.id, [('read', '=', False), ('message_id', 'in', msg_ids), ('partner_id', '=', user_raoul.partner_id.id)])
+        self.assertEqual(len(raoul_notification_ids), 9, 'message_post: wrong number of produced and/or read notifications')
+
         # ----------------------------------------
         # CASE1: message_read with domain, threaded
         # We simulate an entire flow, using the expandables to test them

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to