fix: also display contact names stored in name.full #179

This commit is contained in:
Linus Rath
2026-04-11 20:15:49 +02:00
parent 88d87be685
commit 457400ceee
3 changed files with 19 additions and 8 deletions
+4 -2
View File
@@ -203,12 +203,14 @@ export interface ContactCard {
} }
export interface ContactName { export interface ContactName {
components: NameComponent[]; components?: NameComponent[];
isOrdered?: boolean; isOrdered?: boolean;
full?: string;
defaultSeparator?: string;
} }
export interface NameComponent { export interface NameComponent {
kind: 'given' | 'surname' | 'prefix' | 'suffix' | 'additional' | 'separator' | 'credential'; kind: 'given' | 'surname' | 'prefix' | 'suffix' | 'additional' | 'separator' | 'credential' | 'title' | 'middle' | 'given2' | 'surname2' | 'generation';
value: string; value: string;
} }
+1 -1
View File
@@ -564,7 +564,7 @@ function generateSingleVCard(contact: ContactCard): string {
const suffix = components.find(c => c.kind === "suffix")?.value || ""; const suffix = components.find(c => c.kind === "suffix")?.value || "";
const additional = components.find(c => c.kind === "additional")?.value || ""; const additional = components.find(c => c.kind === "additional")?.value || "";
const fn = [prefix, given, additional, surname, suffix].filter(Boolean).join(" "); const fn = [prefix, given, additional, surname, suffix].filter(Boolean).join(" ") || contact.name?.full || "";
if (fn) { if (fn) {
lines.push(`FN:${encodeValue(fn)}`); lines.push(`FN:${encodeValue(fn)}`);
lines.push(`N:${encodeValue(surname)};${encodeValue(given)};${encodeValue(additional)};${encodeValue(prefix)};${encodeValue(suffix)}`); lines.push(`N:${encodeValue(surname)};${encodeValue(given)};${encodeValue(additional)};${encodeValue(prefix)};${encodeValue(suffix)}`);
+14 -5
View File
@@ -5,16 +5,25 @@ import type { IJMAPClient } from '@/lib/jmap/client-interface';
import { generateUUID } from '@/lib/utils'; import { generateUUID } from '@/lib/utils';
export function getContactDisplayName(contact: ContactCard): string { export function getContactDisplayName(contact: ContactCard): string {
if (contact.name?.components) { if (contact.name) {
const given = contact.name.components.find(c => c.kind === 'given')?.value || ''; // Try given + surname from components first
const surname = contact.name.components.find(c => c.kind === 'surname')?.value || ''; if (contact.name.components && contact.name.components.length > 0) {
const full = [given, surname].filter(Boolean).join(' '); const given = contact.name.components.find(c => c.kind === 'given')?.value || '';
if (full) return full; const surname = contact.name.components.find(c => c.kind === 'surname')?.value || '';
const full = [given, surname].filter(Boolean).join(' ');
if (full) return full;
}
// Fall back to name.full (RFC 9553 — used by Stalwart and other JMAP servers)
if (contact.name.full) return contact.name.full;
} }
if (contact.nicknames) { if (contact.nicknames) {
const nick = Object.values(contact.nicknames)[0]; const nick = Object.values(contact.nicknames)[0];
if (nick?.name) return nick.name; if (nick?.name) return nick.name;
} }
if (contact.organizations) {
const org = Object.values(contact.organizations)[0];
if (org?.name) return org.name;
}
if (contact.emails) { if (contact.emails) {
const email = Object.values(contact.emails)[0]; const email = Object.values(contact.emails)[0];
if (email?.address) return email.address; if (email?.address) return email.address;