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 @@ -158,6 +158,7 @@ activeURIs = new Map(); replyCallbacks: Array<(message: string) => void> = []; pendingThreadCreations = new Map>(); + pendingThreadUpdateHandlers = new Map mixed>(); // When the user sends a multimedia message that triggers the creation of a // sidebar, the sidebar gets created right away, but the message needs to wait @@ -389,6 +390,7 @@ unregisterSendCallback: this.unregisterSendCallback, uploadInProgress: this.uploadInProgress, reportURIDisplayed: this.reportURIDisplayed, + setPendingThreadUpdateHandler: this.setPendingThreadUpdateHandler, }), ); @@ -447,6 +449,12 @@ messageInfo.text, viewerID, ); + if (threadInfo !== inputThreadInfo) { + const pendingThreadUpdateHandler = this.pendingThreadUpdateHandlers.get( + threadInfo.id, + ); + pendingThreadUpdateHandler?.(threadInfo); + } } let newThreadID = null; @@ -1435,6 +1443,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 =