summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/chat_manager.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-02-02 14:52:15 +0100
committerChristophe Simonis <chs@odoo.com>2016-02-02 14:52:15 +0100
commit469e04e97c2aa60d9d41bd430e0aeba77ee6f9dd (patch)
tree0119f59009274d2c569920432c9a7fabafde0974 /addons/mail/static/src/js/chat_manager.js
parent78d20b552b4374b94aec7097c0e6a48a3dd2d961 (diff)
parent2611a8198eaac60cf424742e4dc411700e439352 (diff)
[MERGE] forward port of branch saas-8 up to 2611a81
Diffstat (limited to 'addons/mail/static/src/js/chat_manager.js')
-rw-r--r--addons/mail/static/src/js/chat_manager.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index 6fd85e33719..2db02429d7a 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -25,6 +25,7 @@ var channels = [];
var channels_preview_def;
var channel_defs = {};
var chat_unread_counter = 0;
+var unread_conversation_counter = 0;
var emojis = [];
var emoji_substitutions = {};
var needaction_counter = 0;
@@ -146,7 +147,7 @@ function add_message (data, options) {
channel.hidden = false;
chat_manager.bus.trigger('new_channel', channel);
}
- if (!msg.author_id || msg.author_id[0] !== session.partner_id) {
+ if (channel.type !== 'static' && !msg.is_author && !msg.is_system_notification) {
if (options.increment_unread) {
update_channel_unread_counter(channel, channel.unread_counter+1);
}
@@ -176,7 +177,9 @@ function make_message (data) {
date: moment(time.str_to_datetime(data.date)),
message_type: data.message_type,
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,
@@ -240,11 +243,7 @@ function make_message (data) {
}
// Don't redirect on author clicked of self-posted messages
- if (msg.author_id && msg.author_id[0] === session.partner_id) {
- msg.author_redirect = false;
- } else {
- msg.author_redirect = true;
- }
+ msg.author_redirect = !msg.is_author;
// Compute the avatar_url
if (msg.author_id && msg.author_id[0]) {
@@ -449,8 +448,13 @@ function fetch_document_messages (ids, options) {
}
function update_channel_unread_counter (channel, counter) {
+ if (channel.unread_counter > 0 && counter === 0) {
+ unread_conversation_counter = Math.max(0, unread_conversation_counter-1);
+ } else if (channel.unread_counter === 0 && counter > 0) {
+ unread_conversation_counter++;
+ }
if (channel.is_chat) {
- chat_unread_counter = chat_unread_counter - channel.unread_counter + counter;
+ chat_unread_counter = Math.max(0, chat_unread_counter - channel.unread_counter + counter);
}
channel.unread_counter = counter;
chat_manager.bus.trigger("update_channel_unread_counter", channel);
@@ -807,6 +811,9 @@ var chat_manager = {
get_chat_unread_counter: function () {
return chat_unread_counter;
},
+ get_unread_conversation_counter: function () {
+ return unread_conversation_counter;
+ },
get_last_seen_message: function (channel) {
if (channel.last_seen_message_id) {
@@ -814,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].author_id && messages[i].author_id[0] === session.partner_id) {
+ while (i < messages.length && (messages[i].is_author || messages[i].is_system_notification)) {
msg = messages[i];
i++;
}