ultisuite-client/lib/mail-settings/resolve-open-email.ts
2026-05-25 13:52:40 +02:00

40 lines
974 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Email } from "@/lib/email-data"
import {
buildThreadViewEmail,
isThreadHeadMessage,
} from "@/lib/mail-thread"
/** Résout lemail affiché dans laperçu. */
export function resolveOpenEmailView(
mailId: string,
allEmails: Email[],
conversationMode: boolean
): { email: Email; threadRoot: Email; isSingleMessageView: boolean } | null {
const byId = new Map(allEmails.map((e) => [e.id, e]))
const message = byId.get(mailId)
if (!message) return null
const threadRoot = buildThreadViewEmail(message, byId)
if (conversationMode && isThreadHeadMessage(message)) {
return {
email: threadRoot,
threadRoot,
isSingleMessageView: false,
}
}
if (conversationMode) {
return null
}
return {
email:
message.conversation === undefined
? message
: { ...message, conversation: undefined },
threadRoot,
isSingleMessageView: (message.threadMessageIds?.length ?? 1) > 1,
}
}