From 3fea5b2136627c1d7e83b2a5e111952fe3eb10a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Mon, 15 Jun 2020 18:12:21 +0000 Subject: [REF] mail, *: refactor messaging with OWL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is a significant rewriting of client-side discuss, chatter, chat window, and messaging menu using OWL. The behavior should be broadly the same, with some slight functional changes here and there. From a technical standpoint, the code of messaging is mainly organized in 2 main groups of modules: - models, which are logical entities that depict the client-side state of messaging as a whole. - components, which are in charge of displaying information from models. This refactoring also introduces new JS guidelines regarding folder structure (/static) and naming rules for JS modules. Community PR: https://github.com/odoo/odoo/pull/39023 Enterprise PR: https://github.com/odoo/enterprise/pull/6249 Task-1914207 This PR is a collaborative work by Alexandre, Julien, Sébastien and Xavier, with the precious help of Lucas to speed it up towards the end. closes odoo/odoo#39023 Related: odoo/enterprise#6249 Signed-off-by: Alexandre Kühn (aku) Co-authored-by: Alexandre Kühn Co-authored-by: Julien Giannone Co-authored-by: Lucas Perais Co-authored-by: Sébastien Theys Co-authored-by: Xavier Dubuc --- .../mail/static/src/js/models/threads/dm_chat.js | 109 --------------------- 1 file changed, 109 deletions(-) delete mode 100644 addons/mail/static/src/js/models/threads/dm_chat.js (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 deleted file mode 100644 index 177c5224ea4..00000000000 --- a/addons/mail/static/src/js/models/threads/dm_chat.js +++ /dev/null @@ -1,109 +0,0 @@ -odoo.define('mail.model.DMChat', function (require) { -"use strict"; - -var ChannelSeenMixin = require('mail.model.ChannelSeenMixin'); -var TwoUserChannel = require('mail.model.TwoUserChannel'); - -var core = require('web.core'); -const { str_to_datetime } = require('web.time'); - -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. - */ -var DMChat = TwoUserChannel.extend(ChannelSeenMixin, { - /** - * @override - * @param {Object} params - * @param {Object} params.data - * @param {string|undefined} [params.custom_channel_name] if set, use this - * custom name for this DM - * @param {Object[]} params.data.direct_partner - * @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_date_end] - */ - init: function (params) { - this._super.apply(this, arguments); - ChannelSeenMixin.init.apply(this, arguments); - - var data = params.data; - - this._directPartnerID = data.direct_partner[0].id; - this._name = data.custom_channel_name || data.direct_partner[0].name; - 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 - }]); - }, - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * Get the direct partner ID linked to the DM, i.e. the partner ID of the - * user at the other end of the DM conversation. All DM chats do have a - * direct partner iD. - * - * @returns {integer} - */ - getDirectPartnerID: function () { - 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 = str_to_datetime(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); - }, - /** - * @override - */ - getPreview: function () { - var result = this._super.apply(this, arguments); - result.imageSRC = '/web/image/res.partner/' + this.getDirectPartnerID() + '/image_128'; - return result; - }, - /** - * @override - * @return {string} - */ - getStatus: function () { - return this.call('mail_service', 'getImStatus', { partnerID: this._directPartnerID }); - }, - - /** - * @param {Object} data - * @param {string} data.outOfOfficeDateEnd - */ - updateOutOfOfficeInfo: function (data) { - this._outOfOfficeDateEnd = data.outOfOfficeDateEnd; - this.call('mail_service', 'getMailBus').trigger('updated_out_of_office', { - threadID: this.getID(), - }); - } -}); - -return DMChat; - -}); -- cgit v1.2.3