[FIX] mail: mark as read only when accessing to chatter

Before this commit, the user could not receive any notification
from the chatter of a document when having Notification Management
set to "Handle with Odoo".

This problem occurs when the user opens (or has opened) the document.
Any messages received from the document are automatically marked
as read, so it removes the notification right after receiving it.

In order to no longer have this issue, the user had to reload all
pages that have opened this document.

This commit slightly changes the behaviour of the chatter, so that
it automatically marks it as read only when accessing the document,
but not when the document is open (or has been opened). Consequently,
if the user has opened the document and then receives a notification
from this document, it won't automatically mark it as read.

Task-ID 1895359

opw-1890556

closes odoo/odoo#28114
This commit is contained in:
Alexandre Kühn
2018-10-26 08:39:39 +00:00
parent b650dc7a21
commit 17bb0ca443
2 changed files with 106 additions and 1 deletions
+8 -1
View File
@@ -20,6 +20,9 @@ var ThreadField = AbstractField.extend({
*/
init: function () {
this._super.apply(this, arguments);
// Used to automatically mark document thread as read at the moment we
// access the document and render the thread.
this._markAsReadOnNextRender = false;
this._setDocumentThread();
},
/**
@@ -115,7 +118,10 @@ var ThreadField = AbstractField.extend({
self._threadWidget.render(self._documentThread, {
displayLoadMore: self._documentThread.getMessages().length < self._documentThread.getMessageIDs().length,
});
return self._documentThread.markAsRead();
if (self._markAsReadOnNextRender) {
self._markAsReadOnNextRender = false;
return self._documentThread.markAsRead();
}
});
}
},
@@ -157,6 +163,7 @@ var ThreadField = AbstractField.extend({
this._documentThread = null;
} else {
this._documentThread = this.call('mail_service', 'getOrAddDocumentThread', params);
this._markAsReadOnNextRender = true;
}
},
+98
View File
@@ -786,6 +786,104 @@ QUnit.test('chatter: post, receive and star messages', function (assert) {
});
});
QUnit.test('chatter: receive notif when document is open', function (assert) {
assert.expect(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"/>' +
'</div>' +
'</form>',
res_id: 2,
session: {
partner_id: 3,
},
});
var thread = form.call('mail_service', 'getDocumentThread', 'partner', 2);
assert.strictEqual(thread.getUnreadCounter(), 0,
"document thread should have no unread messages initially");
// simulate receiving a needaction message on this document thread
var needactionMessageData = {
id: 5,
author_id: [42, "Someone"],
body: 'important message',
channel_ids: [],
res_id: 2,
model: 'partner',
needaction: true,
needaction_partner_ids: [3],
};
this.data['mail.message'].records.push(needactionMessageData);
var notification = [[false, 'mail.channel', 1], needactionMessageData];
form.call('bus_service', 'trigger', 'notification', [notification]);
assert.strictEqual(thread.getUnreadCounter(), 1,
"document thread should now have one unread message");
form.destroy();
});
QUnit.test('chatter: access document with some notifs', function (assert) {
assert.expect(3);
// simulate received needaction message on this document thread
var needactionMessageData = {
id: 5,
author_id: [42, "Someone"],
body: 'important message',
channel_ids: [],
res_id: 2,
model: 'partner',
needaction: true,
needaction_partner_ids: [3],
};
this.data['mail.message'].records.push(needactionMessageData);
this.data['partner'].records[0].message_ids = [5];
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"/>' +
'</div>' +
'</form>',
res_id: 2,
session: {
partner_id: 3,
},
mockRPC: function (route, args) {
if (args.method === 'set_message_done') {
assert.step('set_message_done');
}
return this._super.apply(this, arguments);
},
});
assert.verifySteps(['set_message_done']);
var thread = form.call('mail_service', 'getDocumentThread', 'partner', 2);
assert.strictEqual(thread.getUnreadCounter(), 0,
"document thread should have no unread messages (marked as read)");
form.destroy();
});
QUnit.test('chatter: post a message and switch in edit mode', function (assert) {
assert.expect(5);