Page MenuHomePhabricator

D13187.id43723.diff
No OneTemporary

D13187.id43723.diff

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

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)

Event Timeline