From 07a261db7196d3f7aa7d50d98575c5b6efca9242 Mon Sep 17 00:00:00 2001 From: XavierDo Date: Mon, 7 Jan 2019 11:19:00 +0000 Subject: [IMP] bus, mail, mail_bot: add im_status service This commit is a refactoring of im_status management. This commit also add im_status in two places, near the author in a mail thread and on each suggestion when using mentions. A service to manage im_status will have multiple benefits here: -centralise information, avoid to call the server multiple time for the same im_status -update all im_status at once and keep consistency in display. With this commit, the im_status updates are now done by rpc call. Updates where previously made with the bus but this has some drawback, since the bus will only give the information 50 seconds after the beginning of the request, in the worst case, we van wait 2*50 seconds to get an update. More than that, the im_status where only updates for pinned dm_chat. Dm chat are synchronized cross tabs, making the use of the bus possible for this purpose. Since we will need to display im_status not linked to dm_chat, the list to update will be different from tab to tab making the use of bus difficult for this purpose. Technical notes: -im_search has been moved from bus to mail addons since it concerns mail.channel -Update of an im_status should be reflected everywhere in the page. Since im_status is a rendered template used in multiple widget, we should add the correct logic to all concerened widget. The current solution is simple: use a jquery selector to find every place where im_status is rendered. -we add a new im_status: im_partner. This will indicate that that the partner has no user linked to him, making it possible to avoid to ask for status updates for this partner. -The update will only be done when the tab is focused. (and will be done asap once the tab get focus back) --- addons/mail/static/src/js/models/threads/dm_chat.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js/models/threads/dm_chat.js') diff --git a/addons/mail/static/src/js/models/threads/dm_chat.js b/addons/mail/static/src/js/models/threads/dm_chat.js index 5e69dbeff8c..4967a1e9963 100644 --- a/addons/mail/static/src/js/models/threads/dm_chat.js +++ b/addons/mail/static/src/js/models/threads/dm_chat.js @@ -26,8 +26,14 @@ var DMChat = TwoUserChannel.extend({ this._directPartnerID = data.direct_partner[0].id; this._name = data.custom_channel_name || data.direct_partner[0].name; - this._status = data.direct_partner[0].im_status; + this._outOfOfficeMessage = data.direct_partner[0].out_of_office_message; + this._outOfOfficeDateEnd = data.direct_partner[0].out_of_office_date_end; this._type = 'dm_chat'; + + this.call('mail_service', 'updateImStatus', [{ + id: this._directPartnerID, + im_status: data.direct_partner[0].im_status + }]); }, //-------------------------------------------------------------------------- @@ -53,10 +59,11 @@ var DMChat = TwoUserChannel.extend({ return result; }, /** - * @param {string} newStatus + * @override + * @return {string} */ - setStatus: function (newStatus) { - this._status = newStatus; + getStatus: function () { + return this.call('mail_service', 'getImStatus', { partnerID: this._directPartnerID }); }, }); -- cgit v1.2.3 From c21d200285ebeb646b8e5be6ba233f96d9714c6f Mon Sep 17 00:00:00 2001 From: XavierDo Date: Mon, 7 Jan 2019 12:31:18 +0000 Subject: [IMP] mail: add ooo status in chats windows. In a chat window with a single usert (dm_chat) the ooo status of the other user is displayed on the top when set. Task: 1856205 --- addons/mail/static/src/js/models/threads/dm_chat.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'addons/mail/static/src/js/models/threads/dm_chat.js') diff --git a/addons/mail/static/src/js/models/threads/dm_chat.js b/addons/mail/static/src/js/models/threads/dm_chat.js index 4967a1e9963..21fb72e91ae 100644 --- a/addons/mail/static/src/js/models/threads/dm_chat.js +++ b/addons/mail/static/src/js/models/threads/dm_chat.js @@ -1,7 +1,9 @@ odoo.define('mail.model.DMChat', function (require) { "use strict"; +var core = require('web.core'); var TwoUserChannel = require('mail.model.TwoUserChannel'); +var _t = core._t; /** * Any piece of code in JS that make use of DMs must ideally interact with @@ -18,6 +20,7 @@ var DMChat = TwoUserChannel.extend({ * @param {integer} params.data.direct_partner[0].id * @param {string} params.data.direct_partner[0].im_status * @param {string} params.data.direct_partner[0].name + * @param {string} [params.data.direct_partner[0].out_of_office_message=''] */ init: function (params) { this._super.apply(this, arguments); @@ -50,6 +53,17 @@ var DMChat = TwoUserChannel.extend({ getDirectPartnerID: function () { return this._directPartnerID; }, + /** + * Get the out of office message of the thread + * + * @returns {string} + */ + getOutOfOfficeMessage: function () { + if (this._outOfOfficeMessage === '') { + return undefined; + } + return this._outOfOfficeMessage; + }, /** * @override */ -- cgit v1.2.3 From 086405344e7302d9f7b243ba0c30d55131aeb3fe Mon Sep 17 00:00:00 2001 From: XavierDo Date: Mon, 7 Jan 2019 10:56:19 +0000 Subject: [IMP] mail, hr_holidays: use leaves to compute im_status When on leave, the im_status can be either leave_online or leave_offline. This will allow to display a specific icon and a default message when the user is not at the office. The leave can have an out of office message. This message will be displayed in the chat window instead of the user ooo message, and the end date of the leave will be displayed too. Technical details. Right now the im_status access leaves directly to know if a user is on leave or not. An index has been added to optimise this request (thanks to rco). A solution to optimise this would be to compute part of the information in a cron. Task: 1856205 --- .../mail/static/src/js/models/threads/dm_chat.js | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'addons/mail/static/src/js/models/threads/dm_chat.js') diff --git a/addons/mail/static/src/js/models/threads/dm_chat.js b/addons/mail/static/src/js/models/threads/dm_chat.js index 21fb72e91ae..fb524515193 100644 --- a/addons/mail/static/src/js/models/threads/dm_chat.js +++ b/addons/mail/static/src/js/models/threads/dm_chat.js @@ -1,8 +1,10 @@ odoo.define('mail.model.DMChat', function (require) { "use strict"; -var core = require('web.core'); var TwoUserChannel = require('mail.model.TwoUserChannel'); + +var core = require('web.core'); + var _t = core._t; /** @@ -20,7 +22,8 @@ var DMChat = TwoUserChannel.extend({ * @param {integer} params.data.direct_partner[0].id * @param {string} params.data.direct_partner[0].im_status * @param {string} params.data.direct_partner[0].name - * @param {string} [params.data.direct_partner[0].out_of_office_message=''] + * @param {string} [params.data.direct_partner[0].out_of_office_message] + * @param {string} [params.data.direct_partner[0].out_of_office_date_end] */ init: function (params) { this._super.apply(this, arguments); @@ -54,14 +57,31 @@ var DMChat = TwoUserChannel.extend({ return this._directPartnerID; }, /** + * Get the out of office info + * + * @override {mail.model.AbstractThread} + * @returns {string|undefined} + */ + getOutOfOfficeInfo: function () { + if (!this._outOfOfficeDateEnd) { + return undefined; + } + var currentDate = new Date(); + var date = new Date(this._outOfOfficeDateEnd); + var options = { day: 'numeric', month: 'short' }; + if (currentDate.getFullYear() !== date.getFullYear()) { + options.year = 'numeric'; + } + var formattedDate = date.toLocaleDateString(window.navigator.language, options); + return _.str.sprintf(_t("Out of office until %s"), formattedDate); + }, + /** * Get the out of office message of the thread * + * @override {mail.model.AbstractThread} * @returns {string} */ getOutOfOfficeMessage: function () { - if (this._outOfOfficeMessage === '') { - return undefined; - } return this._outOfOfficeMessage; }, /** -- cgit v1.2.3