diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index a62ac73101f..6925128f689 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -886,8 +886,8 @@ class mail_thread(osv.AbstractModel): return mail_message.create(cr, uid, values, context=context) - def message_post_user_api(self, cr, uid, thread_id, body='', subject=False, parent_id=False, - attachment_ids=None, extra_email=[], + def message_post_user_api(self, cr, uid, thread_id, body='', subject=False, + parent_id=False, attachment_ids=None, extra_emails=None, context=None, content_subtype='plaintext', **kwargs): """ Wrapper on message_post, used for user input : - mail gateway @@ -902,40 +902,41 @@ class mail_thread(osv.AbstractModel): to the related document. Should only be set by Chatter. - extra_email: [ 'Fabien ', 'al@openerp.com' ] """ + partner_obj = self.pool.get('res.partner') + mail_message_obj = self.pool.get('mail.message') ir_attachment = self.pool.get('ir.attachment') + extra_emails = extra_emails or [] - # 1. Pre-processing: body, partner_ids, type and subtype - if content_subtype == 'plaintext': - body = tools.plaintext2html(body) - - new_partner_ids = set([]) - for partner in extra_email: - part_ids = self.pool.get('res.partner').search(cr, uid, [('email', '=', partner)], context=context) - # create a new partner if not exists - if not part_ids: - part_ids = [self.pool.get('res.partner').name_create(cr, uid, partner, context=dict())[0]] + # 1.A.1: pre-process partners and incoming extra_emails + partner_ids = set([]) + for email in extra_emails: + partner_id = partner_obj.find_or_create(cr, uid, email, context=context) # link mail with this from mail to the new partner id - message_ids = mail_message.search(cr, uid, [('email_from', '=', partner)], context=context) - if part_ids and message_ids: - mail_message.write(cr, uid, message_ids, {'email_from': None, 'author_id': part_ids[0]}, context=context) - new_partner_ids |= set(part_ids) - - if new_partner_ids: - self.message_subscribe(cr, uid, [thread_id], list(new_partner_ids), context=context) - - partner_ids = set(kwargs.pop('partner_ids', [])) | set(new_partner_ids) + partner_msg_ids = mail_message_obj.search(cr, SUPERUSER_ID, [('email_from', '=', email), ('author_id', '=', False)], context=context) + if partner_id and partner_msg_ids: + mail_message_obj.write(cr, SUPERUSER_ID, partner_msg_ids, {'email_from': None, 'author_id': partner_id}, context=context) + partner_ids.add((4, partner_id)) + if partner_ids: + self.message_subscribe(cr, uid, [thread_id], list(partner_ids), context=context) + # 1.A.2: add recipients of parent message if parent_id: - parent_message = self.pool.get('mail.message').browse(cr, uid, parent_id, context=context) + parent_message = mail_message_obj.browse(cr, uid, parent_id, context=context) partner_ids |= set([(4, partner.id) for partner in parent_message.partner_ids]) # TDE FIXME HACK: mail.thread -> private message if self._name == 'mail.thread' and parent_message.author_id.id: partner_ids.add((4, parent_message.author_id.id)) + # 1.A.3: add specified recipients + partner_ids |= set(kwargs.pop('partner_ids', [])) + + # 1.B: handle body, message_type and message_subtype + if content_subtype == 'plaintext': + body = tools.plaintext2html(body) message_type = kwargs.pop('type', 'comment') message_subtype = kwargs.pop('subtype', 'mail.mt_comment') - # 2. Pre-processing: free attachments linked to the model + # 2. Pre-processing: attachments # HACK TDE FIXME: Chatter: attachments linked to the document (not done JS-side), load the message if attachment_ids: # TDE FIXME (?): when posting a private message, we use mail.thread as a model @@ -955,10 +956,10 @@ class mail_thread(osv.AbstractModel): attachment_ids = [] # 3. Post message - new_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject, type=message_type, - subtype=message_subtype, parent_id=parent_id, attachment_ids=[(4, id) for id in attachment_ids], - context=context, partner_ids=partner_ids, **kwargs) - + new_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject, + type=message_type, subtype=message_subtype, parent_id=parent_id, + attachment_ids=[(4, id) for id in attachment_ids], partner_ids=partner_ids, + context=context, **kwargs) return new_message_id #------------------------------------------------------ diff --git a/addons/mail/res_partner.py b/addons/mail/res_partner.py index cf9a2272a98..cfcb1106afc 100644 --- a/addons/mail/res_partner.py +++ b/addons/mail/res_partner.py @@ -42,8 +42,7 @@ class res_partner_mail(osv.Model): 'notification_email_send': lambda *args: 'comment' } - def message_post(self, cr, uid, thread_id, body='', subject=None, type='notification', - subtype=None, parent_id=False, attachments=None, context=None, **kwargs): + def message_post(self, cr, uid, thread_id, **kwargs): """ Override related to res.partner. In case of email message, set it as private: - add the target partner in the message partner_ids @@ -58,7 +57,6 @@ class res_partner_mail(osv.Model): partner_ids.append((4, thread_id)) kwargs['partner_ids'] = partner_ids thread_id = False - return super(res_partner_mail, self).message_post(cr, uid, thread_id, body=body, subject=subject, - type=type, subtype=subtype, parent_id=parent_id, attachments=attachments, context=context, **kwargs) + return super(res_partner_mail, self).message_post(cr, uid, thread_id, **kwargs) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py index 24c9c185d4d..6c7fe712652 100644 --- a/addons/mail/res_users.py +++ b/addons/mail/res_users.py @@ -116,36 +116,28 @@ class res_users(osv.Model): alias_pool.unlink(cr, uid, alias_ids, context=context) return res - - def message_post_user_api(self, cr, uid, thread_id, body='', subject=False, parent_id=False, - attachment_ids=None, extra_email=[], - context=None, content_subtype='plaintext', **kwargs): - """ Redirect the posting of message on res.users to the related partner. - This is done because when giving the context of Chatter on the - various mailboxes, we do not have access to the current partner_id. - We therefore post on the user and redirect on its partner. """ + def _message_post_get_pid(self, cr, uid, thread_id, context=None): assert thread_id, "res.users does not support posting global messages" if context and 'thread_model' in context: context['thread_model'] = 'res.partner' if isinstance(thread_id, (list, tuple)): thread_id = thread_id[0] - partner_id = self.browse(cr, uid, thread_id).partner_id.id - return self.pool.get('res.partner').message_post_user_api(cr, uid, - partner_id, body=body, subject=subject, parent_id=parent_id, - attachment_ids=attachment_ids, extra_email=extra_email, - context=context, content_subtype=content_subtype, **kwargs) + return self.browse(cr, uid, thread_id).partner_id.id + + def message_post_user_api(self, cr, uid, thread_id, body='', context=None, **kwargs): + """ Redirect the posting of message on res.users to the related partner. + This is done because when giving the context of Chatter on the + various mailboxes, we do not have access to the current partner_id. + We therefore post on the user and redirect on its partner. """ + partner_id = self._message_post_get_pid(cr, uid, thread_id, context=context) + return self.pool.get('res.partner').message_post_user_api(cr, uid, partner_id, **kwargs) def message_post(self, cr, uid, thread_id, context=None, **kwargs): """ Redirect the posting of message on res.users to the related partner. This is done because when giving the context of Chatter on the various mailboxes, we do not have access to the current partner_id. We therefore post on the user and redirect on its partner. """ - assert thread_id, "res.users does not support posting global messages" - if context and 'thread_model' in context: - context['thread_model'] = 'res.partner' - if isinstance(thread_id, (list, tuple)): - thread_id = thread_id[0] - partner_id = self.browse(cr, uid, thread_id).partner_id.id + partner_id = self._message_post_get_pid(cr, uid, thread_id, context=context) return self.pool.get('res.partner').message_post(cr, uid, partner_id, context=context, **kwargs) def message_update(self, cr, uid, ids, msg_dict, update_vals=None, context=None): diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index dbeb882d570..1efbcfcfcf1 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -256,6 +256,7 @@ .openerp .oe_mail .oe_msg_composer .oe_emails_from{ font-size: 12px; margin-left: 20px; + margin-bottom: 2px; } .openerp .oe_mail .oe_msg_composer .oe_emails_from label{ vertical-align: middle; diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 50d24b93ca4..f9ef9ef371b 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -609,17 +609,14 @@ openerp.mail = function (session) { /*do post a message and fetch the message*/ do_send_message_post: function () { var self = this; - //session.web.blockUI(); - var values = [ - this.context.default_res_id, //thread_id - this.$('textarea').val(), //body - false, //subject - this.context.default_parent_id, //parent_id - _.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids - _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email - this.parent_thread.context, // context - ]; - this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (message_id) { + this.parent_thread.ds_thread._model.call('message_post_user_api', [this.context.default_res_id], { + 'body': this.$('textarea').val(), + 'subject': false, + 'parent_id': this.context.default_parent_id, + 'attachment_ids': _.map(this.attachment_ids, function (file) {return file.id;}), + 'extra_emails': _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), + 'context': this.parent_thread.context, + }).done(function (message_id) { var thread = self.parent_thread; var root = thread == self.options.root_thread; if (self.options.display_indented_thread < self.thread_level && thread.parent_message) { @@ -632,7 +629,6 @@ openerp.mail = function (session) { thread.insert_message( message, root ? undefined : self.$el, root ); }); self.on_cancel(); - //session.web.unblockUI(); }); }, @@ -1060,7 +1056,7 @@ openerp.mail = function (session) { this.author_id = datasets.author_id || false; this.thread_level = (datasets.thread_level+1) || 0; this.partner_ids = datasets.partner_ids || []; - if (datasets.author_id) + if (datasets.author_id && datasets.author_id[0]) this.partner_ids.push(datasets.author_id); this.messages = []; diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 41de6d6b40f..5401675b0f1 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -114,26 +114,23 @@ and - - - - - - - + - + - - , others... + + , others... <<< -
+
- +