Skip to content

Commit 992a68a

Browse files
bit-odoohbh-odoo
authored andcommitted
[FIX] im_livechat: few changes for livechat
Before this commit: - When the operator edit or delete a message, but the livechat visitor does not receive the updated content. - If the first message of a series of squashed messages is deleted, the avatar and the name of the author are lost on the visitor side. After this commit: - Livechat visitors will receive the updated content instantly and disable the reactions and replay buttons for the LiveChat channel. - Displayed message with the avatar and the name of the author on visitor side. Task-2678397 closes odoo#82892 Signed-off-by: Alexandre Kühn (aku) <[email protected]>
1 parent b21a960 commit 992a68a

File tree

5 files changed

+127
-3
lines changed

5 files changed

+127
-3
lines changed

addons/im_livechat/models/mail_channel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ def _send_history_message(self, pid, page_history):
154154
message_body = '<ul>%s</ul>' % (''.join(html_links))
155155
self._send_transient_message(self.env['res.partner'].browse(pid), message_body)
156156

157+
def _message_update_content_after_hook(self, message):
158+
self.ensure_one()
159+
if self.channel_type == 'livechat':
160+
self.env['bus.bus']._sendone(self.uuid, 'mail.message/insert', {
161+
'id': message.id,
162+
'body': message.body,
163+
})
164+
super()._message_update_content_after_hook(message=message)
165+
157166
def _get_visitor_leave_message(self, operator=False, cancel=False):
158167
return _('Visitor has left the conversation.')
159168

addons/im_livechat/static/src/components/discuss/tests/discuss_tests.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,68 @@ QUnit.test('call buttons should not be present on livechat', async function (ass
378378
);
379379
});
380380

381+
QUnit.test('reaction button should not be present on livechat', async function (assert) {
382+
assert.expect(1);
383+
384+
this.data['mail.channel'].records.push({
385+
channel_type: 'livechat',
386+
id: 10,
387+
livechat_operator_id: this.data.currentPartnerId,
388+
members: [this.data.currentPartnerId, this.data.publicPartnerId],
389+
});
390+
await this.start({
391+
discuss: {
392+
params: {
393+
default_active_id: 'mail.channel_10',
394+
},
395+
},
396+
});
397+
await afterNextRender(() => {
398+
document.querySelector(`.o_ComposerTextInput_textarea`).focus();
399+
document.execCommand('insertText', false, "Test");
400+
});
401+
await afterNextRender(() =>
402+
document.querySelector('.o_Composer_buttonSend').click()
403+
);
404+
await afterNextRender(() => document.querySelector('.o_Message').click());
405+
assert.containsNone(
406+
document.body,
407+
'.o_MessageActionList_actionReaction',
408+
"should not have action to add a reaction"
409+
);
410+
});
411+
412+
QUnit.test('reply button should not be present on livechat', async function (assert) {
413+
assert.expect(1);
414+
415+
this.data['mail.channel'].records.push({
416+
channel_type: 'livechat',
417+
id: 10,
418+
livechat_operator_id: this.data.currentPartnerId,
419+
members: [this.data.currentPartnerId, this.data.publicPartnerId],
420+
});
421+
await this.start({
422+
discuss: {
423+
params: {
424+
default_active_id: 'mail.channel_10',
425+
},
426+
},
427+
});
428+
await afterNextRender(() => {
429+
document.querySelector(`.o_ComposerTextInput_textarea`).focus();
430+
document.execCommand('insertText', false, "Test");
431+
});
432+
await afterNextRender(() =>
433+
document.querySelector('.o_Composer_buttonSend').click()
434+
);
435+
await afterNextRender(() => document.querySelector('.o_Message').click());
436+
assert.containsNone(
437+
document.body,
438+
'.o_MessageActionList_actionReply',
439+
"should not have reply action"
440+
);
441+
});
442+
381443
});
382444
});
383445
});

addons/im_livechat/static/src/legacy/public_livechat.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ var LivechatButton = Widget.extend({
221221
this._renderMessages();
222222
return;
223223
}
224+
case 'mail.message/insert': {
225+
const message = this._messages.find(message => message._id === payload.id);
226+
if (!message) {
227+
return;
228+
}
229+
message._body = utils.Markup(payload.body);
230+
this._renderMessages()
231+
return;
232+
}
224233
}
225234
},
226235
/**
@@ -701,7 +710,8 @@ var WebsiteLivechat = AbstractThread.extend(ThreadTypingMixin, {
701710
* @returns {im_livechat.legacy.im_livechat.model.WebsiteLivechatMessage[]}
702711
*/
703712
getMessages: function () {
704-
return this._messages;
713+
// ignore removed messages
714+
return this._messages.filter(message => !message.isEmpty());
705715
},
706716
/**
707717
* @returns {Array}
@@ -2997,7 +3007,7 @@ var ThreadWidget = Widget.extend({
29973007
this._currentThreadID = thread.getID();
29983008

29993009
// copy so that reverse do not alter order in the thread object
3000-
var messages = _.clone(thread.getMessages({ domain: options.domain || [] }));
3010+
var messages = _.clone(thread.getMessages());
30013011

30023012
var modeOptions = options.isCreateMode ? this._disabledOptions :
30033013
this._enabledOptions;

addons/im_livechat/static/src/models/message/message.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @odoo-module **/
22

3-
import { registerClassPatchModel } from '@mail/model/model_core';
3+
import {
4+
registerClassPatchModel,
5+
registerInstancePatchModel,
6+
} from '@mail/model/model_core';
47

58
registerClassPatchModel('mail.message', 'im_livechat/static/src/models/message/message.js', {
69
/**
@@ -23,3 +26,19 @@ registerClassPatchModel('mail.message', 'im_livechat/static/src/models/message/m
2326
return data2;
2427
},
2528
});
29+
registerInstancePatchModel('mail.message', 'im_livechat/static/src/models/message/message.js', {
30+
31+
//----------------------------------------------------------------------
32+
// Private
33+
//----------------------------------------------------------------------
34+
35+
/**
36+
* @override
37+
*/
38+
_computeHasReactionIcon() {
39+
if (this.originThread && this.originThread.channel_type === 'livechat') {
40+
return false;
41+
}
42+
return this._super();
43+
},
44+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** @odoo-module **/
2+
3+
import { registerInstancePatchModel } from '@mail/model/model_core';
4+
5+
registerInstancePatchModel('mail.message_action_list', 'im_livechat/static/src/models/message_action_list/message_action_list.js', {
6+
7+
//----------------------------------------------------------------------
8+
// Private
9+
//----------------------------------------------------------------------
10+
11+
/**
12+
* @override
13+
*/
14+
_computeHasReplyIcon() {
15+
if (
16+
this.message &&
17+
this.message.originThread &&
18+
this.message.originThread.channel_type === 'livechat'
19+
) {
20+
return false;
21+
}
22+
return this._super();
23+
}
24+
});

0 commit comments

Comments
 (0)