[Gekidou] Thread auto follow on receiving new post when user is in a NOT-FOLLOWING thread (#6448)

* Fix

* Using queries

* Made thread optional
This commit is contained in:
Anurag Shivarathri
2022-06-30 20:34:28 +05:30
committed by GitHub
parent 6c18cc8b38
commit 247c515b01
2 changed files with 9 additions and 6 deletions

View File

@@ -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),
};
});

View File

@@ -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<number>(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 = (
<PostList