[FIX] mail: use the domain to determine message to mark as read
The button 'mark all as read' used to mark all messages as read, which is not usually what the user wants when there is an active filter in the search view. This commit make sure that the domain is send to the server and used correctly.
This commit is contained in:
@@ -7,6 +7,7 @@ import logging
|
||||
from openerp import _, api, fields, models, SUPERUSER_ID
|
||||
from openerp import tools
|
||||
from openerp.exceptions import UserError, AccessError
|
||||
from openerp.osv import expression
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -147,34 +148,36 @@ class Message(models.Model):
|
||||
#------------------------------------------------------
|
||||
|
||||
@api.model
|
||||
def mark_all_as_read(self, channel_ids=None):
|
||||
def mark_all_as_read(self, channel_ids=None, domain=None):
|
||||
""" Remove all needactions of the current partner. If channel_ids is
|
||||
given, restrict to messages written in one of those channels. """
|
||||
partner_id = self.env.user.partner_id.id
|
||||
# possibly horribly inefficient method:
|
||||
# it does one db request for the search, and one for each message in
|
||||
# the result set to remove the current user from the relation.
|
||||
# domain = [('needaction_partner_ids', 'in', partner_id)]
|
||||
# if channel_ids:
|
||||
# domain += [('channel_ids', 'in', channel_ids)]
|
||||
# unread_messages = self.search(domain)
|
||||
# unread_messages.write({'needaction_partner_ids': [(3, partner_id)]})
|
||||
if domain is None:
|
||||
query = "DELETE FROM mail_message_res_partner_needaction_rel WHERE res_partner_id IN %s"
|
||||
args = [(partner_id,)]
|
||||
if channel_ids:
|
||||
query += """
|
||||
AND mail_message_id in
|
||||
(SELECT mail_message_id
|
||||
FROM mail_message_mail_channel_rel
|
||||
WHERE mail_channel_id in %s)"""
|
||||
args += [tuple(channel_ids)]
|
||||
query += " RETURNING mail_message_id as id"
|
||||
self._cr.execute(query, args)
|
||||
self.invalidate_cache()
|
||||
|
||||
# a much faster way to do this is in pure sql:
|
||||
query = "DELETE FROM mail_message_res_partner_needaction_rel WHERE res_partner_id IN %s"
|
||||
args = [(partner_id,)]
|
||||
if channel_ids:
|
||||
query += """
|
||||
AND mail_message_id in
|
||||
(SELECT mail_message_id
|
||||
FROM mail_message_mail_channel_rel
|
||||
WHERE mail_channel_id in %s)"""
|
||||
args += [tuple(channel_ids)]
|
||||
query += " RETURNING mail_message_id as id"
|
||||
self._cr.execute(query, args)
|
||||
self.invalidate_cache()
|
||||
ids = [m['id'] for m in self._cr.dictfetchall()]
|
||||
else:
|
||||
# not really efficient method: it does one db request for the
|
||||
# search, and one for each message in the result set to remove the
|
||||
# current user from the relation.
|
||||
msg_domain = [('needaction_partner_ids', 'in', partner_id)]
|
||||
if channel_ids:
|
||||
msg_domain += [('channel_ids', 'in', channel_ids)]
|
||||
unread_messages = self.search(expression.AND([msg_domain, domain]))
|
||||
unread_messages.write({'needaction_partner_ids': [(3, partner_id)]})
|
||||
ids = unread_messages.mapped('id')
|
||||
|
||||
ids = [m['id'] for m in self._cr.dictfetchall()]
|
||||
notification = {'type': 'mark_as_read', 'message_ids': ids, 'channel_ids': channel_ids}
|
||||
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), notification)
|
||||
|
||||
|
||||
@@ -777,9 +777,9 @@ var chat_manager = {
|
||||
return $.when();
|
||||
}
|
||||
},
|
||||
mark_all_as_read: function (channel) {
|
||||
if ((!channel && needaction_counter) || (channel && channel.needaction_counter)) {
|
||||
return MessageModel.call('mark_all_as_read', channel ? [[channel.id]] : []);
|
||||
mark_all_as_read: function (channel, domain) {
|
||||
if ((channel.id === "channel_inbox" && needaction_counter) || (channel && channel.needaction_counter)) {
|
||||
return MessageModel.call('mark_all_as_read', [], {channel_ids: channel.id !== "channel_inbox" ? [channel.id] : [], domain: domain});
|
||||
}
|
||||
return $.when();
|
||||
},
|
||||
|
||||
@@ -200,7 +200,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
|
||||
self.$('.o_mail_chat_sidebar').slideToggle(200);
|
||||
});
|
||||
this.$buttons.on('click', '.o_mail_chat_button_mark_read', function () {
|
||||
chat_manager.mark_all_as_read();
|
||||
chat_manager.mark_all_as_read(self.channel, self.domain);
|
||||
});
|
||||
this.$buttons.on('click', '.o_mail_chat_button_unstar_all', chat_manager.unstar_all);
|
||||
this.$buttons.on('click', '.o_mail_chat_button_new_message', this.on_click_new_message);
|
||||
|
||||
Reference in New Issue
Block a user