Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/edit-messages-utils.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | |||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { threadIsPending, threadHasPermission } from './thread-utils.js'; | import { threadIsPending, threadHasPermission } from './thread-utils.js'; | ||||
import { | import { | ||||
sendEditMessageActionTypes, | sendEditMessageActionTypes, | ||||
sendEditMessage, | sendEditMessage, | ||||
} from '../actions/message-actions.js'; | } from '../actions/message-actions.js'; | ||||
import type { | import type { | ||||
SendEditMessageResult, | SendEditMessageResult, | ||||
RobotextMessageInfo, | RobotextMessageInfo, | ||||
ComposableMessageInfo, | ComposableMessageInfo, | ||||
} from '../types/message-types'; | } from '../types/message-types'; | ||||
import { messageTypes } from '../types/message-types-enum.js'; | import { messageTypes } from '../types/message-types-enum.js'; | ||||
import { threadPermissions } from '../types/thread-permission-types.js'; | import { threadPermissions } from '../types/thread-permission-types.js'; | ||||
import { type ThreadInfo } from '../types/thread-types.js'; | import { type ThreadInfo } from '../types/thread-types.js'; | ||||
import { | import { | ||||
useDispatchActionPromise, | useDispatchActionPromise, | ||||
useServerCall, | useServerCall, | ||||
} from '../utils/action-utils.js'; | } from '../utils/action-utils.js'; | ||||
import { useSelector } from '../utils/redux-utils.js'; | import { useSelector } from '../utils/redux-utils.js'; | ||||
function useEditMessage(): ( | function useEditMessage(): ( | ||||
messageID?: string, | messageID: string, | ||||
newText: string, | newText: string, | ||||
) => Promise<SendEditMessageResult> { | ) => Promise<SendEditMessageResult> { | ||||
const callEditMessage = useServerCall(sendEditMessage); | const callEditMessage = useServerCall(sendEditMessage); | ||||
const dispatchActionPromise = useDispatchActionPromise(); | const dispatchActionPromise = useDispatchActionPromise(); | ||||
return React.useCallback( | return React.useCallback( | ||||
(messageID, newText) => { | (messageID, newText) => { | ||||
invariant(messageID, 'messageID should be set!'); | |||||
const editMessagePromise = (async () => { | const editMessagePromise = (async () => { | ||||
const result = await callEditMessage({ | const result = await callEditMessage({ | ||||
targetMessageID: messageID, | targetMessageID: messageID, | ||||
text: newText, | text: newText, | ||||
}); | }); | ||||
return { | return { | ||||
newMessageInfos: result.newMessageInfos, | newMessageInfos: result.newMessageInfos, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |