diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-08-13 16:26:35 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-08-13 16:26:35 +0000 |
| commit | c2918c139b8f1026b57a257fbb74570d7a224c98 (patch) | |
| tree | 6b1a5cbf5b048dd86048119cd66f5fa382595a7b /addons/mail/static/src/models/thread/thread.js | |
| parent | 41527531b7b6f727e25a5a68aedb49609fbb1d3a (diff) | |
[IMP] web, *: improve mock server and replace most mail mockRPC
Improve mock server:
- add support for mocked `fetch`
- add support for `active_test`
- add support for x2m `in` in domains
- add support for default values computed from a function
- implement a more natural "next id" compute
- allow initial data without ids
- ensure write and x2m commands integrity
- improve bad data/bad commands error messages
- always warn for failing RPC, not only in debug mode
- fix all existing tests that had inconsistency data
Other changes done in mail (or dependents) that are not just related to tests:
- remove `direct_partner` from formatter result
->`correspondent` can be computed from other keys, especially `members`
- fix `livechat_visitor` convertData
-> only process if there is value
- add `current_partner` and `current_user_id` as `init_messaging` result
-> easier to mock than session
- remove usage of `need_moderation`
-> that was just a search indirection to `moderation_status`
- adapt `partner_id` -> `res_partner_id` key in `_notification_format`
-> to be consistent with field name
- add name in result of `mail_partner_format`
-> sometimes display_name is not the same
- remove usage of `is_moderator`
-> that was just an indirection to `moderation_channel_ids`
Enterprise counterpart: https://github.com/odoo/enterprise/pull/11523
task-2287171
closes odoo/odoo#55854
X-original-commit: 7ba3fecb3377a720d1eb70e7515a0c45da73836d
Related: odoo/enterprise#12391
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models/thread/thread.js')
| -rw-r--r-- | addons/mail/static/src/models/thread/thread.js | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index 6b6f9a4c1d4..56bdfd36138 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -206,16 +206,7 @@ function factory(dependencies) { data2.uuid = data.uuid; } - // relation - if ('direct_partner' in data) { - if (!data.direct_partner) { - data2.correspondent = [['unlink-all']]; - } else { - data2.correspondent = [ - ['insert', this.env.models['mail.partner'].convertData(data.direct_partner[0])], - ]; - } - } + // relations if ('members' in data) { if (!data.members) { data2.members = [['unlink-all']]; @@ -798,6 +789,23 @@ function factory(dependencies) { /** * @private + * @returns {mail.partner} + */ + _computeCorrespondent() { + if (this.channel_type === 'channel') { + return [['unlink']]; + } + const correspondents = this.members.filter(partner => + partner !== this.env.messaging.currentPartner + ); + if (correspondents.length === 1) { + return [['link', correspondents[0]]]; + } + return [['unlink']]; + } + + /** + * @private * @returns {string} */ _computeDisplayName() { @@ -843,16 +851,13 @@ function factory(dependencies) { * @returns {boolean} */ _computeIsModeratedByCurrentPartner() { - if (this.model !== 'mail.channel') { - return false; - } if (!this.messaging) { return false; } if (!this.messaging.currentPartner) { return false; } - return this.messaging.currentPartner.moderatedChannelIds.includes(this.id); + return this.moderators.includes(this.env.messaging.currentPartner); } /** @@ -1211,6 +1216,12 @@ function factory(dependencies) { isCausal: true, }), correspondent: many2one('mail.partner', { + compute: '_computeCorrespondent', + dependencies: [ + 'channel_type', + 'members', + 'messagingCurrentPartner', + ], inverse: 'correspondentThreads', }), correspondentNameOrDisplayName: attr({ @@ -1281,8 +1292,8 @@ function factory(dependencies) { isModeratedByCurrentPartner: attr({ compute: '_computeIsModeratedByCurrentPartner', dependencies: [ - 'model', 'messagingCurrentPartner', + 'moderators', ], }), /** @@ -1377,6 +1388,12 @@ function factory(dependencies) { moderation: attr({ default: false, }), + /** + * Partners that are moderating this thread (only applies to channels). + */ + moderators: many2many('mail.partner', { + inverse: 'moderatedChannels', + }), moduleIcon: attr(), name: attr(), needactionMessages: many2many('mail.message', { |
