diff options
| author | Aaron Bohy <aab@odoo.com> | 2016-01-07 13:07:41 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2016-01-14 11:22:25 +0100 |
| commit | b3868a613c77e2169be1947ce61cbdfcd62a7bf9 (patch) | |
| tree | 1a616cc4a4d90cafa11a3df7219ed84d9d5c3ab0 /addons/mail/static/src | |
| parent | d93231afe201997305759767e24e6df0972175fe (diff) | |
[IMP] mail: needaction/unread messages counters
Some UI changes:
- Unread messages in chat are now displayed as needactions in the Discuss's
sidebar (badge with counter of unread messages, instead of simply bolding the
channel name).
- The counter displayed in the navbar is now the sum of needactions and total
of unread messages in chat.
- The counter displayed next to Inbox is still the needaction counter.
For consistency between tabs/browsers/devices, the channel_seen info is now
broadcasted, meaning that every tab/browser/device will be noticed.
Also now correctly increment the unread counter of a channel if the received
message is a needaction.
Diffstat (limited to 'addons/mail/static/src')
| -rw-r--r-- | addons/mail/static/src/js/chat_manager.js | 27 | ||||
| -rw-r--r-- | addons/mail/static/src/js/systray.js | 6 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/client_action.xml | 2 |
3 files changed, 30 insertions, 5 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 150e803920c..c5b510ce8ad 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -23,6 +23,7 @@ var messages = []; var channels = []; var channels_preview_def; var channel_defs = {}; +var chat_unread_counter = 0; var emojis = []; var emoji_substitutions = {}; var needaction_counter = 0; @@ -303,7 +304,7 @@ function make_channel (data, options) { display_needactions: options.display_needactions, mass_mailing: data.mass_mailing, needaction_counter: data.message_needaction_counter || 0, - unread_counter: data.message_unread_counter || 0, + unread_counter: 0, last_seen_message_id: data.seen_message_id, cache: {'[]': { all_history_loaded: false, @@ -325,6 +326,9 @@ function make_channel (data, options) { bus.update_option('bus_presence_partner_ids', pinned_dm_partners); } channel.is_chat = !channel.type.match(/^(public|private|static)$/); + if (data.message_unread_counter) { + update_channel_unread_counter(channel, data.message_unread_counter); + } return channel; } @@ -440,6 +444,9 @@ function fetch_document_messages (ids, options) { } function update_channel_unread_counter (channel, counter) { + if (channel.is_chat) { + chat_unread_counter = chat_unread_counter - channel.unread_counter + counter; + } channel.unread_counter = counter; chat_manager.bus.trigger("update_channel_unread_counter", channel); } @@ -470,7 +477,11 @@ function on_notification (notification) { } function on_needaction_notification (message) { - message = add_message(message, { channel_id: 'channel_inbox', show_notification: true} ); + message = add_message(message, { + channel_id: 'channel_inbox', + show_notification: true, + increment_unread: true, + }); invalidate_caches(message.channel_ids); needaction_counter++; _.each(message.channel_ids, function (channel_id) { @@ -505,6 +516,8 @@ function on_partner_notification (data) { on_mark_as_read_notification(data); } else if (data.type === 'mark_as_unread') { on_mark_as_unread_notification(data); + } else if (data.info === 'channel_seen') { + on_channel_seen_notification(data); } else { on_chat_session_notification(data); } @@ -575,6 +588,13 @@ function on_mark_as_unread_notification (data) { chat_manager.bus.trigger('update_needaction', needaction_counter); } +function on_channel_seen_notification (data) { + var channel = chat_manager.get_channel(data.id); + if (channel && channel.unread_counter) { + update_channel_unread_counter(channel, 0); + } +} + function on_chat_session_notification (chat_session) { var channel; if ((chat_session.channel_type === "channel") && (chat_session.state === "open")) { @@ -760,6 +780,9 @@ var chat_manager = { get_needaction_counter: function () { return needaction_counter; }, + get_chat_unread_counter: function () { + return chat_unread_counter; + }, get_discuss_ids: function () { return discuss_ids; diff --git a/addons/mail/static/src/js/systray.js b/addons/mail/static/src/js/systray.js index 74209a967ec..342167bfed2 100644 --- a/addons/mail/static/src/js/systray.js +++ b/addons/mail/static/src/js/systray.js @@ -30,13 +30,15 @@ var MessagingMenu = Widget.extend({ this.$channels_preview = this.$('.o_mail_navbar_dropdown_channels'); this.filter = false; chat_manager.bus.on("update_needaction", this, this.update_counter); - this.update_counter(chat_manager.get_needaction_counter()); + chat_manager.bus.on("update_channel_unread_counter", this, this.update_counter); + this.update_counter(); return this._super(); }, is_open: function () { return this.$el.hasClass('open'); }, - update_counter: function (counter) { + update_counter: function () { + var counter = chat_manager.get_needaction_counter() + chat_manager.get_chat_unread_counter(); this.$('.o_notification_counter').text(counter); if (this.is_open()) { this.render_channels_preview(); diff --git a/addons/mail/static/src/xml/client_action.xml b/addons/mail/static/src/xml/client_action.xml index 55be6233d22..04d45eb9bdc 100644 --- a/addons/mail/static/src/xml/client_action.xml +++ b/addons/mail/static/src/xml/client_action.xml @@ -81,7 +81,7 @@ </t> <t t-name="mail.chat.SidebarItems"> <t t-foreach="channels" t-as="channel"> - <t t-set="counter" t-value="channel.needaction_counter"/> + <t t-set="counter" t-value="channel.is_chat ? channel.unread_counter : channel.needaction_counter"/> <div t-if="channel.type === channel_type" t-att-data-channel-id="channel.id" t-attf-class="o_mail_chat_channel_item #{channel.unread_counter ? ' o_unread_message' : ''} #{(active_channel_id == channel.id) ? 'o_active': ''}"> <span t-if="display_status"> |
