diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js --- a/keyserver/src/endpoints.js +++ b/keyserver/src/endpoints.js @@ -70,6 +70,10 @@ setThreadUnreadStatusValidator, updateActivityResponderInputValidator, } from './responders/activity-responders.js'; +import { + fetchCommunityInfosResponder, + fetchCommunityInfosResponseValidator, +} from './responders/community-responders.js'; import { deviceTokenUpdateResponder, deviceTokenUpdateRequestInputValidator, @@ -592,6 +596,12 @@ versionResponseValidator, [], ), + fetch_community_infos: createJSONResponder( + fetchCommunityInfosResponder, + ignoredArgumentValidator, + fetchCommunityInfosResponseValidator, + baseLegalPolicies, + ), create_or_update_farcaster_channel_tag: createJSONResponder( createOrUpdateFarcasterChannelTagResponder, createOrUpdateFarcasterChannelTagInputValidator, diff --git a/keyserver/src/fetchers/community-fetchers.js b/keyserver/src/fetchers/community-fetchers.js --- a/keyserver/src/fetchers/community-fetchers.js +++ b/keyserver/src/fetchers/community-fetchers.js @@ -1,13 +1,12 @@ // @flow -import type { CommunityInfo } from 'lib/types/community-types.js'; +import type { ServerCommunityInfo } from 'lib/types/community-types.js'; import { dbQuery, SQL } from '../database/database.js'; import { Viewer } from '../session/viewer.js'; type ServerCommunityInfoWithHolder = $ReadOnly<{ - ...CommunityInfo, - +id: string, + ...ServerCommunityInfo, +blobHolder: ?string, }>; diff --git a/keyserver/src/responders/community-responders.js b/keyserver/src/responders/community-responders.js new file mode 100644 --- /dev/null +++ b/keyserver/src/responders/community-responders.js @@ -0,0 +1,32 @@ +// @flow + +import t, { type TInterface } from 'tcomb'; + +import { + serverCommunityInfoValidator, + type FetchCommunityInfosResponse, +} from 'lib/types/community-types.js'; +import { tShape } from 'lib/utils/validation-utils.js'; + +import { fetchCommunityInfos } from '../fetchers/community-fetchers.js'; +import { Viewer } from '../session/viewer.js'; + +const fetchCommunityInfosResponseValidator: TInterface = + tShape({ + communityInfos: t.list(serverCommunityInfoValidator), + }); + +async function fetchCommunityInfosResponder( + viewer: Viewer, +): Promise { + const communitiesWithHolder = await fetchCommunityInfos(viewer); + + const communityInfos = communitiesWithHolder.map(community => ({ + id: community.id, + farcasterChannelID: community.farcasterChannelID, + })); + + return { communityInfos }; +} + +export { fetchCommunityInfosResponseValidator, fetchCommunityInfosResponder }; diff --git a/lib/types/community-types.js b/lib/types/community-types.js --- a/lib/types/community-types.js +++ b/lib/types/community-types.js @@ -1,5 +1,9 @@ // @flow +import t, { type TInterface } from 'tcomb'; + +import { tID, tShape } from '../utils/validation-utils.js'; + export type CommunityInfo = { +farcasterChannelID: ?string, }; @@ -15,6 +19,21 @@ +newCommunityInfo: CommunityInfo, }; +export type ServerCommunityInfo = { + +id: string, + +farcasterChannelID: ?string, +}; + +export const serverCommunityInfoValidator: TInterface = + tShape({ + id: tID, + farcasterChannelID: t.maybe(t.String), + }); + +export type FetchCommunityInfosResponse = { + +communityInfos: $ReadOnlyArray, +}; + export type CreateOrUpdateFarcasterChannelTagRequest = { +commCommunityID: string, +farcasterChannelID: string, diff --git a/lib/types/endpoints.js b/lib/types/endpoints.js --- a/lib/types/endpoints.js +++ b/lib/types/endpoints.js @@ -112,6 +112,7 @@ SEARCH_MESSAGES: 'search_messages', GET_OLM_SESSION_INITIALIZATION_DATA: 'get_olm_session_initialization_data', VERSION: 'version', + FETCH_COMMUNITY_INFOS: 'fetch_community_infos', CREATE_OR_UPDATE_FARCASTER_CHANNEL_TAG: 'create_or_update_farcaster_channel_tag', DELETE_FARCASTER_CHANNEL_TAG: 'delete_farcaster_channel_tag',