diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-08-28 12:53:38 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-08-28 16:15:15 +0000 |
| commit | 17611f4adc5e950b0a75a2a6615b1da3c956387f (patch) | |
| tree | ede6cbc0bc67c1dceed3b5ca6c1bb3e08389675c /addons/mail/static/src/js | |
| parent | 5ba64925fd846e9a9a4884913e3d1004d05ecdf6 (diff) | |
[FIX] mail, *: fix opens and redirects, adapt messaging menu close
task-2244279
task-2262862
task-2274993
task-2277537
task-2282238
closes odoo/odoo#56745
X-original-commit: 109f202
Related: odoo/enterprise#12761
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/js')
| -rw-r--r-- | addons/mail/static/src/js/many2one_avatar_user.js | 93 |
1 files changed, 9 insertions, 84 deletions
diff --git a/addons/mail/static/src/js/many2one_avatar_user.js b/addons/mail/static/src/js/many2one_avatar_user.js index 3a4e04089f5..6a5b527004a 100644 --- a/addons/mail/static/src/js/many2one_avatar_user.js +++ b/addons/mail/static/src/js/many2one_avatar_user.js @@ -4,27 +4,18 @@ odoo.define('mail.Many2OneAvatarUser', function (require) { // This module defines an extension of the Many2OneAvatar widget, which is // integrated with the messaging system. The Many2OneAvatarUser is designed // to display people, and when the avatar of those people is clicked, it - // opens a DM chat window with the corresponding partner (the messaging - // system is based on model 'res.partner'). + // opens a DM chat window with the corresponding user. // - // This widget is supported on many2one fields pointing to 'res.users'. When - // the user is clicked, we fetch the partner id of the given user (field - // 'partner_id'), and we open a chat window with this partner. + // This widget is supported on many2one fields pointing to 'res.users'. // // Usage: // <field name="user_id" widget="many2one_avatar_user"/> // // The widget is designed to be extended, to support many2one fields pointing - // to other models than 'res.users'. Those models must have a many2one field - // pointing to 'res.partner'. Ideally, the many2one should be false if the - // corresponding partner isn't associated with a user, otherwise it will open - // chat windows with partners that won't be able to read your messages and - // reply. + // to other models than 'res.users'. - const { _t } = require('web.core'); const fieldRegistry = require('web.field_registry'); const { Many2OneAvatar } = require('web.relational_fields'); - const session = require('web.session'); const { Component } = owl; @@ -32,71 +23,17 @@ odoo.define('mail.Many2OneAvatarUser', function (require) { events: Object.assign({}, Many2OneAvatar.prototype.events, { 'click .o_m2o_avatar': '_onAvatarClicked', }), - // Maps record ids to promises that resolve with the corresponding partner ids. - // Used as a cache shared between all instances of this widget. - partnerIds: {}, // This widget is only supported on many2ones pointing to 'res.users' - supportedModel: 'res.users', + supportedModels: ['res.users'], init() { this._super(...arguments); - if (this.supportedModel !== this.field.relation) { - throw new Error(`This widget is only supported on many2one fields pointing to ${this.supportedModel}`); + if (!this.supportedModels.includes(this.field.relation)) { + throw new Error(`This widget is only supported on many2one fields pointing to ${JSON.stringify(this.supportedModels)}`); } if (this.mode === 'readonly') { this.className += ' o_clickable_m2o_avatar'; } - this.partnerField = 'partner_id'; // field to read on 'res.users' to get the partner id - }, - - //---------------------------------------------------------------------- - // Private - //---------------------------------------------------------------------- - - /** - * Displays a warning when we can't open a DM chat window with the partner - * corresponding to the clicked record. On model 'res.users', it only - * happens when the user clicked on himself. This can be overridden by - * extensions of this widget, for instance to handle the case where the - * user clicked on a record whose partner isn't associated with any user. - * - * @private - */ - _displayWarning() { - this.displayNotification({ - message: _t('You cannot chat with yourself'), - type: 'info', - }); - }, - /** - * @private - * @param {number} resId - * @returns {string} the key to use in the partnerIds cache - */ - _getCacheKey(resId) { - return `${this.field.relation}_${resId}`; - }, - /** - * For a given record id of the comodel, returns the corresponding - * partner id. - * - * @param {number} resId - * @returns {Promise<integer|false>} - */ - _resIdToPartnerId(resId) { - const key = this._getCacheKey(resId); - if (!this.partnerIds[key]) { - const params = { - method: 'read', - model: this.field.relation, - args: [resId, [this.partnerField]], - }; - this.partnerIds[key] = this._rpc(params).then(recs => { - const partner = recs[0][this.partnerField]; - return partner && partner[0]; - }); - } - return this.partnerIds[key]; }, //---------------------------------------------------------------------- @@ -105,27 +42,15 @@ odoo.define('mail.Many2OneAvatarUser', function (require) { /** * When the avatar is clicked, open a DM chat window with the - * corresponding partner. If the user clicked on himself, open a blank - * thread window, for the sake of consistency. + * corresponding user. * * @private * @param {MouseEvent} ev */ async _onAvatarClicked(ev) { ev.stopPropagation(); // in list view, prevent from opening the record - let partnerId; - if (this.field.relation !== 'res.users' || this.value.res_id !== session.uid) { - partnerId = await this._resIdToPartnerId(this.value.res_id); - } - if (partnerId && partnerId !== session.partner_id) { - const env = Component.env; - const partner = env.models['mail.partner'].insert({ - id: partnerId, - }); - partner.openChat(); - } else { - this._displayWarning(partnerId); - } + const env = Component.env; + await env.messaging.openChat({ userId: this.value.res_id }); } }); |
