Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3154454
D11924.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D11924.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D11924: [lib] Introduce `useThreadsWithPermission` to filter `ThreadInfo`s
Attached
Detach File
Event Timeline
Log In to Comment