diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js --- a/lib/shared/avatar-utils.js +++ b/lib/shared/avatar-utils.js @@ -9,7 +9,10 @@ import { threadOtherMembers } from './thread-utils.js'; import genesis from '../facts/genesis.js'; import { useENSAvatar } from '../hooks/ens-cache.js'; -import { useFarcasterUserAvatarURL } from '../hooks/fc-cache.js'; +import { + useFarcasterUserAvatarURL, + useFarcasterChannelAvatarURL, +} from '../hooks/fc-cache.js'; import type { ClientAvatar, ClientEmojiAvatar, @@ -319,9 +322,11 @@ return getDefaultAvatar(thread.id, thread.color); } +type UsernameAndFID = { +username?: ?string, +farcasterID?: ?string, ... }; + function useResolvedUserAvatar( userAvatarInfo: ClientAvatar, - usernameAndFID: ?{ +username?: ?string, +farcasterID?: ?string, ... }, + usernameAndFID: ?UsernameAndFID, ): ResolvedClientAvatar { const ethAddress = React.useMemo( () => getETHAddressForUserInfo(usernameAndFID), @@ -338,12 +343,14 @@ return userAvatarInfo; } - if (ensAvatarURI) { + if (ensAvatarURI && userAvatarInfo.type === 'ens') { return { type: 'image', uri: ensAvatarURI, }; - } else if (farcasterAvatarURL) { + } + + if (farcasterAvatarURL && userAvatarInfo.type === 'farcaster') { return { type: 'image', uri: farcasterAvatarURL, @@ -356,14 +363,25 @@ return resolvedAvatar; } +type UsernameFIDAndChannel = { + ...UsernameAndFID, + +fcChannelID?: ?string, + ... +}; + function useResolvedThreadAvatar( threadAvatarInfo: ClientAvatar, - displayUser: ?{ +username?: ?string, +farcasterID?: ?string, ... }, + usernameFIDAndChannel: ?UsernameFIDAndChannel, ): ResolvedClientAvatar { - const resolvedUserAvatar = useResolvedUserAvatar( - threadAvatarInfo, - displayUser, - ); + const username = usernameFIDAndChannel?.username; + const farcasterID = usernameFIDAndChannel?.farcasterID; + const fcChannelID = usernameFIDAndChannel?.fcChannelID; + + const resolvedUserAvatar = useResolvedUserAvatar(threadAvatarInfo, { + username, + farcasterID, + }); + const farcasterAvatarURL = useFarcasterChannelAvatarURL(fcChannelID); if ( threadAvatarInfo.type !== 'ens' && @@ -372,7 +390,24 @@ return threadAvatarInfo; } - return resolvedUserAvatar; + // If `usernameFIDAndChannel` contains information about the display user AND + // a Farcaster channel ID, the former should supersede the latter + if (username || farcasterID) { + return resolvedUserAvatar; + } + + if (farcasterAvatarURL) { + return { + type: 'image', + uri: farcasterAvatarURL, + }; + } + + return { + type: 'emoji', + color: selectedThreadColors[4], + emoji: '🙂', + }; } export {