Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3401395
D13187.id43723.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13187.id43723.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,12 +1,20 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
+import uuid from 'uuid';
+import {
+ type OutboundDMOperationSpecification,
+ dmOperationSpecificationTypes,
+} from './dm-ops/dm-op-utils.js';
+import { useProcessAndSendDMOperation } from './dm-ops/process-dm-ops.js';
import { threadIsPending, useThreadHasPermission } from './thread-utils.js';
import {
sendEditMessageActionTypes,
useSendEditMessage,
} from '../actions/message-actions.js';
+import { type DMSendEditMessageOperation } from '../types/dm-ops.js';
import type {
ComposableMessageInfo,
RawMessageInfo,
@@ -15,39 +23,73 @@
import { messageTypes } from '../types/message-types-enum.js';
import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { threadPermissions } from '../types/thread-permission-types.js';
+import { threadTypeIsThick } from '../types/thread-types-enum.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector } from '../utils/redux-utils.js';
-function useEditMessage(): (
- messageID: string,
- newText: string,
-) => Promise<void> {
+function useEditMessage(
+ threadInfo: ThreadInfo,
+): (messageID: string, newText: string) => Promise<void> {
const callEditMessage = useSendEditMessage();
const dispatchActionPromise = useDispatchActionPromise();
+ const processAndSendDMOperation = useProcessAndSendDMOperation();
+ const viewerID = useSelector(
+ state => state.currentUserInfo && state.currentUserInfo.id,
+ );
return React.useCallback(
(messageID, newText) => {
- const editMessagePromise = (async () => {
- const result = await callEditMessage({
+ if (threadTypeIsThick(threadInfo.type)) {
+ invariant(viewerID, 'viewerID should be set');
+ const op: DMSendEditMessageOperation = {
+ type: 'send_edit_message',
+ threadID: threadInfo.id,
+ creatorID: viewerID,
+ time: Date.now(),
+ messageID: uuid.v4(),
targetMessageID: messageID,
text: newText,
- });
+ };
+ const opSpecification: OutboundDMOperationSpecification = {
+ type: dmOperationSpecificationTypes.OUTBOUND,
+ op,
+ recipients: {
+ type: 'some_users',
+ userIDs: threadInfo.members.map(member => member.id),
+ },
+ };
+ return processAndSendDMOperation(opSpecification);
+ } else {
+ const editMessagePromise = (async () => {
+ const result = await callEditMessage({
+ targetMessageID: messageID,
+ text: newText,
+ });
- return ({
- newMessageInfos: result.newMessageInfos,
- }: { +newMessageInfos: $ReadOnlyArray<RawMessageInfo> });
- })();
+ return ({
+ newMessageInfos: result.newMessageInfos,
+ }: { +newMessageInfos: $ReadOnlyArray<RawMessageInfo> });
+ })();
- void dispatchActionPromise(
- sendEditMessageActionTypes,
- editMessagePromise,
- );
+ void dispatchActionPromise(
+ sendEditMessageActionTypes,
+ editMessagePromise,
+ );
- return (async () => {
- await editMessagePromise;
- })();
+ return (async () => {
+ await editMessagePromise;
+ })();
+ }
},
- [dispatchActionPromise, callEditMessage],
+ [
+ threadInfo.type,
+ threadInfo.id,
+ threadInfo.members,
+ viewerID,
+ processAndSendDMOperation,
+ dispatchActionPromise,
+ callEditMessage,
+ ],
);
}
diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js
--- a/native/chat/chat-input-bar.react.js
+++ b/native/chat/chat-input-bar.react.js
@@ -1280,7 +1280,7 @@
props.threadInfo,
getDefaultTextMessageRules(chatMentionCandidates).simpleMarkdownRules,
);
- const editMessage = useEditMessage();
+ const editMessage = useEditMessage(props.threadInfo);
const [selectionState, setSelectionState] =
React.useState<SyncedSelectionData>({
diff --git a/web/chat/edit-text-message.react.js b/web/chat/edit-text-message.react.js
--- a/web/chat/edit-text-message.react.js
+++ b/web/chat/edit-text-message.react.js
@@ -34,7 +34,7 @@
const { background, threadInfo, item } = props;
const { editState, clearEditModal, setDraft, setError, updatePosition } =
useEditModalContext();
- const editMessage = useEditMessage();
+ const editMessage = useEditMessage(threadInfo);
const myRef = React.useRef<?HTMLDivElement>(null);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 11:53 AM (20 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2611588
Default Alt Text
D13187.id43723.diff (4 KB)
Attached To
Mode
D13187: [lib] add editing DM messages
Attached
Detach File
Event Timeline
Log In to Comment