ultisuite-client/lib/compose/identity-map.ts
R3D347HR4Y ad1370ea7e
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat: enhance configuration and add new demo layouts
- Introduced turbopack alias for canvas in next.config.mjs.
- Updated package.json scripts for development and branding tasks.
- Added new dependencies for Tiptap extensions.
- Implemented new demo layouts for agenda, contacts, drive, and mail applications.
- Enhanced globals.css for improved theming and splash screen animations.
- Added OAuth callback handling for drive mounts.
- Updated layout components to integrate new demo shells and improve structure.
2026-06-12 19:10:24 +02:00

75 lines
2.4 KiB
TypeScript

'use client'
import type { ApiIdentity, ApiMailSignature } from '@/lib/api/types'
import type { Identity } from '@/lib/compose-context'
import { insertSignatureHtml } from '@/components/gmail/compose/compose-shared'
import { getSignatureHtmlById } from '@/lib/stores/mail-signatures-store'
export function resolveIdentitySignatureHtml(
identity: ApiIdentity,
signaturesById?: Map<string, ApiMailSignature>
): string | null {
const fromLibrary = identity.default_signature_id
? (signaturesById?.get(identity.default_signature_id)?.html ??
getSignatureHtmlById(identity.default_signature_id))
: null
if (fromLibrary?.trim()) return fromLibrary
const inline = identity.signature_html?.trim()
return inline || null
}
export function apiIdentityToCompose(
identity: ApiIdentity,
signaturesById?: Map<string, ApiMailSignature>
): Identity {
const defaultSignatureId = identity.default_signature_id ?? null
const signatureHtml = resolveIdentitySignatureHtml(identity, signaturesById)
return {
id: identity.id,
accountId: identity.account_id,
name: identity.name,
email: identity.email,
defaultSignatureId,
signatureHtml,
isDefault: identity.is_default,
}
}
export function buildBodyWithSignature(bodyHtml: string, identity: Identity): string {
const html = identity.signatureHtml ?? null
if (!html?.trim()) return bodyHtml
return insertSignatureHtml(bodyHtml, html)
}
export function myEmailsFromIdentities(identities: Identity[]): Set<string> {
return new Set(identities.map((i) => i.email.trim().toLowerCase()).filter(Boolean))
}
export function defaultComposeIdentity(
identities: Identity[],
accountId?: string | null
): Identity | null {
if (accountId) {
const scoped = identities.filter((i) => i.accountId === accountId)
return scoped.find((i) => i.isDefault) ?? scoped[0] ?? null
}
return identities.find((i) => i.isDefault) ?? identities[0] ?? null
}
function composeIdentityDedupeKey(identity: Identity): string {
return `${identity.accountId ?? ""}:${identity.email.trim().toLowerCase()}`
}
/** Évite les doublons accountId+email (hydratation multi-comptes / re-fetch). */
export function dedupeComposeIdentities(identities: Identity[]): Identity[] {
const seen = new Set<string>()
const out: Identity[] = []
for (const identity of identities) {
const key = composeIdentityDedupeKey(identity)
if (seen.has(key)) continue
seen.add(key)
out.push(identity)
}
return out
}