Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3369361
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
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)
Attached To
Mode
D11924: [lib] Introduce `useThreadsWithPermission` to filter `ThreadInfo`s
Attached
Detach File
Event Timeline
Log In to Comment