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
Wed, Nov 6, 8:39 AM (19 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2429788
Default Alt Text
D11924.diff (1 KB)

Event Timeline