import { isOfficialChannel, OFFICIAL_SENDER_USER_ID, } from '@linktr.ee/messaging-taxonomy' import type { Channel } from 'stream-chat' type ChannelMembers = NonNullable['members'] type ChannelMember = ChannelMembers[string] /** * Resolves the member to display as the conversation's "other party". * * For a normal 1:1 channel this is the member that isn't the current user. The * official channel is special: its display identity is always the official * sender ("Linktree"), regardless of who is viewing. That matters because an * unverified sensitive linker reads the official channel as a guest whose * random Stream id isn't a member, so the "not me" heuristic would otherwise * fall back to the linker's own member and show their name instead of Linktree. */ export function resolveConversationParticipant( members: ChannelMembers | undefined, currentUserId: string | undefined, channelType: string | undefined ): ChannelMember | undefined { const memberList = Object.values(members || {}) if (isOfficialChannel(channelType)) { const officialSender = memberList.find( (member) => member.user?.id === OFFICIAL_SENDER_USER_ID ) if (officialSender) return officialSender } return memberList.find( (member) => member.user?.id && member.user.id !== currentUserId ) }