summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models
diff options
context:
space:
mode:
authorRobot Odoo <xmo+roboto@odoo.com>2019-02-11 12:57:48 +0100
committerGitHub <noreply@github.com>2019-02-11 12:57:48 +0100
commit47bb7ef7968cb3c5c11f767df06fcf09333a2b13 (patch)
tree1e86b27e45fe2b5803294e886227495fdd68a96b /addons/mail/static/src/js/models
parent768844040f887868759309ad101fe50191fc949a (diff)
parent975164473ccd51c00eee5917dddbd8be71b5aefc (diff)
[MERGE] mail, hr_holidays, *: add out of office status
*: base, bus, mail_bot, test_mail Before this task, it was not easy to tell when a user is not available (or is on holiday) from conversations, such as from chat windows. With this task, a user can now tell that he is out-of-office from the user menu preferences, by defining an an out-of-office message. This information will be displayed to other users from chat conversations and mention suggestions (i.e. with `@`). Also, the computation of the user `im_status` has been changed when he has an active leave: an out-of-office message can be set on the leave, and this will be displayed on conversations instead of the user's out-of-office message from the user menu preferences. Task: 1856205 closes odoo/odoo#29974
Diffstat (limited to 'addons/mail/static/src/js/models')
-rw-r--r--addons/mail/static/src/js/models/messages/abstract_message.js8
-rw-r--r--addons/mail/static/src/js/models/messages/message.js10
-rw-r--r--addons/mail/static/src/js/models/threads/abstract_thread.js16
-rw-r--r--addons/mail/static/src/js/models/threads/dm_chat.js49
4 files changed, 79 insertions, 4 deletions
diff --git a/addons/mail/static/src/js/models/messages/abstract_message.js b/addons/mail/static/src/js/models/messages/abstract_message.js
index c1ae22b9708..bb2a19cc6ac 100644
--- a/addons/mail/static/src/js/models/messages/abstract_message.js
+++ b/addons/mail/static/src/js/models/messages/abstract_message.js
@@ -76,6 +76,14 @@ var AbstractMessage = Class.extend({
return this._serverAuthorID[0];
},
/**
+ * Threads do not have an im status by default
+ *
+ * @return {undefined}
+ */
+ getAuthorImStatus: function () {
+ return undefined;
+ },
+ /**
* Get the relative url of the avatar to display next to the message
*
* @abstract
diff --git a/addons/mail/static/src/js/models/messages/message.js b/addons/mail/static/src/js/models/messages/message.js
index dc98bb7195b..a414a11874b 100644
--- a/addons/mail/static/src/js/models/messages/message.js
+++ b/addons/mail/static/src/js/models/messages/message.js
@@ -66,6 +66,16 @@ var Message = AbstractMessage.extend(Mixins.EventDispatcherMixin, ServicesMixin
this._customerEmailData.push(data);
},
/**
+ * @override
+ * @return {string|undefined}
+ */
+ getAuthorImStatus: function () {
+ if (!this.hasAuthor()) {
+ return undefined;
+ }
+ return this.call('mail_service', 'getImStatus', { partnerID: this.getAuthorID() });
+ },
+ /**
* Get the name of the author of this message
* If there are no author, return "".
*
diff --git a/addons/mail/static/src/js/models/threads/abstract_thread.js b/addons/mail/static/src/js/models/threads/abstract_thread.js
index d6a37967c68..a515c4d2f8a 100644
--- a/addons/mail/static/src/js/models/threads/abstract_thread.js
+++ b/addons/mail/static/src/js/models/threads/abstract_thread.js
@@ -75,6 +75,22 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, {
return this._name;
},
/**
+ * By default, threads do not have out-of-office feature
+ *
+ * @return {string|undefined}
+ */
+ getOutOfOfficeInfo: function () {
+ return undefined;
+ },
+ /**
+ * By default, threads do not have out-of-office feature
+ *
+ * @return {string|undefined}
+ */
+ getOutOfOfficeMessage: function () {
+ return undefined;
+ },
+ /**
* Get the status of the thread (e.g. 'online', 'offline', etc.)
*
* @returns {string}
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..fb524515193 100644
--- a/addons/mail/static/src/js/models/threads/dm_chat.js
+++ b/addons/mail/static/src/js/models/threads/dm_chat.js
@@ -3,6 +3,10 @@ odoo.define('mail.model.DMChat', function (require) {
var TwoUserChannel = require('mail.model.TwoUserChannel');
+var core = require('web.core');
+
+var _t = core._t;
+
/**
* Any piece of code in JS that make use of DMs must ideally interact with
* such objects, instead of direct data from the server.
@@ -18,6 +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_date_end]
*/
init: function (params) {
this._super.apply(this, arguments);
@@ -26,8 +32,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
+ }]);
},
//--------------------------------------------------------------------------
@@ -45,6 +57,34 @@ 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 () {
+ return this._outOfOfficeMessage;
+ },
+ /**
* @override
*/
getPreview: function () {
@@ -53,10 +93,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 });
},
});