diff --git a/native/chat/settings/thread-settings.react.js b/native/chat/settings/thread-settings.react.js --- a/native/chat/settings/thread-settings.react.js +++ b/native/chat/settings/thread-settings.react.js @@ -258,10 +258,6 @@ } componentDidMount() { - const threadInfo = this.props.threadInfo; - if (!threadInChatList(threadInfo)) { - threadWatcher.watchID(threadInfo.id); - } const tabNavigation: ?TabNavigationProp< 'Chat', > = this.props.navigation.dangerouslyGetParent(); @@ -270,10 +266,6 @@ } componentWillUnmount() { - const threadInfo = this.props.threadInfo; - if (!threadInChatList(threadInfo)) { - threadWatcher.removeID(threadInfo.id); - } const tabNavigation: ?TabNavigationProp< 'Chat', > = this.props.navigation.dangerouslyGetParent(); @@ -291,19 +283,6 @@ const prevThreadInfo = prevProps.threadInfo; const newThreadInfo = this.props.threadInfo; - if (newThreadInfo && newThreadInfo !== prevThreadInfo) { - this.props.navigation.setParams({ threadInfo: newThreadInfo }); - } - - if (prevThreadInfo.id !== newThreadInfo.id) { - if (!threadInChatList(prevThreadInfo)) { - threadWatcher.removeID(prevThreadInfo.id); - } - if (!threadInChatList(newThreadInfo)) { - threadWatcher.watchID(newThreadInfo.id); - } - } - if ( !tinycolor.equals(newThreadInfo.color, prevThreadInfo.color) && tinycolor.equals(this.state.colorEditValue, prevThreadInfo.color) @@ -1080,6 +1059,7 @@ state => state.currentUserInfo && state.currentUserInfo.id, ); const threadID = props.route.params.threadInfo.id; + const reduxThreadInfo: ?ThreadInfo = useSelector( state => threadInfoSelector(state)[threadID], ); @@ -1090,8 +1070,26 @@ ); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + + const { setParams } = props.navigation; + React.useEffect(() => { + if (reduxThreadInfo) { + setParams({ threadInfo: reduxThreadInfo }); + } + }, [reduxThreadInfo, setParams]); const threadInfo: ThreadInfo = reduxThreadInfo ?? props.route.params.threadInfo; + + React.useEffect(() => { + if (threadInChatList(threadInfo)) { + return undefined; + } + threadWatcher.watchID(threadInfo.id); + return () => { + threadWatcher.removeID(threadInfo.id); + }; + }, [threadInfo]); + const parentThreadID = threadInfo.parentThreadID; const parentThreadInfo: ?ThreadInfo = useSelector(state => parentThreadID ? threadInfoSelector(state)[parentThreadID] : null,