diff --git a/app/screens/global_threads/threads_list/thread/index.ts b/app/screens/global_threads/threads_list/thread/index.ts index 66c285d513..07be2a8ebc 100644 --- a/app/screens/global_threads/threads_list/thread/index.ts +++ b/app/screens/global_threads/threads_list/thread/index.ts @@ -7,6 +7,7 @@ import {of as of$} from 'rxjs'; import {switchMap} from 'rxjs/operators'; import {observeChannel} from '@queries/servers/channel'; +import {observePost} from '@queries/servers/post'; import {observeUser} from '@queries/servers/user'; import Thread from './thread'; @@ -15,7 +16,7 @@ import type {WithDatabaseArgs} from '@typings/database/database'; import type ThreadModel from '@typings/database/models/servers/thread'; const enhanced = withObservables([], ({database, thread}: WithDatabaseArgs & {thread: ThreadModel}) => { - const post = thread.post.observe(); + const post = observePost(database, thread.id); return { post, thread: thread.observe(), diff --git a/app/screens/global_threads/threads_list/thread/thread.tsx b/app/screens/global_threads/threads_list/thread/thread.tsx index dac144eae5..d3f6e8de53 100644 --- a/app/screens/global_threads/threads_list/thread/thread.tsx +++ b/app/screens/global_threads/threads_list/thread/thread.tsx @@ -142,6 +142,10 @@ const Thread = ({author, channel, location, post, teammateNameDisplay, testID, t } }, [isTablet, theme, thread]); + if (!post || !channel) { + return null; + } + const threadStarterName = displayUsername(author, intl.locale, teammateNameDisplay); const threadItemTestId = `${testID}.thread_item.${thread.id}`; @@ -219,7 +223,7 @@ const Thread = ({author, channel, location, post, teammateNameDisplay, testID, t {name} - {channel && threadStarterName !== channel?.displayName && ( + {threadStarterName !== channel?.displayName && ( 0 ? threads[threads.length - 1] : null; useEffect(() => { - // this is to be called only when there are no threads + // This is to be called only when there are no threads if (tab === 'all' && noThreads && !hasFetchedOnce.current) { setIsLoading(true); fetchThreads(serverUrl, teamId).finally(() => { @@ -74,7 +74,14 @@ const ThreadsList = ({ setIsLoading(false); }); } - }, [noThreads, tab]); + }, [noThreads, serverUrl, tab]); + + useEffect(() => { + // This is to be called when threads already exist locally and to fetch the latest threads + if (!noThreads) { + fetchNewThreads(serverUrl, teamId); + } + }, [noThreads, serverUrl, teamId]); const listEmptyComponent = useMemo(() => { if (isLoading) {