2025-02-14 14:11:32 +08:00
|
|
|
import { queryOptions } from '@tanstack/react-query';
|
2025-03-08 07:02:56 +08:00
|
|
|
import type { BusterMetricData } from '@/api/asset_interfaces/metric';
|
|
|
|
import { IBusterChat, BusterChatListItem, IBusterChatMessage } from '@/api/asset_interfaces/chat';
|
2025-02-14 05:28:45 +08:00
|
|
|
import type { GetChatListParams } from '@/api/request_interfaces/chats';
|
|
|
|
|
|
|
|
const chatsGetChat = (chatId: string) =>
|
2025-02-18 06:03:41 +08:00
|
|
|
queryOptions<IBusterChat>({
|
2025-02-14 05:28:45 +08:00
|
|
|
queryKey: ['chats', 'get', chatId] as const,
|
2025-03-06 01:13:24 +08:00
|
|
|
enabled: !!chatId,
|
2025-02-18 06:03:41 +08:00
|
|
|
staleTime: 60 * 1000 // 1 minute
|
|
|
|
});
|
|
|
|
|
|
|
|
const chatsMessages = (messageId: string) =>
|
|
|
|
queryOptions<IBusterChatMessage>({
|
|
|
|
queryKey: ['chats', 'messages', messageId] as const,
|
2025-03-06 01:13:24 +08:00
|
|
|
staleTime: Infinity,
|
|
|
|
enabled: !!messageId
|
2025-02-14 05:28:45 +08:00
|
|
|
});
|
|
|
|
|
2025-02-18 13:09:13 +08:00
|
|
|
const chatsMessagesFetchingData = (messageId: string) =>
|
|
|
|
queryOptions<BusterMetricData>({
|
|
|
|
queryKey: ['chats', 'messages-data', messageId] as const,
|
2025-03-06 01:13:24 +08:00
|
|
|
staleTime: Infinity,
|
|
|
|
enabled: !!messageId
|
2025-02-18 13:09:13 +08:00
|
|
|
});
|
|
|
|
|
2025-02-14 05:28:45 +08:00
|
|
|
const chatsGetList = (filters?: GetChatListParams) =>
|
|
|
|
queryOptions<BusterChatListItem[]>({
|
|
|
|
queryKey: ['chats', 'list', filters] as const,
|
2025-03-11 23:38:49 +08:00
|
|
|
staleTime: 10 * 1000,
|
|
|
|
initialData: []
|
2025-02-14 05:28:45 +08:00
|
|
|
});
|
|
|
|
|
2025-03-07 01:50:25 +08:00
|
|
|
const chatsBlackBoxMessages = (messageId: string) =>
|
|
|
|
queryOptions<string | null>({
|
|
|
|
queryKey: ['chats', 'messages', messageId, 'black-box'] as const,
|
|
|
|
staleTime: Infinity,
|
|
|
|
enabled: false,
|
|
|
|
queryFn: () => Promise.resolve(null)
|
|
|
|
});
|
|
|
|
|
2025-02-14 05:28:45 +08:00
|
|
|
export const chatQueryKeys = {
|
2025-02-18 06:03:41 +08:00
|
|
|
chatsGetChat,
|
|
|
|
chatsGetList,
|
2025-02-18 13:09:13 +08:00
|
|
|
chatsMessages,
|
2025-03-07 01:50:25 +08:00
|
|
|
chatsMessagesFetchingData,
|
|
|
|
chatsBlackBoxMessages
|
2025-02-14 05:28:45 +08:00
|
|
|
};
|