Files
im_webapp/web/src/features/messages/chat-list.ts
T

21 lines
707 B
TypeScript

export interface FriendAvatarSource {
user_id: string;
topic?: string;
avatar_file_id?: string;
}
/**
* P2P contacts are keyed by their `p2p...` topic after the first subscription,
* while the friends API identifies the same person with a `usr...` user ID.
* Keep both aliases so avatars work during both the initial and established
* conversation states.
*/
export function friendAvatarLookup(friends: FriendAvatarSource[] = []) {
const avatars = new Map<string, string | undefined>();
for (const friend of friends) {
if (friend.user_id) avatars.set(friend.user_id, friend.avatar_file_id);
if (friend.topic) avatars.set(friend.topic, friend.avatar_file_id);
}
return avatars;
}