diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-01-05 15:51:49 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-01-05 15:51:49 +0100 |
| commit | 31ce19bd7c8ff90aa3a3f34ba13dfbbe00865b3b (patch) | |
| tree | 4f24c985d7f4f7d08af1830f8199b120f35018f7 /addons/mail/static/src/js | |
| parent | 9b5311e0c94ea2b3ad6c36bc9a4ea63228779b66 (diff) | |
| parent | 97e87a42cdfaed04a6f50d928d86ac6e3bec9f91 (diff) | |
[MERGE] forward port of branch 9.0 up to 97e87a4
Diffstat (limited to 'addons/mail/static/src/js')
| -rw-r--r-- | addons/mail/static/src/js/chat_manager.js | 78 | ||||
| -rw-r--r-- | addons/mail/static/src/js/client_action.js | 15 |
2 files changed, 58 insertions, 35 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); }, |
