mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-05 00:14:18 +00:00
fix: keep unfolded messages readable when the conversation is read again after a send
This commit is contained in:
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user