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,21 @@ return checkThread(viewer, threadID, [{ check: 'is_member' }]); } +async function viewerHasPositiveRole( + viewer: Viewer, + threadID: string, +): Promise { + const query = SQL` + SELECT role + FROM memberships + WHERE thread = ${threadID} AND user = ${viewer.userID} + `; + + const [queryResult] = await dbQuery(query); + const positiveRoles = queryResult.filter(row => Number(row.role) > 0); + return positiveRoles.length > 0; +} + type Check = | { +check: 'is_member' } | { +check: 'permission', +permission: ThreadPermission }; @@ -438,4 +453,5 @@ checkThread, checkIfThreadIsBlocked, validateCandidateMembers, + viewerHasPositiveRole, }; diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js --- a/keyserver/src/updaters/thread-updaters.js +++ b/keyserver/src/updaters/thread-updaters.js @@ -58,7 +58,7 @@ } from '../fetchers/thread-fetchers.js'; import { checkThreadPermission, - viewerIsMember as fetchViewerIsMember, + viewerHasPositiveRole as fetchViewerHasPositiveRole, checkThread, validateCandidateMembers, } from '../fetchers/thread-permission-fetchers.js'; @@ -858,7 +858,7 @@ const [isMember, hasPermission, communityFarcasterChannelTag] = await Promise.all([ - fetchViewerIsMember(viewer, request.threadID), + fetchViewerHasPositiveRole(viewer, request.threadID), permissionPromise, communityFarcasterChannelTagPromise, ]);