diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 6c3f0812214d..4e12c75248d3 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -123,7 +123,7 @@ function ReportScreen({ const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); const isFocused = useIsFocused(); - + const prevIsFocused = usePrevious(isFocused); const firstRenderRef = useRef(true); const flatListRef = useRef(null); const reactionListRef = useRef(null); @@ -362,6 +362,17 @@ function ReportScreen({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + // If a user has chosen to leave a thread, and then returns to it (e.g. with the back button), we need to call `openReport` again in order to allow the user to rejoin and to receive real-time updates + useEffect(() => { + if (!isFocused || prevIsFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + return; + } + Report.openReport(report.reportID); + + // We don't want to run this useEffect every time `report` is changed + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [prevIsFocused, report.notificationPreference, isFocused]); + useEffect(() => { // We don't want this effect to run on the first render. if (firstRenderRef.current) {