Files
openconcho/packages/web/src/lib/peerDisplay.ts
Offending Commit 3de6832a5d feat(web): configurable peer display name
Human peers surface as raw ids (WhatsApp `…-lid`, UUIDs). Read an
optional `display_name` from peer metadata and prefer it over the id in
the peer header and breadcrumb, with the raw id kept as a sub-caption.
An inline edit on the header writes `display_name` via useUpdatePeer
(merging existing metadata); blank clears it. Falls back to the id when
unset.

Closes #32.
2026-05-28 15:56:42 -05:00

26 lines
818 B
TypeScript

/**
* Resolve a peer's friendly display name from its metadata, falling back to the
* raw peer id. Honcho peers are keyed by opaque ids (WhatsApp `…-lid`, UUIDs);
* a `display_name` metadata key lets the UI show something human-readable.
*/
export const DISPLAY_NAME_KEY = "display_name";
export function peerDisplayName(
metadata: Record<string, unknown> | null | undefined,
fallbackId: string,
): string {
const value = metadata?.[DISPLAY_NAME_KEY];
if (typeof value === "string" && value.trim().length > 0) {
return value.trim();
}
return fallbackId;
}
/** Whether a peer has an explicit display name distinct from its id. */
export function hasDisplayName(
metadata: Record<string, unknown> | null | undefined,
peerId: string,
): boolean {
return peerDisplayName(metadata, peerId) !== peerId;
}