From 22f3dd9444a975829fcf078e7152a3a9874a11c6 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Tue, 25 Oct 2022 13:10:53 -0400 Subject: [PATCH] Disable chatMessages query if blocked --- .../features/chats/components/chat-message-list.tsx | 2 +- app/soapbox/queries/chats.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-message-list.tsx b/app/soapbox/features/chats/components/chat-message-list.tsx index 46b506d033..9c541a538f 100644 --- a/app/soapbox/features/chats/components/chat-message-list.tsx +++ b/app/soapbox/features/chats/components/chat-message-list.tsx @@ -87,7 +87,7 @@ const ChatMessageList: React.FC = ({ chat, autosize }) => { isFetchingNextPage, isLoading, refetch, - } = useChatMessages(chat.id); + } = useChatMessages(chat); const formattedChatMessages = chatMessages || []; diff --git a/app/soapbox/queries/chats.ts b/app/soapbox/queries/chats.ts index b739f359f6..354dbddbb2 100644 --- a/app/soapbox/queries/chats.ts +++ b/app/soapbox/queries/chats.ts @@ -7,7 +7,7 @@ import { getNextLink } from 'soapbox/api'; import compareId from 'soapbox/compare_id'; import { useChatContext } from 'soapbox/contexts/chat-context'; import { useStatContext } from 'soapbox/contexts/stat-context'; -import { useApi, useAppDispatch, useFeatures } from 'soapbox/hooks'; +import { useApi, useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks'; import { flattenPages, PaginatedResult, updatePageItem } from 'soapbox/utils/queries'; import { queryClient } from './client'; @@ -52,8 +52,9 @@ const ChatKeys = { const reverseOrder = (a: IChat, b: IChat): number => compareId(a.id, b.id); -const useChatMessages = (chatId: string) => { +const useChatMessages = (chat: IChat) => { const api = useApi(); + const isBlocked = useAppSelector((state) => state.getIn(['relationships', chat.account.id, 'blocked_by'])); const getChatMessages = async (chatId: string, pageParam?: any): Promise> => { const nextPageLink = pageParam?.link; @@ -72,7 +73,8 @@ const useChatMessages = (chatId: string) => { }; }; - const queryInfo = useInfiniteQuery(ChatKeys.chatMessages(chatId), ({ pageParam }) => getChatMessages(chatId, pageParam), { + const queryInfo = useInfiniteQuery(ChatKeys.chatMessages(chat.id), ({ pageParam }) => getChatMessages(chat.id, pageParam), { + enabled: !isBlocked, getNextPageParam: (config) => { if (config.hasMore) { return { link: config.link };