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 @@ -5,8 +5,11 @@ ServerCommunityInfoWithCommunityName, } from 'lib/types/community-types.js'; +import { fetchThreadInfos } from './thread-fetchers.js'; import { dbQuery, SQL } from '../database/database.js'; +import { createScriptViewer } from '../session/scripts.js'; import { Viewer } from '../session/viewer.js'; +import { thisKeyserverAdmin } from '../user/identity.js'; type ServerCommunityInfoWithHolder = $ReadOnly<{ ...ServerCommunityInfo, @@ -78,12 +81,24 @@ INNER JOIN threads t ON c.id = t.id `; - const [result] = await dbQuery(query); + const [[result], admin] = await Promise.all([ + dbQuery(query), + thisKeyserverAdmin(), + ]); + + const threadIDs = new Set(result.map(row => row.id.toString())); + + const adminViewer = createScriptViewer(admin.id); + + const threadInfosResult = await fetchThreadInfos(adminViewer, { + threadIDs, + }); const communityInfos = result.map(row => ({ id: row.id.toString(), farcasterChannelID: row.farcasterChannelID, communityName: row.communityName, + threadInfo: threadInfosResult.threadInfos[row.id.toString()] ?? null, })); return communityInfos; diff --git a/keyserver/src/responders/community-responders.js b/keyserver/src/responders/community-responders.js --- a/keyserver/src/responders/community-responders.js +++ b/keyserver/src/responders/community-responders.js @@ -2,7 +2,7 @@ import type { FetchCommunityInfosResponse, - FetchAllCommunityInfosWithNamesResponse, + ServerFetchAllCommunityInfosWithNamesResponse, } from 'lib/types/community-types.js'; import { @@ -26,7 +26,7 @@ async function fetchAllCommunityInfosWithNamesResponder( viewer: Viewer, -): Promise { +): Promise { if (!viewer.loggedIn) { return { allCommunityInfosWithNames: [] }; } 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 @@ -7,7 +7,7 @@ import type { ServerCommunityInfo, FetchCommunityInfosResponse, - FetchAllCommunityInfosWithNamesResponse, + ClientFetchAllCommunityInfosWithNamesResponse, CreateOrUpdateFarcasterChannelTagRequest, CreateOrUpdateFarcasterChannelTagResponse, DeleteFarcasterChannelTagRequest, @@ -69,7 +69,7 @@ const fetchAllCommunityInfosWithNames = ( callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, - ): (() => Promise) => + ): (() => Promise) => () => callSingleKeyserverEndpoint('fetch_all_community_infos_with_names'); const createOrUpdateFarcasterChannelTagActionTypes = Object.freeze({ 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 @@ -3,8 +3,13 @@ import t, { type TInterface } from 'tcomb'; import type { RawMessageInfo } from './message-types.js'; -import type { ChangeThreadSettingsResult } from './thread-types.js'; +import type { ThinRawThreadInfo } from './minimally-encoded-thread-permissions-types.js'; +import type { + ChangeThreadSettingsResult, + LegacyThinRawThreadInfo, +} from './thread-types.js'; import type { ServerUpdateInfo } from './update-types.js'; +import { mixedRawThreadInfoValidator } from '../permissions/minimally-encoded-raw-thread-info-validators.js'; import { tID, tShape } from '../utils/validation-utils.js'; export type CommunityInfo = { @@ -36,6 +41,13 @@ export type ServerCommunityInfoWithCommunityName = $ReadOnly<{ ...ServerCommunityInfo, +communityName: string, + +threadInfo: LegacyThinRawThreadInfo | ThinRawThreadInfo | null, +}>; + +export type ClientCommunityInfoWithCommunityName = $ReadOnly<{ + ...ServerCommunityInfo, + +communityName: string, + +threadInfo: ?ThinRawThreadInfo, }>; export const serverCommunityInfoWithCommunityNameValidator: TInterface = @@ -43,16 +55,21 @@ id: tID, farcasterChannelID: t.maybe(t.String), communityName: t.String, + threadInfo: t.maybe(mixedRawThreadInfoValidator), }); export type FetchCommunityInfosResponse = { +communityInfos: $ReadOnlyArray, }; -export type FetchAllCommunityInfosWithNamesResponse = { +export type ServerFetchAllCommunityInfosWithNamesResponse = { +allCommunityInfosWithNames: $ReadOnlyArray, }; +export type ClientFetchAllCommunityInfosWithNamesResponse = { + +allCommunityInfosWithNames: $ReadOnlyArray, +}; + export type CreateOrUpdateFarcasterChannelTagRequest = { +commCommunityID: string, +farcasterChannelID: string, 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 @@ -34,7 +34,7 @@ CommunityStore, AddCommunityPayload, FetchCommunityInfosResponse, - FetchAllCommunityInfosWithNamesResponse, + ClientFetchAllCommunityInfosWithNamesResponse, CreateOrUpdateFarcasterChannelTagResponse, DeleteFarcasterChannelTagPayload, } from './community-types.js'; @@ -1487,7 +1487,7 @@ } | { +type: 'FETCH_ALL_COMMUNITY_INFOS_WITH_NAMES_SUCCESS', - +payload: FetchAllCommunityInfosWithNamesResponse, + +payload: ClientFetchAllCommunityInfosWithNamesResponse, +loadingInfo: LoadingInfo, } | { diff --git a/lib/types/validators/community-validators.js b/lib/types/validators/community-validators.js --- a/lib/types/validators/community-validators.js +++ b/lib/types/validators/community-validators.js @@ -7,7 +7,7 @@ serverCommunityInfoValidator, serverCommunityInfoWithCommunityNameValidator, type FetchCommunityInfosResponse, - type FetchAllCommunityInfosWithNamesResponse, + type ServerFetchAllCommunityInfosWithNamesResponse, } from '../community-types.js'; const fetchCommunityInfosResponseValidator: TInterface = @@ -15,7 +15,7 @@ communityInfos: t.list(serverCommunityInfoValidator), }); -const fetchAllCommunityInfosWithNamesResponseValidator: TInterface = +const fetchAllCommunityInfosWithNamesResponseValidator: TInterface = tShape({ allCommunityInfosWithNames: t.list( serverCommunityInfoWithCommunityNameValidator,