From dabbaf3fd12911c3a0c6654777643f2f20b747df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 29 Mar 2012 10:53:06 +0200 Subject: [PATCH] [IMP] mail.thread: moved code that user_ids for notifications in a separated function; adding the check of notifications pushed to parent to have child messages pushed to @login users that do not necessarily follow the discussion; some fixes in mail.js bzr revid: tde@openerp.com-20120329085306-7nx6co992vnlvyvv --- addons/mail/mail_thread.py | 37 ++++++++++++++++++++++--------- addons/mail/static/src/js/mail.js | 7 +++--- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 0be5dff11be..b3680d5d755 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -135,28 +135,43 @@ class mail_thread(osv.osv): # create message msg_id = self.pool.get('mail.message').create(cr, uid, vals, context=context) - thread_obj = self.browse(cr, uid, [thread_id], context=context)[0] # automatically subscribe the writer of the message if not subscribed if vals['user_id'] and not self.message_is_subscriber(cr, vals['user_id'], [thread_id], context=context): self.message_subscribe(cr, uid, [thread_id], [vals['user_id']], context=context) - # push the message to suscribed users - users = self.message_get_subscribers(cr, uid, [thread_id], context=context) - user_to_push_ids += [user['id'] for user in users] - # parse message to get requested users - user_to_push_ids += self.message_parse_users(cr, uid, [msg_id], vals['body_text'], context=context) - # push to need_action_user_ids - if hasattr(self, 'get_needaction_user_ids'): - user_to_push_ids += self.get_needaction_user_ids(cr, uid, [thread_id], context=context)[thread_id] - # remove duplicate entries - user_to_push_ids = list(set(user_to_push_ids)) # effectively push message to users + user_to_push_ids = self.message_create_get_notification_user_ids(cr, uid, [thread_id], msg_id, vals, context=context) for id in user_to_push_ids: notification_obj.create(cr, uid, {'user_id': id, 'message_id': msg_id}, context=context) return msg_id + def message_create_get_notification_user_ids(self, cr, uid, thread_ids, msg_id, new_msg_vals, context=None): + if context is None: + context = {} + + notif_user_ids = [] + for thread_id in thread_ids: + # add subscribers + users = self.message_get_subscribers(cr, uid, [thread_id], context=context) + notif_user_ids += [user['id'] for user in users] + # add users requested via parsing message (@login) + notif_user_ids += self.message_parse_users(cr, uid, [thread_id], new_msg_vals['body_text'], context=context) + # add users requested to perform an action (need_action mechanism) + if hasattr(self, 'get_needaction_user_ids'): + notif_user_ids += self.get_needaction_user_ids(cr, uid, [thread_id], context=context)[thread_id] + # add users notified of the parent messages (because: if parent message contains @login, login must receive the replies) + if new_msg_vals.get('parent_id', False): + notif_obj = self.pool.get('mail.notification') + parent_notif_ids = notif_obj.search(cr, uid, [('message_id', '=', new_msg_vals.get('parent_id'))], context=context) + parent_notifs = notif_obj.read(cr, uid, parent_notif_ids, context=context) + notif_user_ids += [parent_notif['user_id'][0] for parent_notif in parent_notifs] + + # remove duplicate entries + notif_user_ids = list(set(notif_user_ids)) + return notif_user_ids + def message_parse_users(self, cr, uid, ids, string, context=None): """Parse message content - if find @login -(^|\s)@(\w*)-: returns the related ids diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index a888f092fdc..4f8372c037d 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -548,8 +548,8 @@ openerp.mail = function(session) { this.display_show_more = true; /* DataSets */ this.ds_msg = new session.web.DataSet(this, 'mail.message'); - this.ds_thread = new session.web.DataSet(this, 'mail.thread'); this.ds_groups = new session.web.DataSet(this, 'mail.group'); + this.ds_thread = new session.web.DataSet(this, 'mail.thread'); this.ds_users = new session.web.DataSet(this, 'res.users'); }, @@ -603,7 +603,7 @@ openerp.mail = function(session) { self.params.search['context'] = results.context; self.params.search['domain'] = results.domain; self.params.search['groupby'] = results.group_by; - self.init_comments(self.params.search['domain'], self.params.search['context']); + self.init_comments(self.params.search['domain'], self.params.search['context'], 0, self.params.limit); }); }, @@ -750,8 +750,7 @@ openerp.mail = function(session) { */ do_comment: function () { var body_text = this.$element.find('textarea.oe_mail_wall_action_textarea').val(); - return this.ds_thread.call('message_append_note', [[], 'Tweet', body_text, false, 'comment']).then(this.init_comments()); - //return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments()); + return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments(this.params.domain, {}, 0, this.params.limit)); }, /**