Skip to content

Commit

Permalink
Merge pull request #38027 from dukenv0307/fix/37612
Browse files Browse the repository at this point in the history
fix:  re-join thread after leaving thread and returning with back button
  • Loading branch information
MariaHCD authored Mar 14, 2024
2 parents b7a230e + d78c0f1 commit 0a512c9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlatList>(null);
const reactionListRef = useRef<ReactionListRef>(null);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0a512c9

Please sign in to comment.