[IMP] Added push of messages when creating one. Fixed bugs in mail_thread subscriptio...
authorThibault Delavallée <tde@openerp.com>
Thu, 2 Feb 2012 11:26:57 +0000 (12:26 +0100)
committerThibault Delavallée <tde@openerp.com>
Thu, 2 Feb 2012 11:26:57 +0000 (12:26 +0100)
bzr revid: tde@openerp.com-20120202112657-zj406ck98n06imo9

addons/mail/mail_message.py
addons/mail/mail_subscription.py
addons/mail/mail_subscription_view.xml
addons/mail/mail_thread.py

index 877ffd9..dfd2fe0 100644 (file)
@@ -71,8 +71,8 @@ class mail_message_common(osv.osv_memory):
     _rec_name = 'subject'
     _columns = {
         'subject': fields.char('Subject', size=512, required=True),
-        'model': fields.char('Related Document model', size=128, select=1), # was rfeadonly
-        'res_id': fields.integer('Related Document ID', select=1), # was rfeadonly
+        'model': fields.char('Related Document model', size=128, select=1), # was readonly
+        'res_id': fields.integer('Related Document ID', select=1), # was readonly
         'date': fields.datetime('Date'),
         'email_from': fields.char('From', size=128, help='Message sender, taken from user preferences. If empty, this is not a mail but a message.'),
         'email_to': fields.char('To', size=256, help='Message recipients'),
@@ -191,11 +191,23 @@ class mail_message(osv.osv):
     }
 
     #------------------------------------------------------
-    # Note specific api
+    # Generic api
     #------------------------------------------------------
     
     def create(self, cr, uid, vals, context=None):
-        return super(mail_message, self).create(cr, uid, vals, context)
+        msg_id = super(mail_message, self).create(cr, uid, vals, context)
+        # push the message to suscribed users
+        subscription_obj = self.pool.get('mail.subscription')
+        notification_obj = self.pool.get('mail.notification')
+        sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', vals['model']), ('user_id', '=', uid)], context=context)
+        subs = subscription_obj.browse(cr, uid, sub_ids, context=context)
+        for sub in subs:
+            notification_obj.create(cr, uid, {'user_id': sub.user_id, 'message_id': msg_id}, context=context)
+        return msg_id
+    
+    #------------------------------------------------------
+    # Note specific api
+    #------------------------------------------------------
     
     def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
         if not context or not context.has_key('filter_search'):
index f250ddc..89750c4 100644 (file)
@@ -30,7 +30,7 @@ class mail_subscription(osv.osv):
     A subscription can be of following:
     - res_model: model of the followed objects
     - res_id: ID of resource OR
-    - res_domain: a domain filtering followed objects
+    - res_domain: a domain filtering followed objects - currently removed
     """
     
     _name = 'mail.subscription'
@@ -38,7 +38,7 @@ class mail_subscription(osv.osv):
     _columns = {
         'res_model': fields.char('Related Document model', size=128, select=1),
         'res_id': fields.integer('Related Document ID', select=1),
-        'res_domain': fields.char('res_domain', size=256),
+        #'res_domain': fields.char('res_domain', size=256),
         'user_id': fields.integer('Related User ID', select=1),
     }
     
@@ -63,6 +63,7 @@ class mail_notification(osv.osv):
     }
     
     _defaults = {
+        'read': False,
     }
 
 mail_notification()
index 75f0408..2850cd2 100644 (file)
@@ -2,6 +2,42 @@
 <openerp>
     <data>
 
+        <!-- 
+            SUBSCRIPTION
+                !-->
+        
+        <record model="ir.ui.view" id="view_subscription_tree">
+            <field name="name">mail.subscription.tree</field>
+            <field name="model">mail.subscription</field>
+            <field name="type">tree</field>
+            <field name="sequence">10</field>
+            <field name="arch" type="xml">
+                <tree string="Subscription">
+                    <field name="user_id"/>
+                    <field name="res_model"/>
+                    <field name="res_id"/>
+                </tree>
+            </field>
+        </record>
+
+        <!-- 
+            NOTIFICATION
+                !-->
+        
+        <record model="ir.ui.view" id="view_notification_tree">
+            <field name="name">mail.notification.tree</field>
+            <field name="model">mail.notification</field>
+            <field name="type">tree</field>
+            <field name="sequence">10</field>
+            <field name="arch" type="xml">
+                <tree string="Subscription">
+                    <field name="user_id"/>
+                    <field name="message_id"/>
+                    <field name="read"/>
+                </tree>
+            </field>
+        </record>
+
         <record id="action_view_subscriptions" model="ir.actions.act_window">
             <field name="name">Subscriptions</field>
             <field name="res_model">mail.subscription</field>
index 8d5a05f..e9df98e 100644 (file)
@@ -504,7 +504,7 @@ class mail_thread(osv.osv):
     def message_get_subscribers(self, cr, uid, ids, context=None):
         subscription_obj = self.pool.get('mail.subscription')
         for id in ids:
-            sub_ids = subscription_obj.search(cr, uid, ['res_model': self._name, 'res_id': id], context=context)
+            sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', '=', id)], context=context)
             subs = subscription_obj.browse(cr, uid, sub_ids, context=context)
         return subs
 
@@ -520,7 +520,7 @@ class mail_thread(osv.osv):
         subscriber_id = uid # TODO
         sub_ids = []
         for id in ids:
-            sub_ids += subscription_obj.search(cr, uid, ['res_model': self._name, 'res_id': id, 'user_id': subscriber_id], context=context)
+            sub_ids += subscription_obj.search(cr, uid, ['&', '&', ('res_model', '=', self._name), ('res_id', '=', id), ('user_id', '=', subscriber_id)], context=context)
         subscription_obj.unlink(cr, uid, ids, context=context)
         return True