diff --git a/app/soapbox/queries/chats.ts b/app/soapbox/queries/chats.ts index 924563192..3be57e8df 100644 --- a/app/soapbox/queries/chats.ts +++ b/app/soapbox/queries/chats.ts @@ -8,7 +8,6 @@ import { ChatWidgetScreens, useChatContext } from 'soapbox/contexts/chat-context import { useStatContext } from 'soapbox/contexts/stat-context'; import { useApi, useAppDispatch, useAppSelector, useFeatures, useOwnAccount } from 'soapbox/hooks'; import { normalizeChatMessage } from 'soapbox/normalizers'; -import { compareId } from 'soapbox/utils/comparators'; import { flattenPages, PaginatedResult, updatePageItem } from 'soapbox/utils/queries'; import { queryClient } from './client'; @@ -80,8 +79,6 @@ const isLastMessage = (chatMessageId: string): boolean => { return !!chat; }; -const reverseOrder = (a: IChat, b: IChat): number => compareId(a.id, b.id); - const useChatMessages = (chat: IChat) => { const api = useApi(); const isBlocked = useAppSelector((state) => state.getIn(['relationships', chat.account.id, 'blocked_by'])); @@ -89,12 +86,12 @@ const useChatMessages = (chat: IChat) => { const getChatMessages = async (chatId: string, pageParam?: any): Promise> => { const nextPageLink = pageParam?.link; const uri = nextPageLink || `/api/v1/pleroma/chats/${chatId}/messages`; - const response = await api.get(uri); + const response = await api.get(uri); const { data } = response; const link = getNextLink(response); const hasMore = !!link; - const result = data.sort(reverseOrder).map(normalizeChatMessage); + const result = data.map(normalizeChatMessage); return { result, @@ -116,7 +113,7 @@ const useChatMessages = (chat: IChat) => { }, }); - const data = flattenPages(queryInfo.data); + const data = flattenPages(queryInfo.data)?.reverse(); return { ...queryInfo, @@ -169,10 +166,7 @@ const useChats = (search?: string) => { }, }); - const data = queryInfo.data?.pages.reduce( - (prev: IChat[], curr) => [...prev, ...curr.result], - [], - ); + const data = flattenPages(queryInfo.data); const chatsQuery = { ...queryInfo, diff --git a/app/soapbox/utils/queries.ts b/app/soapbox/utils/queries.ts index 0a0983e41..336fdddd1 100644 --- a/app/soapbox/utils/queries.ts +++ b/app/soapbox/utils/queries.ts @@ -28,8 +28,7 @@ const deduplicateById = (entities: T[]): T[] => { /** Flatten paginated results into a single array. */ const flattenPages = (queryData: InfiniteData> | undefined) => { const data = queryData?.pages.reduce( - // FIXME: Pleroma wants these to be reversed for Chats. - (prev: T[], curr) => [...curr.result, ...prev], + (prev: T[], curr) => [...prev, ...curr.result], [], );