Page MenuHomePhabricator

D11955.id40040.diff
No OneTemporary

D11955.id40040.diff

diff --git a/keyserver/src/fetchers/community-fetchers.js b/keyserver/src/fetchers/community-fetchers.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/fetchers/community-fetchers.js
@@ -0,0 +1,41 @@
+// @flow
+
+import type { CommunityInfo } 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,
+ +blobHolder: ?string,
+}>;
+
+async function fetchCommunityInfos(
+ viewer: Viewer,
+): Promise<$ReadOnlyArray<ServerCommunityInfoWithHolder>> {
+ if (!viewer) {
+ return [];
+ }
+
+ const query = SQL`
+ SELECT c.id, c.farcaster_channel_id as farcasterChannelID,
+ c.blob_holder as blobHolder
+ FROM communities c
+ INNER JOIN memberships m
+ ON c.id = m.thread AND m.user = ${viewer.userID}
+ WHERE m.role > 0
+ `;
+
+ const [result] = await dbQuery(query);
+
+ const communityInfos = result.map(row => ({
+ id: row.id.toString(),
+ farcasterChannelID: row.farcasterChannelID,
+ blobHolder: row.blobHolder,
+ }));
+
+ return communityInfos;
+}
+
+export { fetchCommunityInfos };

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 12:03 PM (21 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2524032
Default Alt Text
D11955.id40040.diff (1 KB)

Event Timeline