Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3749341
D7601.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7601.diff
View Options
diff --git a/lib/permissions/thread-permissions.js b/lib/permissions/thread-permissions.js
--- a/lib/permissions/thread-permissions.js
+++ b/lib/permissions/thread-permissions.js
@@ -152,7 +152,7 @@
}
}
-type RolePermissionBlobs = {
+export type RolePermissionBlobs = {
+Members: ThreadRolePermissionsBlob,
+Admins?: ThreadRolePermissionsBlob,
};
diff --git a/native/redux/update-roles-and-permissions.js b/native/redux/update-roles-and-permissions.js
--- a/native/redux/update-roles-and-permissions.js
+++ b/native/redux/update-roles-and-permissions.js
@@ -1,6 +1,10 @@
// @flow
-import type { ThreadStoreThreadInfos } from 'lib/types/thread-types.js';
+import { getRolePermissionBlobs } from 'lib/permissions/thread-permissions.js';
+import type {
+ RawThreadInfo,
+ ThreadStoreThreadInfos,
+} from 'lib/types/thread-types.js';
import { values } from 'lib/utils/objects.js';
type ThreadTraversalNode = {
@@ -10,7 +14,7 @@
function constructThreadTraversalNodes(
threadStoreInfos: ThreadStoreThreadInfos,
-): $ReadOnlyArray<ThreadTraversalNode> {
+): $ReadOnlyArray<$ReadOnly<ThreadTraversalNode>> {
const parentThreadMap = {};
for (const threadInfo of values(threadStoreInfos)) {
@@ -32,8 +36,31 @@
function updateRolesAndPermissions(
threadStoreInfos: ThreadStoreThreadInfos,
): ThreadStoreThreadInfos {
- constructThreadTraversalNodes(threadStoreInfos);
- return threadStoreInfos;
+ const updatedThreadStoreInfos = { ...threadStoreInfos };
+ const rootNodes = constructThreadTraversalNodes(updatedThreadStoreInfos);
+
+ const recursivelyUpdateRoles = (node: $ReadOnly<ThreadTraversalNode>) => {
+ const threadInfo: RawThreadInfo = updatedThreadStoreInfos[node.threadID];
+ const computedRolePermissionBlobs = getRolePermissionBlobs(threadInfo.type);
+
+ const roles = { ...threadInfo.roles };
+ for (const roleID of Object.keys(roles)) {
+ roles[roleID] = {
+ ...roles[roleID],
+ permissions: computedRolePermissionBlobs[roles[roleID].name],
+ };
+ }
+ updatedThreadStoreInfos[node.threadID] = {
+ ...threadInfo,
+ roles,
+ };
+
+ return node.children?.map(recursivelyUpdateRoles);
+ };
+
+ rootNodes.forEach(recursivelyUpdateRoles);
+
+ return updatedThreadStoreInfos;
}
export { updateRolesAndPermissions };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 10, 9:24 PM (16 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2855436
Default Alt Text
D7601.diff (2 KB)
Attached To
Mode
D7601: [native] Introduce `recursivelyUpdateRoles(ThreadTraversalNode)`
Attached
Detach File
Event Timeline
Log In to Comment