Page MenuHomePhabricator

D11924.diff
No OneTemporary

D11924.diff

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<ThreadInfo>,
permission: ThreadPermission,
-): boolean {
+): $ReadOnlyArray<ThreadInfo> {
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(

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 10:30 PM (21 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2586584
Default Alt Text
D11924.diff (1 KB)

Event Timeline