Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3351360
D7143.id24061.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
D7143.id24061.diff
View Options
diff --git a/lib/shared/edit-messages-utils.js b/lib/shared/edit-messages-utils.js
--- a/lib/shared/edit-messages-utils.js
+++ b/lib/shared/edit-messages-utils.js
@@ -1,14 +1,55 @@
// @flow
+import * as React from 'react';
+
import { threadHasPermission } from './thread-utils.js';
+import {
+ sendEditMessageActionTypes,
+ sendEditMessage,
+} from '../actions/message-actions.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 {
+ useDispatchActionPromise,
+ useServerCall,
+} from '../utils/action-utils.js';
+import { cloneError } from '../utils/errors.js';
import { useSelector } from '../utils/redux-utils.js';
+function useEditMessage(messageID?: string): (newText: string) => mixed {
+ const callEditMessage = useServerCall(sendEditMessage);
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(
+ newText => {
+ if (!messageID) {
+ return;
+ }
+
+ const editMessagePromise = (async () => {
+ try {
+ const result = await callEditMessage({
+ targetMessageID: messageID,
+ text: newText,
+ });
+ return {
+ newMessageInfos: result.newMessageInfos,
+ };
+ } catch (e) {
+ throw cloneError(e);
+ }
+ })();
+
+ dispatchActionPromise(sendEditMessageActionTypes, editMessagePromise);
+ },
+ [messageID, dispatchActionPromise, callEditMessage],
+ );
+}
+
function useCanEditMessage(
threadInfo: ThreadInfo,
targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo,
@@ -36,4 +77,4 @@
return hasPermission;
}
-export { useCanEditMessage };
+export { useCanEditMessage, useEditMessage };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 1:12 AM (20 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573379
Default Alt Text
D7143.id24061.diff (1 KB)
Attached To
Mode
D7143: [lib] Function to dispatch edit message action
Attached
Detach File
Event Timeline
Log In to Comment