diff --git a/lib/actions/community-actions.js b/lib/actions/community-actions.js --- a/lib/actions/community-actions.js +++ b/lib/actions/community-actions.js @@ -4,6 +4,8 @@ import { useKeyserverCall } from '../keyserver-conn/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js'; import type { + ServerCommunityInfo, + FetchCommunityInfosResponse, CreateOrUpdateFarcasterChannelTagRequest, CreateOrUpdateFarcasterChannelTagResponse, DeleteFarcasterChannelTagRequest, @@ -17,6 +19,46 @@ const addCommunityActionType = 'ADD_COMMUNITY'; +const fetchCommunityInfosActionTypes = Object.freeze({ + started: 'FETCH_COMMUNITY_INFOS_STARTED', + success: 'FETCH_COMMUNITY_INFOS_SUCCESS', + failed: 'FETCH_COMMUNITY_INFOS_FAILED', +}); + +const fetchCommunityInfos = + ( + callKeyserverEndpoint: CallKeyserverEndpoint, + allKeyserverIDs: $ReadOnlyArray, + ): (() => Promise) => + async () => { + const requests: { [string]: void } = {}; + + for (const keyserverID of allKeyserverIDs) { + requests[keyserverID] = undefined; + } + + const responses = await callKeyserverEndpoint( + 'fetch_community_infos', + requests, + ); + + let communityInfos: $ReadOnlyArray = []; + + for (const keyserverID in responses) { + communityInfos = communityInfos.concat( + responses[keyserverID].communityInfos, + ); + } + + return { + communityInfos, + }; + }; + +function useFetchCommunityInfos(): () => Promise { + return useKeyserverCall(fetchCommunityInfos); +} + const createOrUpdateFarcasterChannelTagActionTypes = Object.freeze({ started: 'CREATE_OR_UPDATE_FARCASTER_CHANNEL_TAG_STARTED', success: 'CREATE_OR_UPDATE_FARCASTER_CHANNEL_TAG_SUCCESS', @@ -99,6 +141,8 @@ updateChatCommunityFilter, clearChatCommunityFilter, addCommunityActionType, + fetchCommunityInfosActionTypes, + useFetchCommunityInfos, createOrUpdateFarcasterChannelTagActionTypes, useCreateOrUpdateFarcasterChannelTag, deleteFarcasterChannelTagActionTypes, diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -28,6 +28,7 @@ import type { CommunityStore, AddCommunityPayload, + FetchCommunityInfosResponse, CreateOrUpdateFarcasterChannelTagResponse, DeleteFarcasterChannelTagPayload, } from './community-types.js'; @@ -1402,6 +1403,22 @@ +type: 'OPS_PROCESSING_FINISHED_ACTION_TYPE', +payload?: void, } + | { + +type: 'FETCH_COMMUNITY_INFOS_STARTED', + +loadingInfo?: LoadingInfo, + +payload?: void, + } + | { + +type: 'FETCH_COMMUNITY_INFOS_SUCCESS', + +payload: FetchCommunityInfosResponse, + +loadingInfo: LoadingInfo, + } + | { + +type: 'FETCH_COMMUNITY_INFOS_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, + } | { +type: 'CREATE_OR_UPDATE_FARCASTER_CHANNEL_TAG_STARTED', +loadingInfo?: LoadingInfo,