diff --git a/native/chat/message-list-container.react.js b/native/chat/message-list-container.react.js --- a/native/chat/message-list-container.react.js +++ b/native/chat/message-list-container.react.js @@ -265,6 +265,21 @@ 'threadInfo must be specified in messageListContainer', ); + const inputState = React.useContext(InputStateContext); + invariant(inputState, 'inputState should be set in MessageListContainer'); + + const isFocused = props.navigation.isFocused(); + const { setPendingThreadUpdateHandler } = inputState; + React.useEffect(() => { + if (!isFocused) { + return; + } + setPendingThreadUpdateHandler(threadInfo.id, setBaseThreadInfo); + return () => { + setPendingThreadUpdateHandler(threadInfo.id, undefined); + }; + }, [setPendingThreadUpdateHandler, isFocused, threadInfo.id]); + const { setParams } = props.navigation; const navigationStack = useNavigationState(state => state.routes); React.useEffect(() => { @@ -278,8 +293,6 @@ } }, [isSearching, navigationStack, setParams, threadInfo]); - const inputState = React.useContext(InputStateContext); - invariant(inputState, 'inputState should be set in MessageListContainer'); const hideSearch = React.useCallback(() => { setBaseThreadInfo(threadInfo); setParams({ searching: false }); diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -155,6 +155,7 @@ activeURIs = new Map(); replyCallbacks: Array<(message: string) => void> = []; pendingThreadCreations = new Map>(); + pendingThreadUpdateHandlers = new Map mixed>(); static getCompletedUploads(props: Props, state: State): CompletedUploads { const completedUploads = {}; @@ -376,6 +377,7 @@ unregisterSendCallback: this.unregisterSendCallback, uploadInProgress: this.uploadInProgress, reportURIDisplayed: this.reportURIDisplayed, + setPendingThreadUpdateHandler: this.setPendingThreadUpdateHandler, }), ); @@ -425,6 +427,12 @@ messageInfo.text, viewerID, ); + if (threadInfo !== inputThreadInfo) { + const pendingThreadUpdateHandler = this.pendingThreadUpdateHandlers.get( + threadInfo.id, + ); + pendingThreadUpdateHandler?.(threadInfo); + } } let newThreadID = null; @@ -1401,6 +1409,20 @@ }); } + setPendingThreadUpdateHandler = ( + threadID: string, + pendingThreadUpdateHandler: ?(ThreadInfo) => mixed, + ) => { + if (!pendingThreadUpdateHandler) { + this.pendingThreadUpdateHandlers.delete(threadID); + } else { + this.pendingThreadUpdateHandlers.set( + threadID, + pendingThreadUpdateHandler, + ); + } + }; + render() { const inputState = this.inputStateSelector(this.state); return ( diff --git a/native/input/input-state.js b/native/input/input-state.js --- a/native/input/input-state.js +++ b/native/input/input-state.js @@ -46,6 +46,10 @@ +unregisterSendCallback: (() => void) => void, +uploadInProgress: () => boolean, +reportURIDisplayed: (uri: string, loaded: boolean) => void, + +setPendingThreadUpdateHandler: ( + threadID: string, + pendingThreadUpdateHandler: ?(ThreadInfo) => mixed, + ) => void, }; const InputStateContext: React.Context =