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,6 +1,9 @@ // @flow -import type { ServerCommunityInfo } from 'lib/types/community-types.js'; +import type { + ServerCommunityInfo, + ServerCommunityInfoWithCommunityName, +} from 'lib/types/community-types.js'; import { dbQuery, SQL } from '../database/database.js'; import { Viewer } from '../session/viewer.js'; @@ -65,4 +68,28 @@ return communityInfo?.farcasterChannelID; } -export { fetchCommunityInfos, fetchCommunityFarcasterChannelTag }; +async function fetchAllCommunityInfosWithNames(): Promise< + $ReadOnlyArray, +> { + const query = SQL` + SELECT c.id, t.name as communityName, c.farcaster_channel_id as farcasterChannelID + FROM communities c + INNER JOIN threads t ON c.id = t.id + `; + + const [result] = await dbQuery(query); + + const communityInfos = result.map(row => ({ + id: row.id.toString(), + farcasterChannelID: row.farcasterChannelID, + communityName: row.communityName, + })); + + return communityInfos; +} + +export { + fetchCommunityInfos, + fetchCommunityFarcasterChannelTag, + fetchAllCommunityInfosWithNames, +}; 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 @@ -30,6 +30,11 @@ farcasterChannelID: t.maybe(t.String), }); +export type ServerCommunityInfoWithCommunityName = $ReadOnly<{ + ...ServerCommunityInfo, + +communityName: string, +}>; + export type FetchCommunityInfosResponse = { +communityInfos: $ReadOnlyArray, };