diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 48ac8cb8c7b..6afeceb6816 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -222,7 +222,7 @@ class mail_message(osv.osv): } _defaults = { - 'type': 'comment', + 'type': 'email', 'state': 'received', } diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index e01da45c13d..a821f962ea2 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -126,6 +126,7 @@ + @@ -208,7 +209,9 @@ mail.message form tree,form + {'search_default_received': 1, 'search_default_exception': 1} diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 6d26e945c1d..b79463bbfc4 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -126,26 +126,57 @@ class mail_thread(osv.osv): """ if context is None: context = {} + if context.get('install_mode', False): + print 'zpfinzpefinzofinzoiznef' + return True + else: + print 'ooooooooooh' + str(context) + str(vals) + user_to_push_ids = [] + + res_users_obj = self.pool.get('res.users') message_obj = self.pool.get('mail.message') subscription_obj = self.pool.get('mail.subscription') notification_obj = self.pool.get('mail.notification') - # create message - msg_id = message_obj.create(cr, uid, vals, context=context) - # automatically subscribe the writer of the message if vals['user_id']: self.message_subscribe(cr, uid, [thread_id], [vals['user_id']], context=context) - # push message to users - user_to_push_ids = self.message_create_get_notification_user_ids(cr, uid, [thread_id], msg_id, vals, context=context) + # get users that will get a notification pushed + user_to_push_ids = self.message_create_get_notification_user_ids(cr, uid, [thread_id], vals, context=context) + + # set email_from and email_to for comments and notifications + if vals['type'] == 'comment' or vals['type'] == 'notification': + current_user = res_users_obj.browse(cr, uid, [uid], context=context)[0] + if not vals.get('email_from', False): + vals['email_from'] = current_user.user_email + if not vals.get('email_to', False): + email_to = '' + for user in res_users_obj.browse(cr, uid, user_to_push_ids, context=context): + if user.message_email_pref == 'all' or user.message_email_pref == 'comments' and vals['type'] == 'comment': + if (user.user_email): + if email_to: + email_to = '%s, ' % (email_to) + email_to = '%s%s' % (email_to, user.user_email) + if email_to: + vals['email_to'] = email_to + print vals['email_from'] + print vals['email_to'] + if email_to: + vals['email_to'] = email_to + vals['state'] = 'outgoing' + + # create message + msg_id = message_obj.create(cr, uid, vals, context=context) + + # push to users 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): + def message_create_get_notification_user_ids(self, cr, uid, thread_ids, new_msg_vals, context=None): if context is None: context = {} diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py index f5de133c607..d371f232963 100644 --- a/addons/mail/res_users.py +++ b/addons/mail/res_users.py @@ -32,11 +32,12 @@ class res_users(osv.osv): _columns = { 'message_email_pref': fields.selection([ - ('all', 'Everytime'), - ('comments', 'Only for comments'), - ('me', 'Only when sent directly to me'), + ('all', 'All feeds'), + ('comments', 'Only comments'), + ('to_me', 'Only when sent directly to me'), ('none', 'Never'), - ], 'New feeds email', help="Choose whether you want to receive an email when you receive new feeds."), + ], string='Receive feeds by email', required=True, + help="Choose whether you want to receive an email when you receive new feeds."), } _default = {