From 247c515b017244c844d608b8e2043708ed813e64 Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Thu, 30 Jun 2022 20:34:28 +0530 Subject: [PATCH] [Gekidou] Thread auto follow on receiving new post when user is in a NOT-FOLLOWING thread (#6448) * Fix * Using queries * Made thread optional --- app/screens/thread/thread_post_list/index.ts | 7 ++++--- app/screens/thread/thread_post_list/thread_post_list.tsx | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/screens/thread/thread_post_list/index.ts b/app/screens/thread/thread_post_list/index.ts index bdba98a2c..e2b939596 100644 --- a/app/screens/thread/thread_post_list/index.ts +++ b/app/screens/thread/thread_post_list/index.ts @@ -7,9 +7,9 @@ import {AppStateStatus} from 'react-native'; import {of as of$} from 'rxjs'; import {switchMap} from 'rxjs/operators'; -import {observeMyChannel} from '@queries/servers/channel'; +import {observeMyChannel, observeChannel} from '@queries/servers/channel'; import {queryPostsChunk, queryPostsInThread} from '@queries/servers/post'; -import {observeIsCRTEnabled} from '@queries/servers/thread'; +import {observeIsCRTEnabled, observeThreadById} from '@queries/servers/thread'; import ThreadPostList from './thread_post_list'; @@ -37,9 +37,10 @@ const enhanced = withObservables(['forceQueryAfterAppState', 'rootPost'], ({data return queryPostsChunk(database, rootPost.id, earliest, latest, true).observe(); }), ), - teamId: rootPost.channel.observe().pipe( + teamId: observeChannel(database, rootPost.channelId).pipe( switchMap((channel) => of$(channel?.teamId)), ), + thread: observeThreadById(database, rootPost.id), }; }); diff --git a/app/screens/thread/thread_post_list/thread_post_list.tsx b/app/screens/thread/thread_post_list/thread_post_list.tsx index ded727603..f422409ed 100644 --- a/app/screens/thread/thread_post_list/thread_post_list.tsx +++ b/app/screens/thread/thread_post_list/thread_post_list.tsx @@ -12,6 +12,7 @@ import {useServerUrl} from '@context/server'; import {useIsTablet} from '@hooks/device'; import type PostModel from '@typings/database/models/servers/post'; +import type ThreadModel from '@typings/database/models/servers/thread'; type Props = { isCRTEnabled: boolean; @@ -20,6 +21,7 @@ type Props = { posts: PostModel[]; rootPost: PostModel; teamId: string; + thread?: ThreadModel; } const edges: Edge[] = ['bottom']; @@ -32,7 +34,7 @@ const styles = StyleSheet.create({ const ThreadPostList = ({ isCRTEnabled, lastViewedAt, - nativeID, posts, rootPost, teamId, + nativeID, posts, rootPost, teamId, thread, }: Props) => { const isTablet = useIsTablet(); const serverUrl = useServerUrl(); @@ -44,11 +46,11 @@ const ThreadPostList = ({ // If CRT is enabled, When new post arrives and thread modal is open, mark thread as read const oldPostsCount = useRef(posts.length); useEffect(() => { - if (isCRTEnabled && oldPostsCount.current < posts.length) { + if (isCRTEnabled && thread?.isFollowing && oldPostsCount.current < posts.length) { oldPostsCount.current = posts.length; markThreadAsRead(serverUrl, teamId, rootPost.id); } - }, [isCRTEnabled, posts, rootPost, serverUrl, teamId]); + }, [isCRTEnabled, posts, rootPost, serverUrl, teamId, thread]); const postList = (