* implement avatar backend functionality * add avatar endpoints * typo * implement client side avatar upload and handling * fixes * Update go/internal/handler/handler.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update js/desktop/src/lib/avatar-image.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * bug in order * remove unused component * fix invalid migration * fix syntax errors --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type { Human } from '@/api/types';
|
||
import { getInitials } from '@/lib/utils';
|
||
|
||
export const REMOVED_MEMBER_LABEL = 'Removed member';
|
||
export const REMOVED_MEMBER_INITIALS = '–';
|
||
|
||
export interface HumanDisplay {
|
||
/** True when the human was found in the provided list. */
|
||
exists: boolean;
|
||
/** Short name for inline text (e.g. message sender). */
|
||
displayName: string;
|
||
/** Full email or fallback label for tooltips. */
|
||
email: string;
|
||
/** Initials for avatar fallback. */
|
||
initials: string;
|
||
/** Avatar object id, when the human has a profile picture set. */
|
||
avatarObjectId: string | null;
|
||
}
|
||
|
||
/**
|
||
* Resolve a human's display info by id, falling back consistently when the
|
||
* human has been removed from the network. Member content (particles, reactions,
|
||
* etc.) is retained after removal, so every render path needs a graceful fallback
|
||
* instead of leaking raw ids into the UI.
|
||
*/
|
||
export function resolveHumanDisplay(
|
||
humanId: string | null | undefined,
|
||
humans: Human[] | undefined,
|
||
): HumanDisplay {
|
||
const human = humanId ? humans?.find((h) => h.id === humanId) : undefined;
|
||
if (!human) {
|
||
return {
|
||
exists: false,
|
||
displayName: REMOVED_MEMBER_LABEL,
|
||
email: REMOVED_MEMBER_LABEL,
|
||
initials: REMOVED_MEMBER_INITIALS,
|
||
avatarObjectId: null,
|
||
};
|
||
}
|
||
return {
|
||
exists: true,
|
||
displayName: human.email_prefix,
|
||
email: human.email,
|
||
initials: getInitials(human.email),
|
||
avatarObjectId: human.avatar_object_id ?? null,
|
||
};
|
||
}
|