diff options
| author | Sébastien Theys <seb@odoo.com> | 2021-01-28 10:55:58 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2021-01-28 10:55:58 +0000 |
| commit | fa398ea291a72fa7752d382f85e6ef2ce7ac4c70 (patch) | |
| tree | 2406dcb022d47409f8843ae03dbb1234398193bc /addons/mail/static/tests | |
| parent | 45544d024d5e4ad71285d70411b5109f4075b440 (diff) | |
[FIX] mail: make Inbox counters more reliable in mark as read flows
- Send the new Inbox counter when marking as read, to guarantee the JS has the
correct value (instead of having to guess it which was impossible when an
arbitrary domain was given to the method).
NOTE: Manual increment is kept on receiving a new Inbox message because that
one was reliable and it would have been more tricky to compute the new counter
for each target partner (mark as read is one user doing an action for himself,
whereas new message is from another user to potentially many different users).
Generic counter for threads is also not sent on every change for similar
reasons.
- Refresh Inbox automatically when some messages are marked as read and there
are more message on the server than currently loaded.
- Remove confusing (and impossible to maintain) counter on non-origin threads
(in particular channel followers). This behavior in JS was not consistent with
the server which always counted only origin thread (model/res_id).
task-2446302
closes odoo/odoo#65161
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/tests')
| -rw-r--r-- | addons/mail/static/tests/helpers/mock_server.js | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index e78ce39fd31..dc027c679f5 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -223,7 +223,8 @@ MockServer.include({ return this._mockMailMessageModerate(args); } if (args.model === 'mail.message' && args.method === 'set_message_done') { - return this._mockMailMessageSetMessageDone(args); + const ids = args.args[0]; + return this._mockMailMessageSetMessageDone(ids); } if (args.model === 'mail.message' && args.method === 'toggle_message_starred') { const ids = args.args[0]; @@ -389,10 +390,7 @@ MockServer.include({ const currentPartner = this._getRecords('res.partner', [['id', '=', this.currentPartnerId]])[0]; const currentPartnerFormat = this._mockResPartnerMailPartnerFormat(currentPartner.id); - const needaction_inbox_counter = this._getRecords('mail.notification', [ - ['res_partner_id', '=', this.currentPartnerId], - ['is_read', '=', false], - ]).length; + const needaction_inbox_counter = this._mockResPartnerGetNeedactionCount(); const mailFailures = this._mockMailMessageMessageFetchFailed(); @@ -1076,9 +1074,9 @@ MockServer.include({ ]; if (domain) { const messages = this._getRecords('mail.message', domain); - notifDomain.push( - ['mail_message_id', 'in', messages.map(messages => messages.id)] - ); + const ids = messages.map(messages => messages.id); + this._mockMailMessageSetMessageDone(ids); + return ids; } const notifications = this._getRecords('mail.notification', notifDomain); this._mockWrite('mail.notification', [ @@ -1104,7 +1102,7 @@ MockServer.include({ }, ]); } - const notificationData = { type: 'mark_as_read', message_ids: messageIds }; + const notificationData = { type: 'mark_as_read', message_ids: messageIds, needaction_inbox_counter: this._mockResPartnerGetNeedactionCount() }; const notification = [[false, 'res.partner', this.currentPartnerId], notificationData]; this._widget.call('bus_service', 'trigger', 'notification', [notification]); return messageIds; @@ -1307,10 +1305,9 @@ MockServer.include({ * messages have been marked as read, so that UI is updated. * * @private - * @param {Object} args + * @param {integer[]} ids */ - _mockMailMessageSetMessageDone(args) { - const ids = args.args[0]; + _mockMailMessageSetMessageDone(ids) { const messages = this._getRecords('mail.message', [['id', 'in', ids]]); const notifications = this._getRecords('mail.notification', [ @@ -1335,7 +1332,7 @@ MockServer.include({ ]); // NOTE server is sending grouped notifications per channel_ids but // this optimization is not needed here. - const data = { type: 'mark_as_read', message_ids: [message.id], channel_ids: message.channel_ids }; + const data = { type: 'mark_as_read', message_ids: [message.id], channel_ids: message.channel_ids, needaction_inbox_counter: this._mockResPartnerGetNeedactionCount() }; const busNotifications = [[[false, 'res.partner', this.currentPartnerId], data]]; this._widget.call('bus_service', 'trigger', 'notification', busNotifications); } @@ -1730,6 +1727,17 @@ MockServer.include({ return [mainMatchingPartners, extraMatchingPartners]; }, /** + * Simulates `get_needaction_count` on `res.partner`. + * + * @private + */ + _mockResPartnerGetNeedactionCount() { + return this._getRecords('mail.notification', [ + ['res_partner_id', '=', this.currentPartnerId], + ['is_read', '=', false], + ]).length; + }, + /** * Simulates `im_search` on `res.partner`. * * @private |
