fix: keep unfolded messages readable when the conversation is read again after a send

This commit is contained in:
Linus Rath
2026-11-04 12:55:41 +01:00
parent c5eb55467d
commit c657c4c5ba
2 changed files with 19 additions and 1 deletions
+9
View File
@@ -61,4 +61,13 @@ describe('echoes of sent replies', () => {
expect(mergeEchoes([...server, { id: 'c' } as Email], [...server, echo]).map((e) => (e.sentEcho ? 'echo' : e.id))).toEqual(['a', 'b', 'c']);
expect(mergeEchoes(server, [...server, echo]).map((e) => (e.sentEcho ? 'echo' : e.id))).toEqual(['a', 'b', 'echo']);
});
it('keeps the body of a message already unfolded', () => {
const loaded = { id: 'a', keywords: {}, mailboxIds: { inbox: true }, bodyValues: { 1: { value: 'Hi' } } } as unknown as Email;
const listed = { id: 'a', keywords: { $seen: true }, mailboxIds: { archive: true } } as unknown as Email;
const [merged] = mergeEchoes([listed], [loaded]);
expect(merged.bodyValues).toEqual(loaded.bodyValues);
expect(merged.keywords).toEqual({ $seen: true });
expect(merged.mailboxIds).toEqual({ archive: true });
});
});
+10 -1
View File
@@ -97,6 +97,15 @@ export function addEcho(conversation: Email[], echo: Email): Email[] {
*/
export function mergeEchoes(server: Email[], shown: Email[]): Email[] {
const ids = new Set(server.map((e) => e.id));
const byId = new Map(shown.map((e) => [e.id, e]));
// The thread read carries list properties only: a message already unfolded
// keeps the body it loaded, with the server's flags and folders.
const merged = server.map((e) => {
const had = byId.get(e.id);
return had?.bodyValues && !e.bodyValues && !had.sentEcho
? { ...had, keywords: e.keywords, mailboxIds: e.mailboxIds }
: e;
});
const echoes = shown.filter((e) => e.sentEcho && !ids.has(e.id));
return echoes.length ? [...server, ...echoes] : server;
return echoes.length ? [...merged, ...echoes] : merged;
}