[FIX] mail: fix inbox mark as read on single message
Clicking on mark as read on a given message would move all messages in inbox to history instead of only selected message(s). This commit fix that behaviour so that only the selected message(s) move(s) to history. task-2284543 closes odoo/odoo#54688 X-original-commit: 3304b89fc799b979b028aa4c7efe902b2f5276c1 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -4053,7 +4053,7 @@ QUnit.test('messages marked as read move to "History" mailbox', async function (
|
||||
}, {
|
||||
id: 51,
|
||||
is_read: false,
|
||||
mail_message_id: 1,
|
||||
mail_message_id: 2,
|
||||
res_partner_id: 3,
|
||||
}];
|
||||
this.data.initMessaging.needaction_inbox_counter = 2;
|
||||
@@ -4086,7 +4086,7 @@ QUnit.test('messages marked as read move to "History" mailbox', async function (
|
||||
this.env.messaging.history.localId
|
||||
}"]
|
||||
`).classList.contains('o-active'),
|
||||
"History mailbox should be active thread"
|
||||
"history mailbox should be active thread"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll(`.o_Discuss_thread .o_MessageList_empty`).length,
|
||||
@@ -4107,17 +4107,17 @@ QUnit.test('messages marked as read move to "History" mailbox', async function (
|
||||
this.env.messaging.inbox.localId
|
||||
}"]
|
||||
`).classList.contains('o-active'),
|
||||
"Inbox mailbox should be active thread"
|
||||
"inbox mailbox should be active thread"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll(`.o_Discuss_thread .o_MessageList_empty`).length,
|
||||
0,
|
||||
"Inbox mailbox should not be empty"
|
||||
"inbox mailbox should not be empty"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll(`.o_Discuss_thread .o_MessageList_message`).length,
|
||||
2,
|
||||
"Inbox mailbox should have 2 messages"
|
||||
"inbox mailbox should have 2 messages"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
@@ -4129,12 +4129,12 @@ QUnit.test('messages marked as read move to "History" mailbox', async function (
|
||||
this.env.messaging.inbox.localId
|
||||
}"]
|
||||
`).classList.contains('o-active'),
|
||||
"Inbox mailbox should still be active after mark as read"
|
||||
"inbox mailbox should still be active after mark as read"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll(`.o_Discuss_thread .o_MessageList_empty`).length,
|
||||
1,
|
||||
"Inbox mailbox should now be empty after mark as read"
|
||||
"inbox mailbox should now be empty after mark as read"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
@@ -4150,17 +4150,148 @@ QUnit.test('messages marked as read move to "History" mailbox', async function (
|
||||
this.env.messaging.history.localId
|
||||
}"]
|
||||
`).classList.contains('o-active'),
|
||||
"History mailbox should be active"
|
||||
"history mailbox should be active"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll(`.o_Discuss_thread .o_MessageList_empty`).length,
|
||||
0,
|
||||
"History mailbox should not be empty after mark as read"
|
||||
"history mailbox should not be empty after mark as read"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll(`.o_Discuss_thread .o_MessageList_message`).length,
|
||||
2,
|
||||
"History mailbox should have 2 messages"
|
||||
"history mailbox should have 2 messages"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('mark a single message as read should only move this message to "History" mailbox', async function (assert) {
|
||||
assert.expect(9);
|
||||
|
||||
this.data['mail.message'].records = [{
|
||||
author_id: [5, 'Demo User'],
|
||||
body: '<p>test 1</p>',
|
||||
id: 1,
|
||||
needaction: true,
|
||||
needaction_partner_ids: [3],
|
||||
}, {
|
||||
author_id: [6, 'Test User'],
|
||||
body: '<p>test 2</p>',
|
||||
id: 2,
|
||||
needaction: true,
|
||||
needaction_partner_ids: [3],
|
||||
}];
|
||||
this.data['mail.notification'].records = [{
|
||||
id: 50,
|
||||
is_read: false,
|
||||
mail_message_id: 1,
|
||||
res_partner_id: 3,
|
||||
}, {
|
||||
id: 51,
|
||||
is_read: false,
|
||||
mail_message_id: 2,
|
||||
res_partner_id: 3,
|
||||
}];
|
||||
this.data.initMessaging.needaction_inbox_counter = 2;
|
||||
await this.start({
|
||||
discuss: {
|
||||
params: {
|
||||
default_active_id: 'mail.box_history',
|
||||
},
|
||||
},
|
||||
env: {
|
||||
session: {
|
||||
name: 'Admin',
|
||||
partner_display_name: 'Your Company, Admin',
|
||||
partner_id: 3,
|
||||
uid: 2,
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.hasClass(
|
||||
document.querySelector(`
|
||||
.o_DiscussSidebar_item[data-thread-local-id="${
|
||||
this.env.messaging.history.localId
|
||||
}"]
|
||||
`),
|
||||
'o-active',
|
||||
"history mailbox should initially be the active thread"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_MessageList_empty',
|
||||
"history mailbox should initially be empty"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector(`
|
||||
.o_DiscussSidebar_item[data-thread-local-id="${
|
||||
this.env.messaging.inbox.localId
|
||||
}"]
|
||||
`).click()
|
||||
);
|
||||
assert.hasClass(
|
||||
document.querySelector(`
|
||||
.o_DiscussSidebar_item[data-thread-local-id="${
|
||||
this.env.messaging.inbox.localId
|
||||
}"]
|
||||
`),
|
||||
'o-active',
|
||||
"inbox mailbox should be active thread after clicking on it"
|
||||
);
|
||||
assert.containsN(
|
||||
document.body,
|
||||
'.o_Message',
|
||||
2,
|
||||
"inbox mailbox should have 2 messages"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector(`
|
||||
.o_Message[data-message-local-id="${
|
||||
this.env.models['mail.message'].find(message => message.id === 1).localId
|
||||
}"] .o_Message_commandMarkAsRead
|
||||
`).click()
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_Message',
|
||||
"inbox mailbox should have one less message after clicking mark as read"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
`.o_Message[data-message-local-id="${
|
||||
this.env.models['mail.message'].find(message => message.id === 2).localId
|
||||
}"]`,
|
||||
"message still in inbox should be the one not marked as read"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector(`
|
||||
.o_DiscussSidebar_item[data-thread-local-id="${
|
||||
this.env.messaging.history.localId
|
||||
}"]
|
||||
`).click()
|
||||
);
|
||||
assert.hasClass(
|
||||
document.querySelector(`
|
||||
.o_DiscussSidebar_item[data-thread-local-id="${
|
||||
this.env.messaging.history.localId
|
||||
}"]
|
||||
`),
|
||||
'o-active',
|
||||
"history mailbox should be active after clicking on it"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_Message',
|
||||
"history mailbox should have only 1 message after mark as read"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
`.o_Message[data-message-local-id="${
|
||||
this.env.models['mail.message'].find(message => message.id === 1).localId
|
||||
}"]`,
|
||||
"message moved in history should be the one marked as read"
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
+14
-6
@@ -530,12 +530,20 @@ function factory(dependencies) {
|
||||
// 1. move messages from inbox to history
|
||||
// AKU TODO: flag other caches to invalidate
|
||||
// task-2171873
|
||||
inboxMailbox.messages.map(message => {
|
||||
message.update({
|
||||
isNeedaction: false,
|
||||
isHistory: true,
|
||||
});
|
||||
});
|
||||
for (const message_id of message_ids) {
|
||||
// We need to ignore all not yet known messages because we don't want them
|
||||
// to be shown partially as they would be linked directly to mainCache
|
||||
// Furthermore, server should not send back all message_ids marked as read
|
||||
// but something like last read message_id or something like that.
|
||||
// (just imagine you mark 1000 messages as read ... )
|
||||
const message = this.env.models['mail.message'].find(m => m.id === message_id);
|
||||
if (message) {
|
||||
message.update({
|
||||
isNeedaction: false,
|
||||
isHistory: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 2. remove "needaction" from channels
|
||||
let channels;
|
||||
|
||||
Reference in New Issue
Block a user