diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -153,28 +153,37 @@ return permissionLookup(threadInfo.currentUser.permissions, permission); } -function useThreadHasPermission( - threadInfo: ?ThreadInfo, +function useThreadsWithPermission( + threadInfos: $ReadOnlyArray, permission: ThreadPermission, -): boolean { +): $ReadOnlyArray { const loggedInUserInfo = useLoggedInUserInfo(); const userInfos = useSelector(state => state.userStore.userInfos); return React.useMemo(() => { - if (!threadInfo) { - return false; - } - - const permissions = threadFrozenDueToBlock( - threadInfo, - loggedInUserInfo?.id, - userInfos, - ) - ? filterOutDisabledPermissions(threadInfo.currentUser.permissions) - : threadInfo.currentUser.permissions; + return threadInfos.filter((threadInfo: ThreadInfo) => { + const permissions = threadFrozenDueToBlock( + threadInfo, + loggedInUserInfo?.id, + userInfos, + ) + ? filterOutDisabledPermissions(threadInfo.currentUser.permissions) + : threadInfo.currentUser.permissions; + + return hasPermission(permissions, permission); + }); + }, [loggedInUserInfo?.id, permission, threadInfos, userInfos]); +} - return hasPermission(permissions, permission); - }, [loggedInUserInfo?.id, permission, threadInfo, userInfos]); +function useThreadHasPermission( + threadInfo: ?ThreadInfo, + permission: ThreadPermission, +): boolean { + const threads = useThreadsWithPermission( + threadInfo ? [threadInfo] : [], + permission, + ); + return threads.length === 1; } function viewerIsMember(