diff --git a/keyserver/src/responders/community-responders.js b/keyserver/src/responders/community-responders.js index 11210f27b..dc8fde021 100644 --- a/keyserver/src/responders/community-responders.js +++ b/keyserver/src/responders/community-responders.js @@ -1,21 +1,42 @@ // @flow -import type { FetchCommunityInfosResponse } from 'lib/types/community-types.js'; +import type { + FetchCommunityInfosResponse, + FetchAllCommunityInfosWithNamesResponse, +} from 'lib/types/community-types.js'; -import { fetchCommunityInfos } from '../fetchers/community-fetchers.js'; +import { + fetchCommunityInfos, + fetchAllCommunityInfosWithNames, +} from '../fetchers/community-fetchers.js'; import { Viewer } from '../session/viewer.js'; async function fetchCommunityInfosResponder( viewer: Viewer, ): Promise { const fetchedCommunities = await fetchCommunityInfos(viewer); const communityInfos = fetchedCommunities.map(community => ({ id: community.id, farcasterChannelID: community.farcasterChannelID, })); return { communityInfos }; } -export { fetchCommunityInfosResponder }; +async function fetchAllCommunityInfosWithNamesResponder( + viewer: Viewer, +): Promise { + if (!viewer.loggedIn) { + return { allCommunityInfosWithNames: [] }; + } + + const allCommunityInfosWithNames = await fetchAllCommunityInfosWithNames(); + + return { allCommunityInfosWithNames }; +} + +export { + fetchCommunityInfosResponder, + fetchAllCommunityInfosWithNamesResponder, +}; diff --git a/lib/types/community-types.js b/lib/types/community-types.js index 411bfdc07..bb0fabb93 100644 --- a/lib/types/community-types.js +++ b/lib/types/community-types.js @@ -1,74 +1,78 @@ // @flow import t, { type TInterface } from 'tcomb'; import { tID, tShape } from '../utils/validation-utils.js'; export type CommunityInfo = { +farcasterChannelID: ?string, }; export type CommunityInfos = { +[threadID: string]: CommunityInfo }; export type CommunityStore = { +communityInfos: CommunityInfos, }; export type AddCommunityPayload = { +id: string, +newCommunityInfo: CommunityInfo, }; export type ServerCommunityInfo = { +id: string, +farcasterChannelID: ?string, }; export const serverCommunityInfoValidator: TInterface = tShape({ id: tID, farcasterChannelID: t.maybe(t.String), }); export type ServerCommunityInfoWithCommunityName = $ReadOnly<{ ...ServerCommunityInfo, +communityName: string, }>; export type FetchCommunityInfosResponse = { +communityInfos: $ReadOnlyArray, }; +export type FetchAllCommunityInfosWithNamesResponse = { + +allCommunityInfosWithNames: $ReadOnlyArray, +}; + export type CreateOrUpdateFarcasterChannelTagRequest = { +commCommunityID: string, +farcasterChannelID: string, }; export type CreateOrUpdateFarcasterChannelTagResponse = { +commCommunityID: string, +farcasterChannelID: string, }; export type DeleteFarcasterChannelTagRequest = { +commCommunityID: string, +farcasterChannelID: string, }; export type DeleteFarcasterChannelTagPayload = { +commCommunityID: string, }; export type OngoingJoinCommunityData = { +resolve: () => mixed, +reject: () => mixed, +communityID: string, +threadID: ?string, }; export type JoinCommunityStep = | 'inactive' | 'add_keyserver' | 'auth_to_keyserver' | 'join_community' | 'join_thread' | 'finished';