[FIX] mail: reorder direct message when opening a new one

Before this PR, newly created direct message would be added at the bottom of the
list instead of the top.
This PR fix the issues by sorting the direct messages when creating a new direct
message channel.

Task-3566728

closes odoo/odoo#139960

X-original-commit: 60cf880102615a524f2fa89c71be7f1b08d931d1
Signed-off-by: Didier Debondt (did) <did@odoo.com>
This commit is contained in:
Didier (did)
2023-10-31 10:33:49 +00:00
parent 34db3fd706
commit ceebd2e8d0
2 changed files with 42 additions and 1 deletions
@@ -546,11 +546,13 @@ export class ThreadService {
const data = await this.orm.call("discuss.channel", "channel_get", [], {
partners_to: [id],
});
return this.store.Thread.insert({
const thread = this.store.Thread.insert({
...data,
model: "discuss.channel",
type: "chat",
});
this.sortChannels();
return thread;
}
executeCommand(thread, command, body = "") {
@@ -1918,3 +1918,42 @@ QUnit.test("Notification settings: mute/unmute channel works correctly", async (
await click("[title='Notification Settings']");
await contains("span", { text: "Unmute Channel" });
});
QUnit.test("Newly created chat should be at the top of the direct message list", async () => {
const pyEnv = await startServer();
const [userId1, userId2] = pyEnv["res.users"].create([
{ name: "Jerry Golay" },
{ name: "Albert" }
]);
const [partnerId1] = pyEnv["res.partner"].create([
{
name: "Albert",
user_ids: [userId2],
},
{
name: "Jerry Golay",
user_ids: [userId1],
}
]);
pyEnv["discuss.channel"].create({
channel_member_ids: [
Command.create({
is_pinned: true,
last_interest_dt: "2021-01-01 10:00:00",
partner_id: pyEnv.currentPartnerId,
}),
Command.create({ partner_id: partnerId1 }),
],
channel_type: "chat",
});
const { openDiscuss } = await start();
await openDiscuss();
await click(".o-mail-DiscussSidebarCategory-add[title='Start a conversation']");
await insertText(".o-discuss-ChannelSelector input", "Jer");
await click(".o-discuss-ChannelSelector-suggestion");
await triggerHotkey("Enter");
await contains(".o-mail-DiscussSidebar-item", {
text: "Jerry Golay",
before: [".o-mail-DiscussSidebar-item", { text: "Albert" }]
});
});