Skip to content

Commit

Permalink
[FIX] mail: don't notify 'join/left' messages
Browse files Browse the repository at this point in the history
Messages of type 'notification' and whose model is 'mail.channel' are
considered as 'system notifications'. This is the case of 'join/left' messages.
They aren't taken into account when computing unread messages anymore.

Also use the same heuristic to decide whether or not to display the message's
star, so from now on pure notifications (not system notifications), like status
change on a document, can be starred.
  • Loading branch information
aab-odoo committed Feb 1, 2016
1 parent ef77e68 commit 4bab99b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion addons/mail/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def _get_message_unread(self):
ON rel.mail_message_id = msg.id
RIGHT JOIN mail_channel_partner cp
ON (cp.channel_id = rel.mail_channel_id AND cp.partner_id = %s AND (cp.seen_message_id < msg.id))
WHERE msg.model = %s AND msg.res_id in %s AND msg.author_id != %s""",
WHERE msg.model = %s AND msg.res_id in %s AND msg.author_id != %s AND
(msg.message_type != 'notification' OR msg.model != 'mail.channel')""",
(partner_id, self._name, tuple(self.ids), partner_id,))
for result in self._cr.fetchall():
res[result[0]] += 1
Expand Down
5 changes: 3 additions & 2 deletions addons/mail/static/src/js/chat_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function add_message (data, options) {
channel.hidden = false;
chat_manager.bus.trigger('new_channel', channel);
}
if (channel.type !== 'static' && !msg.is_author) {
if (channel.type !== 'static' && !msg.is_author && !msg.is_system_notification) {
if (options.increment_unread) {
update_channel_unread_counter(channel, channel.unread_counter+1);
}
Expand Down Expand Up @@ -179,6 +179,7 @@ function make_message (data) {
subtype_description: data.subtype_description,
is_author: data.author_id && data.author_id[0] === session.partner_id,
is_note: data.is_note,
is_system_notification: data.message_type === 'notification' && data.model === 'mail.channel',
attachment_ids: data.attachment_ids,
subject: data.subject,
email_from: data.email_from,
Expand Down Expand Up @@ -820,7 +821,7 @@ var chat_manager = {
var msg = _.findWhere(messages, {id: channel.last_seen_message_id});
if (msg) {
var i = _.sortedIndex(messages, msg, 'id') + 1;
while (i < messages.length && messages[i].is_author) {
while (i < messages.length && (messages[i].is_author || messages[i].is_system_notification)) {
msg = messages[i];
i++;
}
Expand Down
2 changes: 1 addition & 1 deletion addons/mail/static/src/js/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var Thread = Widget.extend({
msg.hour = msg.date.format('LT');
}

msg.display_subject = message.subject && message.message_type !== 'notification' && !(message.model && (message.model !== 'mail.channel'));
msg.display_subject = message.subject && !message.is_system_notification;
return msg;
},

Expand Down
2 changes: 1 addition & 1 deletion addons/mail/static/src/xml/thread.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
(from <a t-att-data-oe-id="message.origin_id" href="#">#<t t-esc="message.origin_name"/></a>)
</t>
<span>
<i t-if="options.display_stars &amp;&amp; message.message_type != 'notification'"
<i t-if="options.display_stars &amp;&amp; !message.is_system_notification"
t-att-class="'fa fa-lg o_thread_message_star ' + (message.is_starred ? 'fa-star' : 'fa-star-o')"
t-att-data-message-id="message.id" title="Mark as Todo"/>
<i t-if="message.is_needaction &amp;&amp; options.display_needactions"
Expand Down

0 comments on commit 4bab99b

Please sign in to comment.