diff --git a/app/screens/channel/channel_post_list/channel_post_list.tsx b/app/screens/channel/channel_post_list/channel_post_list.tsx index 58912261f..07c30adf8 100644 --- a/app/screens/channel/channel_post_list/channel_post_list.tsx +++ b/app/screens/channel/channel_post_list/channel_post_list.tsx @@ -11,7 +11,6 @@ import {Screens} from '@constants'; import {useServerUrl} from '@context/server'; import {debounce} from '@helpers/api/general'; import {useIsTablet} from '@hooks/device'; -import {sortPostsByNewest} from '@utils/post'; import Intro from './intro'; @@ -44,7 +43,7 @@ const ChannelPostList = ({ const onEndReached = useCallback(debounce(async () => { if (!fetchingPosts.current && canLoadPosts.current && posts.length) { fetchingPosts.current = true; - const lastPost = sortPostsByNewest(posts)[0]; + const lastPost = posts[posts.length - 1]; const result = await fetchPostsBefore(serverUrl, channelId, lastPost.id); canLoadPosts.current = ((result as ProcessedPosts).posts?.length ?? 1) > 0; fetchingPosts.current = false; diff --git a/app/utils/post/index.ts b/app/utils/post/index.ts index 27e4aeab4..8ae3ac7cc 100644 --- a/app/utils/post/index.ts +++ b/app/utils/post/index.ts @@ -62,16 +62,6 @@ export function shouldIgnorePost(post: Post): boolean { return Post.IGNORE_POST_TYPES.includes(post.type); } -export const sortPostsByNewest = (posts: PostModel[]) => { - return posts.sort((a, b) => { - if (a.createAt > b.createAt) { - return 1; - } - - return -1; - }); -}; - export const processPostsFetched = (data: PostResponse) => { const order = data.order; const posts = Object.values(data.posts) as Post[];