[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.
This commit is contained in:
Aaron Bohy
2016-01-14 11:22:25 +01:00
parent d93231afe2
commit b3868a613c
4 changed files with 31 additions and 5 deletions
+1
View File
@@ -446,6 +446,7 @@ class Channel(models.Model):
if self.channel_message_ids.ids:
last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message
self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]).write({'seen_message_id': last_message_id})
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), {'info': 'channel_seen', 'id': self.id})
return last_message_id
@api.multi
+25 -2
View File
@@ -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;
+4 -2
View File
@@ -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();
+1 -1
View File
@@ -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">