[FIX] mail: automatically consider messages sent as read

Problem was that since rev. 617968c61, we consider sent messages as read client
side. This has been done to avoid to indicate that a channel has unread
messages e.g. when this channel is a follower of a chatter in which we wrote
a message.

This change has as consequence that we don't perform the 'channel_seen' RPC for
messages sent. At each refresh, the server sends information about pinned
channels, especially the unread counter, which was thus sometimes incorrect.

This rev. simply doesn't take messages we wrote into account when computing
the message_unread_counter field.

Also correctly display the 'New messages' separator in threads, by automatically
skipping messages we wrote (i.e. it is now displayed above the first message m
with m.id > last_message_seen_id and such that we aren't the author of m).
This commit is contained in:
Aaron Bohy
2016-01-25 15:46:55 +01:00
parent f35b48aa90
commit 6cc8d32d60
3 changed files with 21 additions and 7 deletions
+3 -2
View File
@@ -169,6 +169,7 @@ class MailThread(models.AbstractModel):
@api.multi
def _get_message_unread(self):
res = dict((res_id, 0) for res_id in self.ids)
partner_id = self.env.user.partner_id.id
# search for unread messages, directly in SQL to improve performances
self._cr.execute(""" SELECT msg.res_id FROM mail_message msg
@@ -176,8 +177,8 @@ class MailThread(models.AbstractModel):
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""",
(self.env.user.partner_id.id, self._name, tuple(self.ids),))
WHERE msg.model = %s AND msg.res_id in %s AND msg.author_id != %s""",
(partner_id, self._name, tuple(self.ids), partner_id,))
for result in self._cr.fetchall():
res[result[0]] += 1
+16 -1
View File
@@ -133,7 +133,7 @@ function add_message (data, options) {
if (!msg) {
msg = make_message(data);
// Keep the array ordered by date when inserting the new message
// Keep the array ordered by id when inserting the new message
messages.splice(_.sortedIndex(messages, msg, 'id'), 0, msg);
_.each(msg.channel_ids, function (channel_id) {
var channel = chat_manager.get_channel(channel_id);
@@ -807,6 +807,21 @@ var chat_manager = {
return chat_unread_counter;
},
get_last_seen_message: function (channel) {
if (channel.last_seen_message_id) {
var messages = channel.cache['[]'].messages;
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].author_id && messages[i].author_id[0] === session.partner_id) {
msg = messages[i];
i++;
}
return msg;
}
}
},
get_discuss_ids: function () {
return discuss_ids;
},
+2 -4
View File
@@ -423,13 +423,11 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
// Compute position of the 'New messages' separator, only once when joining
// a channel to keep it in the thread when new messages arrive
if (_.isUndefined(this.messages_separator_position)) {
var msg_id = this.last_seen_message_id;
if (!this.unread_counter) {
this.messages_separator_position = false; // no unread message -> don't display separator
} else if ((msg_id === false) || !_.findWhere(messages, {id: msg_id})) {
this.messages_separator_position = 'top'; // all displayed messages are unread
} else {
this.messages_separator_position = msg_id; // last read message is msg_id
var msg = chat_manager.get_last_seen_message(this.channel);
this.messages_separator_position = msg ? msg.id : 'top';
}
}
return {