diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 3f2f678fe9e..bbf68509277 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -193,7 +193,7 @@ class mail_message(osv.Model): attachment_ids = [] try: author_id = self.pool.get('res.partner').name_get(cr, uid, [msg.author_id.id], context=context)[0] - is_author = uid in msg.author_id.user_ids + is_author = uid == msg.author_id.user_ids[0].id except (orm.except_orm, osv.except_osv): author_id = False is_author = False @@ -215,8 +215,6 @@ class mail_message(osv.Model): 'author_id': author_id, 'is_author': is_author, 'partner_ids': partner_ids, - 'child_ids': [], - 'child_nbr': child_nbr, 'parent_id': msg.parent_id and msg.parent_id.id or False, 'vote_user_ids': vote_ids, 'has_voted': has_voted, @@ -311,18 +309,20 @@ class mail_message(osv.Model): limit = limit or self._message_read_limit context = context or {} - if not ids: - ids = self.search(cr, SUPERUSER_ID, domain, context=context, limit=limit) - # if the user can read a message, he can read all the thread - messages = self.browse(cr, uid, ids, context=context) - - - # key: ID, value: record tree = [] result = [] record = None - for msg in messages: + + # select ids + if ids: + for msg in self.browse(cr, uid, ids, context=context): + result.append(self._message_dict_get(cr, uid, msg, context=context)) + return result + + # key: ID, value: record + ids = self.search(cr, SUPERUSER_ID, domain, context=context, limit=limit) + for msg in self.browse(cr, uid, ids, context=context): # if not in record and not in message_loded list if msg.id not in tree and msg.id not in message_loaded : record = self._message_dict_get(cr, uid, msg, context=context) @@ -341,10 +341,12 @@ class mail_message(osv.Model): result = sorted(result, key=lambda k: k['id']) + + tree_not = [] # expandable for not show message for id_msg in tree: # get all childs - not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=limit) + not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=1000) # group childs not read id_min=None id_max=None @@ -356,6 +358,7 @@ class mail_message(osv.Model): id_min=not_loaded_id if id_max==None or id_max0: result.append({ @@ -375,8 +378,9 @@ class mail_message(osv.Model): 'id': id_min }) + # expandable for limit max - ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded]], context=context, limit=1) + ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded+tree+tree_not]], context=context, limit=1) if len(ids) > 0: result.append( { diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2d7c55b4d06..e0c9ac9b7fc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -277,7 +277,6 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - this.$('*').unbind(); // event: click on 'Vote' button this.$el.on('click', 'a.oe_mail_fetch_more', self.on_expandable); }, @@ -421,7 +420,6 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - this.$('*').unbind(); // event: click on 'Attachment(s)' in msg this.$el.on('click', 'a.oe_mail_msg_view_attachments', function (event) { var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments'); @@ -450,7 +448,7 @@ openerp.mail = function(session) { on_message_reply_by_mail:function(event){ event.stopPropagation(); - this.thread.on_compose_message($(event.srcElement).hasClass("oe_full_reply"), true); + this.thread.on_compose_message(true, true); return false; }, @@ -496,7 +494,7 @@ openerp.mail = function(session) { animated_destroy: function(options) { var self=this; //graphic effects - if(options.fadeTime) { + if(options && options.fadeTime) { self.$el.fadeOut(options.fadeTime, function(){ self.destroy(); }); @@ -688,16 +686,16 @@ openerp.mail = function(session) { this.display_user_avatar(); var display_done = compose_done = false; - - if(this.options.thread._parents[0]==this){ - this.on_first_thread(); - } // add message composition form view compose_done = this.instantiate_composition_form(); this.bind_events(); + if(this.options.thread._parents[0]==this){ + this.on_first_thread(); + } + return display_done && compose_done; }, @@ -707,7 +705,7 @@ openerp.mail = function(session) { * in the composition form. */ do_action: function(action, on_close) { this.instantiate_composition_form(); - this.message_fletch(); + this.message_fletch(false, false, false, [action.id]); return this._super(action, on_close); }, @@ -832,7 +830,7 @@ openerp.mail = function(session) { if (!this.compose_message_widget) return true; this.compose_message_widget.refresh({ 'default_composition_mode': 'reply', - 'default_parent_id': message.id, + 'default_parent_id': this.id, 'default_content_subtype': 'html'} ); } this.$('div.oe_mail_thread_action:first').toggle(); @@ -854,8 +852,7 @@ openerp.mail = function(session) { comment_node.val(''); } if(body.match(/\S+/)) { - //this.$("textarea:first").blur(); - return this.ds_thread.call('message_post_api', [ + this.ds_thread.call('message_post_api', [ [this.context.default_res_id], body, false, 'comment', false, this.context.default_parent_id, undefined]) .then(this.proxy('switch_new_message')); } @@ -871,7 +868,7 @@ openerp.mail = function(session) { * @param {Array} replace_domain: added to this.domain * @param {Object} replace_context: added to this.context */ - message_fletch: function (initial_mode, replace_domain, replace_context) { + message_fletch: function (initial_mode, replace_domain, replace_context, ids) { var self = this; // initial mode: try to use message_data or message_ids @@ -883,7 +880,7 @@ openerp.mail = function(session) { fetch_context = replace_context ? replace_context : this.context; fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() ); - return this.ds_message.call('message_read', [false, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined] + return this.ds_message.call('message_read', [ids, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined] ).then(this.proxy('switch_new_message')); }, @@ -933,16 +930,18 @@ openerp.mail = function(session) { }); } + var thread = self.options.thread.display_on_flat ? self.options.thread._parents[0] : this; + // check older and newer message for insert var parent_newer = false; var parent_older = false; - for(var i in this.messages){ - if(this.messages[i].id > message.id){ - if(!parent_newer || parent_newer.id>this.messages[i].id) - parent_newer = this.messages[i]; - } else if(this.messages[i].id>0 && this.messages[i].id < message.id) { - if(!parent_older || parent_older.id message.id){ + if(!parent_newer || parent_newer.id>thread.messages[i].id) + parent_newer = thread.messages[i]; + } else if(thread.messages[i].id>0 && thread.messages[i].id < message.id) { + if(!parent_older || parent_older.id
  • - -
  • W
  • -
  • h
  • -
  • )
  • -
  • )
  • -
    +
  • W
  • +
  • h
  • +
  • )
  • +
  • )
  • @@ -176,7 +174,7 @@
  • diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 7147f73a515..3baf3ff9023 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -255,13 +255,13 @@ class mail_compose_message(osv.TransientModel): post_values['attachments'] += new_attachments post_values.update(email_dict) # post the message - active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values) + id=active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values) # post process: update attachments, because id is not necessarily known when adding attachments in Chatter # self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], { # 'res_id': wizard.id, 'res_model': wizard.model or False}, context=context) - return {'type': 'ir.actions.act_window_close', 'res_model':'mail.compose.message'} + return {'type': 'ir.actions.act_window_close', 'res_model':'mail.compose.message', 'id': id} def render_message(self, cr, uid, wizard, res_id, context=None): """ Generate an email from the template for given (wizard.model, res_id)