Page MenuHomePhabricator

D14181.diff
No OneTemporary

D14181.diff

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
@@ -6,6 +6,7 @@
} from 'lib/types/community-types.js';
import { fetchPrivilegedThreadInfos } from './thread-fetchers.js';
+import { viewerIsMemberOfThreads } from './thread-permission-fetchers.js';
import { dbQuery, SQL, mergeAndConditions } from '../database/database.js';
import { Viewer } from '../session/viewer.js';
@@ -93,13 +94,23 @@
const [result] = await dbQuery(query);
- const threadIDs = new Set(result.map(row => row.id.toString()));
+ const threadIDs = result.map(row => row.id.toString());
+
+ const membershipMap = await viewerIsMemberOfThreads(viewer, threadIDs);
+
+ const filteredResult = result.filter(
+ row => !!row.farcasterChannelID && !membershipMap.get(row.id.toString()),
+ );
+
+ const filteredThreadIDs = new Set(
+ filteredResult.map(row => row.id.toString()),
+ );
const threadInfosResult = await fetchPrivilegedThreadInfos(viewer, {
- threadIDs,
+ threadIDs: filteredThreadIDs,
});
- const communityInfos = result.map(
+ const communityInfos = filteredResult.map(
(row): ServerCommunityInfoWithCommunityName => ({
id: row.id.toString(),
farcasterChannelID: row.farcasterChannelID,
diff --git a/keyserver/src/fetchers/thread-permission-fetchers.js b/keyserver/src/fetchers/thread-permission-fetchers.js
--- a/keyserver/src/fetchers/thread-permission-fetchers.js
+++ b/keyserver/src/fetchers/thread-permission-fetchers.js
@@ -71,6 +71,19 @@
return checkThread(viewer, threadID, [{ check: 'is_member' }]);
}
+async function viewerIsMemberOfThreads(
+ viewer: Viewer,
+ threadIDs: $ReadOnlyArray<string>,
+): Promise<Map<string, boolean>> {
+ const validThreadIDs = await checkThreads(viewer, threadIDs, [
+ { check: 'is_member' },
+ ]);
+
+ return new Map(
+ threadIDs.map(threadID => [threadID, validThreadIDs.has(threadID)]),
+ );
+}
+
async function viewerHasPositiveRole(
viewer: Viewer,
threadID: string,
@@ -448,6 +461,7 @@
fetchThreadPermissionsBlob,
checkThreadPermission,
viewerIsMember,
+ viewerIsMemberOfThreads,
checkThreads,
getValidThreads,
checkThread,

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 5:05 AM (5 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2701645
Default Alt Text
D14181.diff (2 KB)

Event Timeline