diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-08-24 10:37:47 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-08-24 13:21:45 +0000 |
| commit | 72b9335334c076d8deaa36e404feaa3f4d30c351 (patch) | |
| tree | aea8c816b33d89b409fedbc75bcca3d2d6597717 /addons/im_livechat/static/src/models/thread | |
| parent | 0834d241624330ab3fd3925366a3217fe8145dfc (diff) | |
[FIX] mail, im_livechat: make livechat work properly
- fix traceback on receiving first livechat message due to bad computation of
correspondent
- fix missing [0] in return of country name_get in channel_info
- fix visitor/correspondent computation to work when chatting with oneself
- reintroduce livechat ordered by last message in discuss sidebar
- improve mock server to make these fixes possible to test
- introduce corresponding tests
PR: #56243
task-2323670
closes odoo/odoo#56414
X-original-commit: f623bfd2c8819604c709bc723153c071dca6e3cc
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/im_livechat/static/src/models/thread')
| -rw-r--r-- | addons/im_livechat/static/src/models/thread/thread.js | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/addons/im_livechat/static/src/models/thread/thread.js b/addons/im_livechat/static/src/models/thread/thread.js index 148e7b7c5ee..190a2088066 100644 --- a/addons/im_livechat/static/src/models/thread/thread.js +++ b/addons/im_livechat/static/src/models/thread/thread.js @@ -17,12 +17,35 @@ registerClassPatchModel('mail.thread', 'im_livechat/static/src/models/thread/thr */ convertData(data) { const data2 = this._super(data); + if ('last_message_id' in data) { + if (!data2.messagesAsServerChannel) { + data2.messagesAsServerChannel = []; + } + data2.messagesAsServerChannel.push(['insert', { id: data.last_message_id }]); + } if ('livechat_visitor' in data && data.livechat_visitor) { if (!data2.members) { data2.members = []; } + // `livechat_visitor` without `id` is the anonymous visitor. if (!data.livechat_visitor.id) { - // Create partner derived from public partner. + /** + * Create partner derived from public partner and replace the + * public partner. + * + * Indeed the anonymous visitor is registered as a member of the + * channel as the public partner in the database to avoid + * polluting the contact list with many temporary partners. + * + * But the issue with public partner is that it is the same + * record for every livechat, whereas every correspondent should + * actually have its own visitor name, typing status, etc. + * + * Due to JS being temporary by nature there is no such notion + * of polluting the database, it is therefore acceptable and + * easier to handle one temporary partner per channel. + */ + data2.members.push(['unlink', this.env.messaging.publicPartner]); const partner = this.env.models['mail.partner'].create( Object.assign( this.env.models['mail.partner'].convertData(data.livechat_visitor), @@ -50,6 +73,9 @@ registerInstancePatchModel('mail.thread', 'im_livechat/static/src/models/thread/ */ _computeDisplayName() { if (this.channel_type === 'livechat' && this.correspondent) { + if (this.correspondent.country) { + return `${this.correspondent.nameOrDisplayName} (${this.correspondent.country.name})`; + } return this.correspondent.nameOrDisplayName; } return this._super(); |
