[FIX] mail: no duplicated messages on (un)star document thread message

Before this commit, when we star or unstar a message from a document thread,
the message was duplicated in the document thread.

This commit fixes this issue by not adding already existing messages on
document threads.

Task-ID 1871428
This commit is contained in:
Pratima Gupta
2018-08-09 13:19:00 +02:00
committed by Alexandre Kühn
parent e0bc158655
commit fca1875a69
2 changed files with 78 additions and 0 deletions
@@ -60,10 +60,15 @@ var DocumentThread = Thread.extend({
/**
* Add this message to this document thread.
*
* This is ignored if the message is already linked to this document thread.
*
* @override
* @param {mail.model.Message} message
*/
addMessage: function (message) {
if (_.contains(this._messages, message)) {
return;
}
// update internal list of messages
this._messages.push(message);
this._messages = _.sortBy(this._messages, function (msg) {
+73
View File
@@ -1674,6 +1674,79 @@ QUnit.test('does not render and crash when destroyed before chat system is ready
def.resolve();
});
QUnit.test('chatter: do not duplicate messages on (un)star message', function (assert) {
assert.expect(4);
this.data.partner.records[0].message_ids = [1];
this.data['mail.message'].records = [{
author_id: ["1", "John Doe"],
body: "A message",
date: "2016-12-20 09:35:40",
id: 1,
is_note: false,
is_discussion: true,
is_notification: false,
is_starred: false,
model: 'partner',
res_id: 2,
}];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
services: this.services,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="foo"/>' +
'</sheet>' +
'<div class="oe_chatter">' +
'<field name="message_ids" widget="mail_thread" options="{\'display_log_button\': True}"/>' +
'</div>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (args.method === 'toggle_message_starred') {
var messageData = _.findWhere(
this.data['mail.message'].records,
{ id: args.args[0][0] }
);
messageData.is_starred = !messageData.is_starred;
// simulate notification received by mail_service from longpoll
var data = {
info: false,
message_ids: [messageData.id],
starred: messageData.is_starred,
type: 'toggle_star',
};
var notification = [[false, 'res.partner'], data];
form.call('bus_service', 'trigger', 'notification', [notification]);
return $.when();
}
return this._super(route, args);
},
session: {},
});
assert.strictEqual(form.$('.o_thread_message').length, 1,
"there should be a single message in the chatter");
assert.ok(form.$('.o_thread_message .o_thread_message_star.fa-star-o').length,
"message should not be starred");
// star message
form.$('.o_thread_message .o_thread_message_star').click();
assert.strictEqual(form.$('.o_thread_message').length, 1,
"there should still be a single message in the chatter after starring the message");
// unstar message
form.$('.o_thread_message .o_thread_message_star').click();
assert.strictEqual(form.$('.o_thread_message').length, 1,
"there should still be a single message in the chatter after unstarring the message");
//cleanup
form.destroy();
});
QUnit.module('FieldMany2ManyTagsEmail', {
beforeEach: function () {
this.data = {