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 @@ -13,7 +13,7 @@ async function fetchCommunityInfos( viewer: Viewer, ): Promise<$ReadOnlyArray> { - if (!viewer) { + if (!viewer.loggedIn) { return []; } diff --git a/keyserver/src/responders/redux-state-responders.js b/keyserver/src/responders/redux-state-responders.js --- a/keyserver/src/responders/redux-state-responders.js +++ b/keyserver/src/responders/redux-state-responders.js @@ -15,6 +15,7 @@ createPendingThread, } from 'lib/shared/thread-utils.js'; import { canUseDatabaseOnWeb } from 'lib/shared/web-database.js'; +import type { CommunityInfo } from 'lib/types/community-types'; import { defaultCalendarFilters } from 'lib/types/filter-types.js'; import { type CommunityLinks, @@ -39,6 +40,7 @@ } from 'web/types/redux-types.js'; import { navInfoFromURL } from 'web/url-utils.js'; +import { fetchCommunityInfos } from '../fetchers/community-fetchers.js'; import { fetchEntryInfos } from '../fetchers/entry-fetchers.js'; import { fetchPrimaryInviteLinks } from '../fetchers/link-fetchers.js'; import { fetchMessageInfos } from '../fetchers/message-fetchers.js'; @@ -333,6 +335,23 @@ }; })(); + const communityStorePromise = (async () => { + const serverCommunityInfos = await fetchCommunityInfos(viewer); + + const communityInfos: { [string]: CommunityInfo } = {}; + + for (const serverCommunityInfo of serverCommunityInfos) { + const communityInfo: CommunityInfo = { + farcasterChannelID: serverCommunityInfo.farcasterChannelID, + }; + communityInfos[serverCommunityInfo.id] = communityInfo; + } + + return { + communityInfos, + }; + })(); + const keyserverInfoPromise = (async () => { const { sessionID, updatesCurrentAsOf } = await promiseAll({ sessionID: sessionIDPromise, @@ -356,6 +375,7 @@ pushApiPublicKey: pushApiPublicKeyPromise, inviteLinksStore: inviteLinksStorePromise, keyserverInfo: keyserverInfoPromise, + communityStore: communityStorePromise, }); return initialReduxState; 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 @@ -8,12 +8,22 @@ +farcasterChannelID: ?string, }; +export const communityInfoValidator: TInterface = + tShape({ + farcasterChannelID: t.maybe(t.String), + }); + export type CommunityInfos = { +[threadID: string]: CommunityInfo }; export type CommunityStore = { +communityInfos: CommunityInfos, }; +export const communityStoreValidator: TInterface = + tShape({ + communityInfos: t.dict(tID, communityInfoValidator), + }); + export type AddCommunityPayload = { +id: string, +newCommunityInfo: CommunityInfo, 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 @@ -195,6 +195,7 @@ +pushApiPublicKey: ?string, +inviteLinksStore: InviteLinksStore, +keyserverInfo: WebInitialKeyserverInfo, + +communityStore: CommunityStore, }; export type ServerWebInitialReduxStateResponse = { +navInfo: WebNavInfo, @@ -206,6 +207,7 @@ +pushApiPublicKey: ?string, +inviteLinksStore: InviteLinksStore, +keyserverInfo: WebInitialKeyserverInfo, + +communityStore: CommunityStore, }; export type WebInitialKeyserverInfo = { +sessionID: ?string, diff --git a/lib/types/validators/redux-state-validators.js b/lib/types/validators/redux-state-validators.js --- a/lib/types/validators/redux-state-validators.js +++ b/lib/types/validators/redux-state-validators.js @@ -4,6 +4,7 @@ import { mixedRawThreadInfoValidator } from '../../permissions/minimally-encoded-raw-thread-info-validators.js'; import { tShape, tID } from '../../utils/validation-utils.js'; +import { communityStoreValidator } from '../community-types.js'; import { entryStoreValidator } from '../entry-types.js'; import { inviteLinksStoreValidator } from '../link-types.js'; import { messageStoreValidator } from '../message-types.js'; @@ -36,4 +37,5 @@ pushApiPublicKey: t.maybe(t.String), inviteLinksStore: inviteLinksStoreValidator, keyserverInfo: initialKeyserverInfoValidator, + communityStore: communityStoreValidator, }); diff --git a/web/redux/action-types.js b/web/redux/action-types.js --- a/web/redux/action-types.js +++ b/web/redux/action-types.js @@ -99,6 +99,9 @@ links: {}, }; let keyserverInfos: { [keyserverID: string]: WebInitialKeyserverInfo } = {}; + const communityStore = { + communityInfos: {}, + }; for (const keyserverID in responses) { entryStore.daysToEntries = { @@ -141,6 +144,11 @@ ...keyserverInfos, [keyserverID]: responses[keyserverID].keyserverInfo, }; + + communityStore.communityInfos = { + ...communityStore.communityInfos, + ...responses[keyserverID].communityStore.communityInfos, + }; } return { @@ -158,6 +166,7 @@ pushApiPublicKey, inviteLinksStore, keyserverInfos, + communityStore, }; }; diff --git a/web/types/redux-types.js b/web/types/redux-types.js --- a/web/types/redux-types.js +++ b/web/types/redux-types.js @@ -1,5 +1,6 @@ // @flow +import type { CommunityStore } from 'lib/types/community-types.js'; import type { EntryStore, CalendarQuery } from 'lib/types/entry-types.js'; import type { InviteLinksStore } from 'lib/types/link-types.js'; import type { MessageStore } from 'lib/types/message-types.js'; @@ -21,6 +22,7 @@ +dataLoaded: boolean, +actualizedCalendarQuery: CalendarQuery, +keyserverInfos: { +[keyserverID: string]: WebInitialKeyserverInfo }, + +communityStore: CommunityStore, }; export type InitialReduxStateActionPayload = $ReadOnly<{