diff options
| author | Aaron Bohy <aab@odoo.com> | 2015-12-10 16:33:46 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2015-12-16 15:48:43 +0100 |
| commit | 5d1b3232fc02d3c0a7f10e6bb73e308596c3a5a5 (patch) | |
| tree | 10bce856ab35fd212e0bfb2e459ff9e899aff1c6 /addons/mail/static/src | |
| parent | 89ba0a811b9cb10ba6747487eb97a35e3300a924 (diff) | |
[FIX] bus,mail: user presence
Before this rev., no notification was sent on the bus when the user presence
changed. Thus, the bullets displayed in Discuss were never updated and stayed
as they were on the initialilization of the chat_manager (on webclient launch).
This rev. makes the bus.presence notifications work, and handles them client
side.
Moreover, the disconnections detection is now performed at each poll (with a
maximum of 1 per minute), instead of randomly (1/100 chance) at each poll, as
it scales better than the former solution. We also added a cron that performs
this check every 5 minutes. It is needed to detect that the last connected user
just disconnected (useful for visitors in the website, trying to talk with a
livechat operator).
Also, the 'away' status is now handled client side, as it makes more sense
that way (being away at each poll, e.g. every 50seconds, during 10 minutes
doesn't mean that we didn't come back between two polls).
Finaly, in bus.js, CrossTabBus, we moved the code writing in/reading the local
storage after the tab registration as this code depends on the fact that the
tab is the master tab or not (and this is known only once the tab is
registered).
This rev. was necessary in stable because the livechat uses the user status to
detect if there is an operator available, and this was often inaccurate.
Moreover, it improves the user experience of the chat in the backend.
Diffstat (limited to 'addons/mail/static/src')
| -rw-r--r-- | addons/mail/static/src/js/chat_manager.js | 12 | ||||
| -rw-r--r-- | addons/mail/static/src/js/client_action.js | 10 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/client_action.xml | 2 |
3 files changed, 19 insertions, 5 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 909a4a0ff5b..cd758790d64 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -272,6 +272,7 @@ function make_channel (data, options) { if ('direct_partner' in data) { channel.type = "dm"; channel.name = data.direct_partner[0].name; + channel.direct_partner_id = data.direct_partner[0].id; channel.status = data.direct_partner[0].im_status; } return channel; @@ -399,6 +400,9 @@ function on_notification (notification) { } else if (model === 'res.partner') { // channel joined/left, message marked as read/(un)starred, chat open/closed on_partner_notification(notification[1]); + } else if (model === 'bus.presence') { + // update presence of users + on_presence_notification(notification[1]); } } @@ -530,6 +534,14 @@ function on_chat_session_notification (chat_session) { } } +function on_presence_notification (data) { + var dm = _.findWhere(channels, {direct_partner_id: data.id}); + if (dm) { + dm.status = data.im_status; + chat_manager.bus.trigger('update_dm_presence', dm); + } +} + // Public interface //---------------------------------------------------------------------------------- var chat_manager = { diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js index 1a12ff36912..3d97a35af0e 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({ width: '100%', allowClear: true, multiple: true, - formatResult: function(item){ - var css_class = "fa-circle" + (item.im_status === 'online' ? "" : "-o"); + 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); }, query: function (query) { @@ -135,6 +135,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, { this.action = action; this.options = options || {}; this.channels_scrolltop = {}; + this.throttled_render_sidebar = _.throttle(this.render_sidebar.bind(this), 100, { leading: false }); }, willStart: function () { @@ -213,9 +214,10 @@ var ChatAction = Widget.extend(ControlPanelMixin, { chat_manager.bus.on('anyone_listening', self, function (channel, query) { query.is_displayed = query.is_displayed || channel.id === self.channel.id; }); - chat_manager.bus.on('update_needaction', self, self.render_sidebar); chat_manager.bus.on('unsubscribe_from_channel', self, self.render_sidebar); - chat_manager.bus.on('update_channel_unread_counter', self, self.render_sidebar); + chat_manager.bus.on('update_needaction', self, self.throttled_render_sidebar); + chat_manager.bus.on('update_channel_unread_counter', self, self.throttled_render_sidebar); + chat_manager.bus.on('update_dm_presence', self, self.throttled_render_sidebar); }); }, diff --git a/addons/mail/static/src/xml/client_action.xml b/addons/mail/static/src/xml/client_action.xml index 11b32ee0e8d..bb29d8cca27 100644 --- a/addons/mail/static/src/xml/client_action.xml +++ b/addons/mail/static/src/xml/client_action.xml @@ -77,7 +77,7 @@ <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' : 'fa-circle-o')"/></span> + <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_hash" class="o_mail_hash">#</span> <t t-esc="channel.name"/> <i t-if="channel.mass_mailing" class="fa fa-envelope-o"/> |
