summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2016-01-20 09:56:28 +0100
committerAaron Bohy <aab@odoo.com>2016-01-25 15:46:55 +0100
commit6cc8d32d605bfce9adf2cced683db6b73c71b166 (patch)
treec77362eaa3fe0753c8450b2d4578d4f3f63048a3 /addons/mail/static/src
parentf35b48aa90555a36b86e51fc304e3028bdd1ff34 (diff)
[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).
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/chat_manager.js17
-rw-r--r--addons/mail/static/src/js/client_action.js6
2 files changed, 18 insertions, 5 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index ec66cdde362..34559eeaad8 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -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;
},
diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js
index 38cc26e8997..e091590faa1 100644
--- a/addons/mail/static/src/js/client_action.js
+++ b/addons/mail/static/src/js/client_action.js
@@ -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 {