Page MenuHomePhabricator

D7142.diff
No OneTemporary

D7142.diff

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

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)

Event Timeline