Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3373812
D7142.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
D7142.diff
View Options
diff --git a/lib/shared/edit-messages-utils.js b/lib/shared/edit-messages-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/edit-messages-utils.js
@@ -0,0 +1,39 @@
+// @flow
+
+import { threadHasPermission } from './thread-utils.js';
+import { messageTypes } from '../types/message-types.js';
+import type {
+ RobotextMessageInfo,
+ ComposableMessageInfo,
+} from '../types/message-types.js';
+import { threadPermissions, type ThreadInfo } from '../types/thread-types.js';
+import { useSelector } from '../utils/redux-utils.js';
+
+function useCanEditMessage(
+ threadInfo: ThreadInfo,
+ targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo,
+): boolean {
+ const currentUserInfo = useSelector(state => state.currentUserInfo);
+
+ if (targetMessageInfo.type !== messageTypes.TEXT) {
+ return false;
+ }
+
+ if (!currentUserInfo || !currentUserInfo.id) {
+ return false;
+ }
+
+ const currentUserId = currentUserInfo.id;
+ const targetMessageCreatorId = targetMessageInfo.creator.id;
+ if (currentUserId !== targetMessageCreatorId) {
+ return false;
+ }
+
+ const hasPermission = threadHasPermission(
+ threadInfo,
+ threadPermissions.EDIT_MESSAGE,
+ );
+ return hasPermission;
+}
+
+export { useCanEditMessage };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 11:59 AM (21 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2590360
Default Alt Text
D7142.diff (1 KB)
Attached To
Mode
D7142: [lib] Checking if the user can edit the message
Attached
Detach File
Event Timeline
Log In to Comment