summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/chat_manager.js78
-rw-r--r--addons/mail/static/src/js/client_action.js15
-rw-r--r--addons/mail/static/src/less/client_action.less66
-rw-r--r--addons/mail/static/src/less/composer.less1
-rw-r--r--addons/mail/static/src/xml/client_action.xml32
-rw-r--r--addons/mail/static/src/xml/composer.xml23
6 files changed, 146 insertions, 69 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index aa72ff3da1b..7796226da10 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -11,7 +11,7 @@ var web_client = require('web.web_client');
var _t = core._t;
var LIMIT = 100;
-var preview_msg_max_size = 50;
+var preview_msg_max_size = 350; // optimal for native english speakers
var MessageModel = new Model('mail.message', session.context);
var ChannelModel = new Model('mail.channel', session.context);
@@ -28,6 +28,7 @@ var needaction_counter = 0;
var mention_partner_suggestions = [];
var discuss_ids = {};
var global_unread_counter = 0;
+var pinned_dm_partners = []; // partner_ids we have a pinned DM with
// Window focus/unfocus, beep and title
//----------------------------------------------------------------------------------
@@ -43,25 +44,36 @@ var beep = (function () {
bus.on("window_focus", null, function() {
global_unread_counter = 0;
- notify();
+ web_client.set_title_part("_chat");
});
-function increment_global_unread_counter () {
- if (!bus.is_odoo_focused()) {
- global_unread_counter++;
- notify(bus.is_master);
+function notify_incoming_message (msg, options) {
+ var title = _t('New message');
+ if (msg.author_id[1]) {
+ title += _t(' from ') + _.escape(msg.author_id[1]);
}
-}
+ var content = $(msg.body).text().substr(0, preview_msg_max_size);
-function notify (play_sound) {
- var title;
- if (global_unread_counter > 0) {
- title = _.str.sprintf(_t("%d Messages"), global_unread_counter);
- if (play_sound) {
- beep();
+ if (bus.is_odoo_focused()) {
+ if (!options.is_displayed) {
+ web_client.do_notify(title, content);
+ }
+ } else {
+ global_unread_counter++;
+ var tab_title = _.str.sprintf(_t("%d Messages"), global_unread_counter);
+ web_client.set_title_part("_chat", tab_title);
+
+ if (Notification && Notification.permission === "granted") {
+ if (bus.is_master) {
+ new Notification(title, {body: content, icon: "/web/static/src/img/odoo.png", silent: false});
+ }
+ } else {
+ web_client.do_notify(title, content);
+ if (bus.is_master) {
+ beep();
+ }
}
}
- web_client.set_title_part("_chat", title);
}
// Message and channel manipulation helpers
@@ -92,22 +104,10 @@ function add_message (data, options) {
channel.hidden = false;
chat_manager.bus.trigger('new_channel', channel);
}
- if (is_chat && options.show_notification) {
- var query = { is_displayed: false };
+ if (is_chat && options.show_notification && (!msg.author_id || msg.author_id[0] !== session.partner_id)) {
+ var query = {is_displayed: false};
chat_manager.bus.trigger('anyone_listening', channel, query);
- if (!query.is_displayed) {
- var title = _t('New message');
- if (msg.author_id[1]) {
- title += _t(' from ') + _.escape(msg.author_id[1]);
- }
- var trunc_text = function (t, limit) {
- return (t.length > limit) ? t.substr(0, limit-1)+'…' : t;
- };
- web_client.do_notify(title, trunc_text(msg.body, preview_msg_max_size));
- }
- }
- if (is_chat && options.increment_unread && (!msg.author_id || msg.author_id[0] !== session.partner_id)) {
- increment_global_unread_counter();
+ notify_incoming_message(msg, query);
}
});
if (!options.silent) {
@@ -274,10 +274,25 @@ function make_channel (data, options) {
channel.name = data.direct_partner[0].name;
channel.direct_partner_id = data.direct_partner[0].id;
channel.status = data.direct_partner[0].im_status;
+ pinned_dm_partners.push(channel.direct_partner_id);
+ bus.update_option('bus_presence_partner_ids', pinned_dm_partners);
}
return channel;
}
+function remove_channel (channel) {
+ if (!channel) { return; }
+ if (channel.type === 'dm') {
+ var index = pinned_dm_partners.indexOf(channel.direct_partner_id);
+ if (index > -1) {
+ pinned_dm_partners.splice(index, 1);
+ bus.update_option('bus_presence_partner_ids', pinned_dm_partners);
+ }
+ }
+ channels = _.without(channels, channel);
+ delete channel_defs[channel.id];
+}
+
function get_channel_cache (channel, domain) {
var stringified_domain = JSON.stringify(domain || []);
if (!channel.cache[stringified_domain]) {
@@ -434,7 +449,7 @@ function on_channel_notification (message) {
function on_partner_notification (data) {
if (data.info === "unsubscribe") {
- channels = _.without(channels, chat_manager.get_channel(data.id));
+ remove_channel(chat_manager.get_channel(data.id));
chat_manager.bus.trigger("unsubscribe_from_channel", data.id);
} else if (data.type === 'toggle_star') {
on_toggle_star_notification(data);
@@ -744,8 +759,7 @@ var chat_manager = {
def = ChannelModel.call('channel_pin', [channel.uuid, false]);
}
return def.then(function () {
- channels = _.without(channels, channel);
- delete channel_defs[channel.id];
+ remove_channel(channel);
});
},
close_chat_session: function (channel_id) {
diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js
index 1e868c08942..ce505e569c1 100644
--- a/addons/mail/static/src/js/client_action.js
+++ b/addons/mail/static/src/js/client_action.js
@@ -52,8 +52,8 @@ var PartnerInviteDialog = Dialog.extend({
allowClear: true,
multiple: true,
formatResult: function(item) {
- var css_class = (item.im_status === 'away' ? "fa-clock-o" : "fa-circle" + (item.im_status === 'online' ? "" : "-o"));
- return $('<span class="fa">').addClass(css_class).text(item.text);
+ var status = QWeb.render('mail.chat.UserStatus', {status: item.im_status});
+ return $('<span>').text(item.text).prepend(status);
},
query: function (query) {
self.PartnersModel.call('im_search', [query.term, 20]).then(function(result){
@@ -116,6 +116,14 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
chat_manager.undo_mark_as_read(msgs_ids, channel);
});
},
+ "click .o_mail_annoying_notification_bar .fa-close": function (event) {
+ this.$(".o_mail_annoying_notification_bar").slideUp();
+ },
+ "click .o_mail_request_permission": function (event) {
+ event.preventDefault();
+ this.$(".o_mail_annoying_notification_bar").slideUp();
+ window.Notification.requestPermission();
+ },
},
on_attach_callback: function () {
@@ -135,6 +143,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
this.options = options || {};
this.channels_scrolltop = {};
this.throttled_render_sidebar = _.throttle(this.render_sidebar.bind(this), 100, { leading: false });
+ this.notification_bar = (window.Notification.permission === "default");
},
willStart: function () {
@@ -558,7 +567,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
},
on_composer_input_focused: function () {
var suggestions = chat_manager.get_mention_partner_suggestions(this.channel);
- var composer = channel.mass_mailing ? self.extended_composer : self.basic_composer;
+ var composer = this.channel.mass_mailing ? this.extended_composer : this.basic_composer;
composer.mention_set_prefetched_partners(suggestions);
},
diff --git a/addons/mail/static/src/less/client_action.less b/addons/mail/static/src/less/client_action.less
index 408f3074311..8ab1c9f221c 100644
--- a/addons/mail/static/src/less/client_action.less
+++ b/addons/mail/static/src/less/client_action.less
@@ -10,6 +10,35 @@
height: auto;
}
+ .o_mail_annoying_notification_bar {
+ height: 40px;
+ background-color: #DFA941;
+ color: white;
+ text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.25);
+ .o-flex-display();
+ border-bottom: 1px solid @odoo-main-color-muted;
+
+ .o_mail_request_permission {
+ .o-flex-display();
+ justify-content: center;
+ .o-flex(1,1, auto);
+ }
+ > span {
+ font-size: 16px;
+ line-height: 40px;
+ > a {
+ color: white;
+ margin-left: 5px;
+ text-decoration: underline;
+ }
+
+ &.fa-close {
+ margin-right: 10px;
+ cursor: pointer;
+ }
+ }
+ }
+
.o_mail_chat_sidebar {
width: @mail-chat-sidebar-width;
height: 100%;
@@ -103,12 +132,15 @@
margin-right: 5px;
border: none;
}
+ &.o_extended_composer .o_composer_input {
+ margin-right: 0;
+ }
+ }
- .o_composer_buttons {
- .o-flex(0, 0, auto);
- .o_composer_button_send {
- float: right;
- }
+ .o_composer_buttons {
+ .o-flex(0, 0, auto);
+ .o_composer_button_send {
+ float: right;
}
}
}
@@ -167,16 +199,6 @@
font-weight: bold;
}
- .o_user_status {
- font-size: 10px;
- position: relative;
- bottom: 1px;
- margin-right: 3px;
- &.fa-circle {
- color: @odoo-brand-optional;
- }
- }
-
> .badge {
color: white;
background-color: @odoo-brand-optional;
@@ -223,3 +245,17 @@
}
}
}
+
+// User status bullet (in Discuss sidebar and Invite dialog)
+.o_mail_user_status {
+ font-size: 10px;
+ position: relative;
+ bottom: 1px;
+ margin-right: 3px;
+ &.o_user_online {
+ color: @odoo-brand-optional;
+ }
+ &.o_user_idle {
+ color: orange;
+ }
+}
diff --git a/addons/mail/static/src/less/composer.less b/addons/mail/static/src/less/composer.less
index 3a0881d5da9..6dad1dac3d2 100644
--- a/addons/mail/static/src/less/composer.less
+++ b/addons/mail/static/src/less/composer.less
@@ -4,6 +4,7 @@
> input {
.o-flex(1, 1, auto);
+ padding: 5px;
margin-right: 30px;
}
}
diff --git a/addons/mail/static/src/xml/client_action.xml b/addons/mail/static/src/xml/client_action.xml
index bb29d8cca27..18fef4a4ed6 100644
--- a/addons/mail/static/src/xml/client_action.xml
+++ b/addons/mail/static/src/xml/client_action.xml
@@ -4,6 +4,12 @@
<!-- Client Action -->
<t t-name="mail.client_action">
<div class="o_mail_chat">
+ <t t-if="widget.notification_bar">
+ <div class="o_mail_annoying_notification_bar">
+ <span class="o_mail_request_permission">Odoo needs your permission to <a href="#"> enable desktop notifications</a>.</span>
+ <span class="fa fa-close"></span>
+ </div>
+ </t>
<div class="o_mail_chat_sidebar"/>
<div class="o_mail_chat_content"/>
</div>
@@ -21,31 +27,31 @@
<span class="fa fa-star-o"/> Starred
</div>
- <t t-set="channel_type">public</t>
+ <t t-set="channel_type" t-value="'public'"/>
<t t-call="mail.chat.SidebarTitle">
<t t-set="channel_title">Channels</t>
</t>
<t t-call="mail.chat.SidebarItems">
- <t t-set="display_hash">true</t>
+ <t t-set="display_hash" t-value="true"/>
<t t-set="input_placeholder">Add a channel</t>
</t>
- <t t-set="channel_type">dm</t>
+ <t t-set="channel_type" t-value="'dm'"/>
<t t-call="mail.chat.SidebarTitle">
<t t-set="channel_title">Direct Messages</t>
</t>
<t t-call="mail.chat.SidebarItems">
- <t t-set="display_status">true</t>
+ <t t-set="display_status" t-value="true"/>
<t t-set="input_placeholder">Open chat</t>
</t>
- <t t-set="channel_type">private</t>
+ <t t-set="channel_type" t-value="'private'"/>
<t t-call="mail.chat.SidebarTitle">
<t t-set="channel_title">Private Channels</t>
</t>
<t t-call="mail.chat.SidebarItems">
<t t-set="input_placeholder">Add a channel</t>
- <t t-set="display_hash">true</t>
+ <t t-set="display_hash" t-value="true"/>
</t>
</div>
</t>
@@ -77,10 +83,14 @@
<t t-set="counter" t-value="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><i t-if="display_status" t-att-class="'o_user_status fa ' + (channel.status == 'online' ? 'fa-circle' : (channel.status == 'away' ? 'fa-clock-o' : 'fa-circle-o'))" t-attf-title="#{channel.status}"/></span>
+ <span t-if="display_status">
+ <t t-call="mail.chat.UserStatus">
+ <t t-set="status" t-value="channel.status"/>
+ </t>
+ </span>
<span t-if="display_hash" class="o_mail_hash">#</span>
<t t-esc="channel.name"/>
- <i t-if="channel.mass_mailing" class="fa fa-envelope-o"/>
+ <i t-if="channel.mass_mailing" class="fa fa-envelope-o" title="Sends messages by email"/>
<t t-call="mail.chat.SidebarNeedaction"/>
<span t-attf-class="fa fa-times pull-right o_mail_partner_unpin #{counter ? 'hide' : ''}"
t-att-title="_t('Leave this channel')" t-att-data-channel-id="channel.id"/>
@@ -92,6 +102,12 @@
</div>
</t>
+ <t t-name="mail.chat.UserStatus">
+ <i t-if="status == 'online'" class="o_mail_user_status o_user_online fa fa-circle" title="Online"/>
+ <i t-if="status == 'away'" class="o_mail_user_status o_user_idle fa fa-circle" title="Idle"/>
+ <i t-if="status == 'offline'" class="o_mail_user_status fa fa-circle-o" title="Offline"/>
+ </t>
+
<t t-name="mail.chat.UndoSnackbar">
<div class="alert o_mail_snackbar" data-dismiss="alert" role="alert">
<t t-esc="nb_needactions"/> mention(s) marked as read.
diff --git a/addons/mail/static/src/xml/composer.xml b/addons/mail/static/src/xml/composer.xml
index 4e1a9295e3b..9af882c4062 100644
--- a/addons/mail/static/src/xml/composer.xml
+++ b/addons/mail/static/src/xml/composer.xml
@@ -5,14 +5,22 @@
<div class="o_composer_attachments_list"/>
<t t-if="widget.extended">
<div class="o_composer_subject">
- <input placeholder="Subject"></input>
- <t t-call="mail.ChatComposer.Buttons"></t>
+ <input type="text" placeholder="Subject"></input>
+ <div class="btn-group o_composer_buttons">
+ <button class="btn btn-sm btn-primary o_composer_button_send" type="button"><t t-esc="widget.options.send_text"/></button>
+ <button class="btn btn-sm btn-icon fa fa-smile-o o_composer_button_emoji" type="button" data-toggle="popover"/>
+ <button class="btn btn-sm btn-icon fa fa-paperclip o_composer_button_add_attachment" type="button"/>
+ </div>
</div>
</t>
- <div class="o_composer">
+ <div t-attf-class="o_composer #{widget.extended ? 'o_extended_composer' : ''}">
<textarea class="o_composer_input" placeholder="Write something..."/>
<t t-if="!widget.extended">
- <t t-call="mail.ChatComposer.Buttons"></t>
+ <div class="btn-group o_composer_buttons">
+ <button class="btn btn-sm btn-primary o_composer_button_send" type="button"><t t-esc="widget.options.send_text"/></button>
+ <button class="btn btn-sm btn-icon fa fa-smile-o o_composer_button_emoji" type="button" data-toggle="popover"/>
+ <button class="btn btn-sm btn-icon fa fa-paperclip o_composer_button_add_attachment" type="button"/>
+ </div>
</t>
</div>
@@ -28,13 +36,6 @@
<span class="o_composer_emoji"></span>
</div>
- <t t-name="mail.ChatComposer.Buttons">
- <div class="btn-group o_composer_buttons">
- <button class="btn btn-sm btn-primary o_composer_button_send" type="button"><t t-esc="widget.options.send_text"/></button>
- <button class="btn btn-sm btn-icon fa fa-smile-o o_composer_button_emoji" type="button" data-toggle="popover"/>
- <button class="btn btn-sm btn-icon fa fa-paperclip o_composer_button_add_attachment" type="button"/>
- </div>
- </t>
<t t-name="mail.ChatComposer.emojis">
<t t-foreach="emojis" t-as="emoji">
<span t-att-data-emoji="emoji.source" class="o_mail_emoji" t-att-title="emoji.description">