[FIX] mail: systray: move Inbox counter to its own item

Clicking on that item redirects to the Inbox in Discuss.

The messaging menu's counter is now the number of conversations (public or
private channels, dm and livechat) in which there is at least one unread
message. Moreover, it is emphasized when one of those conversations is a chat.

Also make mass-mailing channels available through the messaging menu (for
consistency as its counter takes those channels into account) and allow to open
them in chat windows without input.
This commit is contained in:
Aaron Bohy
2016-02-01 11:31:09 +01:00
parent 68c928aca7
commit ef77e6821a
9 changed files with 83 additions and 53 deletions
+7
View File
@@ -823,6 +823,13 @@ msgstr ""
msgid "Conversation is minimied"
msgstr ""
#. module: mail
#. openerp-web
#: code:addons/mail/static/src/xml/systray.xml:14
#, python-format
msgid "Conversations"
msgstr ""
#. module: mail
#. openerp-web
#: code:addons/mail/static/src/js/client_action.js:250
+14 -8
View File
@@ -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) {
if (options.increment_unread) {
update_channel_unread_counter(channel, channel.unread_counter+1);
}
@@ -176,6 +177,7 @@ 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,
attachment_ids: data.attachment_ids,
subject: data.subject,
@@ -240,11 +242,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 +447,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 +810,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 +820,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) {
msg = messages[i];
i++;
}
+1
View File
@@ -28,6 +28,7 @@ return Widget.extend({
this.options = _.defaults(options || {}, {
display_stars: true,
placeholder: _t("Say something"),
input_less: false,
});
this.unread_msgs = unread_msgs || 0;
this.is_hidden = false;
+1 -1
View File
@@ -360,7 +360,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
// Hide 'detach' button in static channels
self.$buttons
.find('.o_mail_chat_button_detach')
.toggle(channel.type !== "static" && !channel.mass_mailing);
.toggle(channel.type !== "static");
// Hide 'invite', 'unsubscribe' and 'settings' buttons in static channels and DM
self.$buttons
.find('.o_mail_chat_button_invite, .o_mail_chat_button_unsubscribe, .o_mail_chat_button_settings')
+41 -20
View File
@@ -9,6 +9,42 @@ var chat_manager = require('mail.chat_manager');
var QWeb = core.qweb;
/**
* Menu item appended in the systray part of the navbar, redirects to the Inbox in Discuss
* Also displays the needaction counter (= Inbox counter)
*/
var InboxItem = Widget.extend({
template:'mail.chat.InboxItem',
events: {
"click": "on_click",
},
start: function () {
this.$needaction_counter = this.$('.o_notification_counter');
chat_manager.bus.on("update_needaction", this, this.update_counter);
this.update_counter();
return this._super();
},
update_counter: function () {
var counter = chat_manager.get_needaction_counter();
this.$needaction_counter.text(counter);
this.$el.toggleClass('o_no_notification', !counter);
},
on_click: function (event) {
event.preventDefault();
this.discuss_redirect();
},
discuss_redirect: _.debounce(function () {
var self = this;
var discuss_ids = chat_manager.get_discuss_ids();
this.do_action(discuss_ids.action_id, {clear_breadcrumbs: true}).then(function () {
self.trigger_up('hide_app_switcher');
core.bus.trigger('change_menu_section', discuss_ids.menu_id);
});
}, 1000, true),
});
SystrayMenu.Items.push(InboxItem);
/**
* Menu item appended in the systray part of the navbar
*
@@ -24,13 +60,11 @@ var MessagingMenu = Widget.extend({
"click .o_filter_button": "on_click_filter_button",
"click .o_new_message": "on_click_new_message",
"click .o_mail_channel_preview": "on_click_channel",
"click .o_redirect_to_discuss": "on_click_redirect_to_discuss",
},
start: function () {
this.$filter_buttons = this.$('.o_filter_button');
this.$channels_preview = this.$('.o_mail_navbar_dropdown_channels');
this.filter = false;
chat_manager.bus.on("update_needaction", this, this.update_counter);
chat_manager.bus.on("update_channel_unread_counter", this, this.update_counter);
this.update_counter();
return this._super();
@@ -39,9 +73,10 @@ var MessagingMenu = Widget.extend({
return this.$el.hasClass('open');
},
update_counter: function () {
var counter = chat_manager.get_needaction_counter() + chat_manager.get_chat_unread_counter();
var counter = chat_manager.get_unread_conversation_counter();
this.$('.o_notification_counter').text(counter);
this.$el.toggleClass('o_no_notification', !counter);
this.$el.toggleClass('o_unread_chat', !!chat_manager.get_chat_unread_counter());
if (this.is_open()) {
this.render_channels_preview();
}
@@ -52,15 +87,13 @@ var MessagingMenu = Widget.extend({
if (self.filter === 'chat') {
return channel.is_chat;
} else if (self.filter === 'channels') {
return !channel.is_chat && channel.type !== 'static' && !channel.mass_mailing;
return !channel.is_chat && channel.type !== 'static';
} else {
return channel.type !== 'static' && !channel.mass_mailing;
return channel.type !== 'static';
}
});
// Update inbox counter and display spinner while waiting for channels preview
var inbox_counter = chat_manager.get_needaction_counter();
this.$('.o_inbox_counter').html(inbox_counter ? '(' + inbox_counter + ')' : '');
// Display spinner while waiting for channels preview
this.$channels_preview.html(QWeb.render('mail.chat.Spinner'));
chat_manager.get_channels_preview(channels).then(function (channels_preview) {
@@ -111,18 +144,6 @@ var MessagingMenu = Widget.extend({
chat_manager.bus.trigger('detach_channel', channel);
}
},
on_click_redirect_to_discuss: function (event) {
event.preventDefault();
this.discuss_redirect();
},
discuss_redirect: _.debounce(function () {
var self = this;
var discuss_ids = chat_manager.get_discuss_ids();
this.do_action(discuss_ids.action_id, {clear_breadcrumbs: true}).then(function () {
self.trigger_up('hide_app_switcher');
core.bus.trigger('change_menu_section', discuss_ids.menu_id);
});
}, 1000, true),
});
SystrayMenu.Items.push(MessagingMenu);
+2 -1
View File
@@ -39,11 +39,12 @@ function open_chat (session) {
var chat_session = _.findWhere(chat_sessions, {id: session.id});
if (!chat_session) {
var prefix = !session.is_chat ? "#" : "";
var options = { input_less: session.mass_mailing };
chat_session = {
id: session.id,
uuid: session.uuid,
name: session.name,
window: new ExtendedChatWindow(web_client, session.id, prefix + session.name, session.is_folded, session.unread_counter),
window: new ExtendedChatWindow(web_client, session.id, prefix + session.name, session.is_folded, session.unread_counter, options),
};
chat_session.window.on("close_chat_session", null, function () {
close_chat(chat_session);
+7 -16
View File
@@ -283,6 +283,9 @@
display: none;
}
}
&.o_unread_chat > a > i {
color: @odoo-brand-optional;
}
&.open .o_mail_navbar_dropdown {
.o-flex-display();
@@ -308,19 +311,16 @@
height: 50px;
}
.o_filter_button,
.o_new_message,
.o_redirect_to_discuss {
.btn-link;
padding: 5px;
}
.o_mail_navbar_dropdown_top {
.o-flex-display();
.o-flex(0, 0, auto);
justify-content: space-between;
border-bottom: 1px solid lightgray;
.o_filter_button, .o_new_message {
.btn-link;
padding: 5px;
}
.o_filter_button {
color: @odoo-main-color-muted;
&:hover, &.o_selected {
@@ -332,15 +332,6 @@
}
}
}
.o_mail_navbar_dropdown_bottom {
.o-flex(0, 0, auto);
border-top: 1px solid lightgray;
height: 35px;
.o_redirect_to_discuss {
height: 100%;
width: 100%;
}
}
.o_mail_navbar_dropdown_channels {
.o-flex(0, 1, auto);
+1 -1
View File
@@ -11,7 +11,7 @@
</div>
<div class="o_chat_content">
</div>
<div class="o_chat_input">
<div t-if='!widget.options.input_less' class="o_chat_input">
<input t-att-placeholder="widget.options.placeholder"/>
</div>
</div>
+9 -6
View File
@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="mail.chat.InboxItem">
<li class="o_mail_navbar_item">
<a href="#" title="Inbox">
<i class="fa fa-at"/> <span class="o_notification_counter"/>
</a>
</li>
</t>
<t t-name="mail.chat.MessagingMenu">
<li class="o_mail_navbar_item">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Messages" href="#">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Conversations" href="#">
<i class="fa fa-comments"/> <span class="o_notification_counter"/>
</a>
<ul class="o_mail_navbar_dropdown dropdown-menu" role="menu">
@@ -16,11 +24,6 @@
<button type="button" class="btn btn-sm o_new_message"> New message </button>
</li>
<li class="o_mail_navbar_dropdown_channels"/>
<li class="o_mail_navbar_dropdown_bottom">
<button type="button" class="btn o_redirect_to_discuss">
@Inbox <span class="o_inbox_counter"/>
</button>
</li>
</ul>
</li>
</t>