diff --git a/lib/shared/threads/protocols/farcaster-thread-protocol.js b/lib/shared/threads/protocols/farcaster-thread-protocol.js --- a/lib/shared/threads/protocols/farcaster-thread-protocol.js +++ b/lib/shared/threads/protocols/farcaster-thread-protocol.js @@ -13,14 +13,18 @@ type SendMultimediaMessagePayload, } from '../../../types/message-types.js'; import type { + FarcasterRawThreadInfo, MemberInfoSansPermissions, RawThreadInfo, + RoleInfo, + ThreadCurrentUserInfo, } from '../../../types/minimally-encoded-thread-permissions-types.js'; import type { SubscriptionUpdateResult } from '../../../types/subscription-types.js'; import type { ThreadType } from '../../../types/thread-types-enum.js'; import { assertFarcasterThreadType } from '../../../types/thread-types-enum.js'; import type { ChangeThreadSettingsPayload, + ClientDBThreadInfo, ThreadJoinPayload, } from '../../../types/thread-types.js'; import { farcasterThreadIDRegExp } from '../../../utils/validation-utils.js'; @@ -82,8 +86,43 @@ throw new Error('leaveThread method is not yet implemented'); }, - convertClientDBThreadInfo: (): RawThreadInfo => { - throw new Error('convertClientDBThreadInfo method is not yet implemented'); + convertClientDBThreadInfo: ( + clientDBThreadInfo: ClientDBThreadInfo, + members: $ReadOnlyArray, + roles: { +[id: string]: RoleInfo }, + currentUser: ThreadCurrentUserInfo, + ) => { + const farcasterThreadType = assertFarcasterThreadType( + clientDBThreadInfo.type, + ); + + let rawThreadInfo: FarcasterRawThreadInfo = { + farcaster: true, + id: clientDBThreadInfo.id, + type: farcasterThreadType, + name: clientDBThreadInfo.name, + description: clientDBThreadInfo.description, + color: clientDBThreadInfo.color, + creationTime: Number(clientDBThreadInfo.creationTime), + parentThreadID: clientDBThreadInfo.parentThreadID, + containingThreadID: clientDBThreadInfo.containingThreadID, + community: clientDBThreadInfo.community, + members, + roles, + currentUser, + repliesCount: clientDBThreadInfo.repliesCount, + pinnedCount: clientDBThreadInfo.pinnedCount, + minimallyEncoded: true, + }; + + if (clientDBThreadInfo.avatar) { + rawThreadInfo = { + ...rawThreadInfo, + avatar: JSON.parse(clientDBThreadInfo.avatar), + }; + } + + return rawThreadInfo; }, fetchMessages: async (): Promise => {