diff --git a/web/input/input-state-container.react.js b/web/input/input-state-container.react.js --- a/web/input/input-state-container.react.js +++ b/web/input/input-state-container.react.js @@ -109,6 +109,9 @@ ) => Promise, +newThread: (request: ClientNewThreadRequest) => Promise, +pushModal: (modal: React.Node) => void, + +sendCallbacks: $ReadOnlyArray<() => mixed>, + +registerSendCallback: (() => mixed) => void, + +unregisterSendCallback: (() => mixed) => void, }; type State = { +pendingUploads: { @@ -498,6 +501,8 @@ addReply: (message: string) => this.addReply(message), addReplyListener: this.addReplyListener, removeReplyListener: this.removeReplyListener, + registerSendCallback: this.props.registerSendCallback, + unregisterSendCallback: this.props.unregisterSendCallback, }; }, ), @@ -937,6 +942,8 @@ messageInfo: RawTextMessageInfo, threadInfo: ThreadInfo, ) { + this.props.sendCallbacks.forEach(callback => callback()); + if (!threadIsPending(threadInfo.id)) { this.props.dispatchActionPromise( sendTextMessageActionTypes, @@ -1248,6 +1255,21 @@ const dispatchActionPromise = useDispatchActionPromise(); const modalContext = useModalContext(); + const [sendCallbacks, setSendCallbacks] = React.useState< + $ReadOnlyArray<() => mixed>, + >([]); + const registerSendCallback = React.useCallback((callback: () => mixed) => { + setSendCallbacks(prevCallbacks => [...prevCallbacks, callback]); + }, []); + const unregisterSendCallback = React.useCallback( + (callback: () => mixed) => { + setSendCallbacks(prevCallbacks => + prevCallbacks.filter(candidate => candidate !== callback), + ); + }, + [], + ); + return ( ); }, diff --git a/web/input/input-state.js b/web/input/input-state.js --- a/web/input/input-state.js +++ b/web/input/input-state.js @@ -57,6 +57,8 @@ addReply: (text: string) => void, addReplyListener: ((message: string) => void) => void, removeReplyListener: ((message: string) => void) => void, + registerSendCallback: (() => mixed) => void, + unregisterSendCallback: (() => mixed) => void, }; const InputStateContext: React.Context = React.createContext(