[FIX] mail: incorrect message order on previous messages load

Discuss models use relationnal fields. Since [1], the implementation
of the `unshift` method changed for `many` fields. The new
implementation is incorrect: unshifting several records results in an
insertion on the inverse order which differs from the native
implementation.

This issue broke the loading of older messages in discuss: older
messages are inserted with the `unshift` method thus in the inverse
order.

[1]: https://github.com/odoo/odoo/pull/136539

closes odoo/odoo#140747

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
tsm-odoo
2023-11-06 12:32:00 +00:00
committed by Alexandre Kühn
parent dfbe78e9e0
commit bad8d093f5
3 changed files with 33 additions and 3 deletions
+2 -2
View File
@@ -215,8 +215,8 @@ export class RecordList extends Array {
}
/** @param {R[]} records */
unshift(...records) {
for (const val of records) {
const r = this._insert(val, (r3) => {
for (let i = records.length - 1; i >= 0; i--) {
const r = this._insert(records[i], (r3) => {
this.data.unshift(r3.localId);
r3.__uses__.add(this);
});
@@ -149,3 +149,32 @@ QUnit.test("Trusted insert on html field with { html: true }", async (assert) =>
assert.strictEqual(hello.body.toString(), "<p>hello</p>");
assert.strictEqual(world.body, "<p>world</p>");
});
QUnit.test("Unshift preserves order", async (assert) => {
(class Message extends Record {
static id = "id";
id;
}).register();
(class Thread extends Record {
static id = "name";
name;
messages = Record.many("Message");
}).register();
const store = await start();
const thread = store.Thread.insert({ name: "General" });
thread.messages.unshift({ id: 3 }, { id: 2 }, { id: 1 });
assert.deepEqual(
thread.messages.map((msg) => msg.id),
[3, 2, 1]
);
thread.messages.unshift({ id: 6 }, { id: 5 }, { id: 4 });
assert.deepEqual(
thread.messages.map((msg) => msg.id),
[6, 5, 4, 3, 2, 1]
);
thread.messages.unshift({ id: 7 });
assert.deepEqual(
thread.messages.map((msg) => msg.id),
[7, 6, 5, 4, 3, 2, 1]
);
});
@@ -49,7 +49,7 @@ QUnit.test("load more messages from channel (auto-load on scroll)", async () =>
});
for (let i = 0; i <= 60; i++) {
pyEnv["mail.message"].create({
body: "not empty",
body: i.toString(),
model: "discuss.channel",
res_id: channelId,
});
@@ -60,6 +60,7 @@ QUnit.test("load more messages from channel (auto-load on scroll)", async () =>
await contains(".o-mail-Thread", { scroll: "bottom" });
await scroll(".o-mail-Thread", 0);
await contains(".o-mail-Message", { count: 60 });
await contains(".o-mail-Message", { text: "30", after: [".o-mail-Message", { text: "29" }] });
});
QUnit.test("show message subject when subject is not the same as the thread name", async () => {