@droppii-org/chat-mobile 0.2.50 → 0.2.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/assets/images/index.js +2 -1
- package/lib/module/assets/images/index.js.map +1 -1
- package/lib/module/assets/images/resource-center-empty-box.png +0 -0
- package/lib/module/components/MediaViewerModal.js +2 -1
- package/lib/module/components/MediaViewerModal.js.map +1 -1
- package/lib/module/components/MergedImageGrid.js +1 -0
- package/lib/module/components/MergedImageGrid.js.map +1 -1
- package/lib/module/components/StickerPicker/StickerCategoryTabs.js +86 -0
- package/lib/module/components/StickerPicker/StickerCategoryTabs.js.map +1 -0
- package/lib/module/components/StickerPicker/StickerPickerPlaceholder.js +18 -0
- package/lib/module/components/StickerPicker/StickerPickerPlaceholder.js.map +1 -0
- package/lib/module/components/StickerPicker/StickerPickerRowItem.js +35 -0
- package/lib/module/components/StickerPicker/StickerPickerRowItem.js.map +1 -0
- package/lib/module/components/StickerPicker/StickerSectionList.js +110 -0
- package/lib/module/components/StickerPicker/StickerSectionList.js.map +1 -0
- package/lib/module/components/StickerPicker/constants.js +14 -0
- package/lib/module/components/StickerPicker/constants.js.map +1 -0
- package/lib/module/components/StickerPicker/index.js +134 -0
- package/lib/module/components/StickerPicker/index.js.map +1 -0
- package/lib/module/components/messages/stickerMessage/index.js +28 -0
- package/lib/module/components/messages/stickerMessage/index.js.map +1 -0
- package/lib/module/config/api-endpoints.js +5 -1
- package/lib/module/config/api-endpoints.js.map +1 -1
- package/lib/module/core/notification/pushToken.js +7 -7
- package/lib/module/core/notification/pushToken.js.map +1 -1
- package/lib/module/hooks/conversation/useGetConversationDetail.js +15 -0
- package/lib/module/hooks/conversation/useGetConversationDetail.js.map +1 -1
- package/lib/module/hooks/flows/useGetConversationFlowMainMenu.js +1 -1
- package/lib/module/hooks/flows/useGetConversationFlowMainMenu.js.map +1 -1
- package/lib/module/hooks/message/useSendMessage.js +45 -18
- package/lib/module/hooks/message/useSendMessage.js.map +1 -1
- package/lib/module/hooks/query-keys.js +11 -0
- package/lib/module/hooks/query-keys.js.map +1 -1
- package/lib/module/hooks/resourceCenter/useThreadResources.js +116 -0
- package/lib/module/hooks/resourceCenter/useThreadResources.js.map +1 -0
- package/lib/module/hooks/stickers/useFetchStickerByCategory.js +12 -0
- package/lib/module/hooks/stickers/useFetchStickerByCategory.js.map +1 -0
- package/lib/module/hooks/stickers/useStickerCategories.js +14 -0
- package/lib/module/hooks/stickers/useStickerCategories.js.map +1 -0
- package/lib/module/hooks/stickers/useStickerHistory.js +16 -0
- package/lib/module/hooks/stickers/useStickerHistory.js.map +1 -0
- package/lib/module/hooks/useChatCompose.js +1 -18
- package/lib/module/hooks/useChatCompose.js.map +1 -1
- package/lib/module/hooks/useImageAttachment.js +0 -2
- package/lib/module/hooks/useImageAttachment.js.map +1 -1
- package/lib/module/hooks/useMediaViewer.js +4 -1
- package/lib/module/hooks/useMediaViewer.js.map +1 -1
- package/lib/module/hooks/useSendAttachment.js +4 -1
- package/lib/module/hooks/useSendAttachment.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/screens/MediaView/index.js +104 -42
- package/lib/module/screens/MediaView/index.js.map +1 -1
- package/lib/module/screens/ResourceCenter/FileResourceRow.js +80 -0
- package/lib/module/screens/ResourceCenter/FileResourceRow.js.map +1 -0
- package/lib/module/screens/ResourceCenter/GridRenderer.js +83 -0
- package/lib/module/screens/ResourceCenter/GridRenderer.js.map +1 -0
- package/lib/module/screens/ResourceCenter/GridThumbnail.js +97 -0
- package/lib/module/screens/ResourceCenter/GridThumbnail.js.map +1 -0
- package/lib/module/screens/ResourceCenter/LinkResourceRow.js +81 -0
- package/lib/module/screens/ResourceCenter/LinkResourceRow.js.map +1 -0
- package/lib/module/screens/ResourceCenter/ListRenderer.js +60 -0
- package/lib/module/screens/ResourceCenter/ListRenderer.js.map +1 -0
- package/lib/module/screens/ResourceCenter/ResourceCenterTabBar.js +75 -0
- package/lib/module/screens/ResourceCenter/ResourceCenterTabBar.js.map +1 -0
- package/lib/module/screens/ResourceCenter/ResourceCenterTabScene.js +122 -0
- package/lib/module/screens/ResourceCenter/ResourceCenterTabScene.js.map +1 -0
- package/lib/module/screens/ResourceCenter/ResourceEmptyState.js +36 -0
- package/lib/module/screens/ResourceCenter/ResourceEmptyState.js.map +1 -0
- package/lib/module/screens/ResourceCenter/index.js +104 -0
- package/lib/module/screens/ResourceCenter/index.js.map +1 -0
- package/lib/module/screens/ResourceCenter/types.js +25 -0
- package/lib/module/screens/ResourceCenter/types.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatComposer.js +64 -16
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetail.js +6 -20
- package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
- package/lib/module/screens/chat-detail/hooks/useChatComposerAnimation.js +15 -4
- package/lib/module/screens/chat-detail/hooks/useChatComposerAnimation.js.map +1 -1
- package/lib/module/screens/chat-detail/hooks/useChatComposerState.js +3 -0
- package/lib/module/screens/chat-detail/hooks/useChatComposerState.js.map +1 -1
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js +5 -6
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js.map +1 -1
- package/lib/module/services/attachmentOrchestrator.js +20 -5
- package/lib/module/services/attachmentOrchestrator.js.map +1 -1
- package/lib/module/services/endpoints.js +4 -1
- package/lib/module/services/endpoints.js.map +1 -1
- package/lib/module/services/resourceCenter.js +102 -0
- package/lib/module/services/resourceCenter.js.map +1 -0
- package/lib/module/store/conversation.js +1 -20
- package/lib/module/store/conversation.js.map +1 -1
- package/lib/module/translation/resources/i18n.js +10 -1
- package/lib/module/translation/resources/i18n.js.map +1 -1
- package/lib/module/types/attachment.js +2 -0
- package/lib/module/types/chat.js +26 -0
- package/lib/module/types/chat.js.map +1 -1
- package/lib/module/types/sticker.js +2 -0
- package/lib/module/types/sticker.js.map +1 -0
- package/lib/module/utils/conversation.js +1 -24
- package/lib/module/utils/conversation.js.map +1 -1
- package/lib/module/utils/messageUtils.js +2 -0
- package/lib/module/utils/messageUtils.js.map +1 -1
- package/lib/module/utils/url.js +11 -0
- package/lib/module/utils/url.js.map +1 -1
- package/lib/typescript/src/assets/images/index.d.ts +1 -0
- package/lib/typescript/src/assets/images/index.d.ts.map +1 -1
- package/lib/typescript/src/components/MediaViewerModal.d.ts +3 -1
- package/lib/typescript/src/components/MediaViewerModal.d.ts.map +1 -1
- package/lib/typescript/src/components/MergedImageGrid.d.ts.map +1 -1
- package/lib/typescript/src/components/StickerPicker/StickerCategoryTabs.d.ts +9 -0
- package/lib/typescript/src/components/StickerPicker/StickerCategoryTabs.d.ts.map +1 -0
- package/lib/typescript/src/components/StickerPicker/StickerPickerPlaceholder.d.ts +2 -0
- package/lib/typescript/src/components/StickerPicker/StickerPickerPlaceholder.d.ts.map +1 -0
- package/lib/typescript/src/components/StickerPicker/StickerPickerRowItem.d.ts +8 -0
- package/lib/typescript/src/components/StickerPicker/StickerPickerRowItem.d.ts.map +1 -0
- package/lib/typescript/src/components/StickerPicker/StickerSectionList.d.ts +15 -0
- package/lib/typescript/src/components/StickerPicker/StickerSectionList.d.ts.map +1 -0
- package/lib/typescript/src/components/StickerPicker/constants.d.ts +11 -0
- package/lib/typescript/src/components/StickerPicker/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/StickerPicker/index.d.ts +7 -0
- package/lib/typescript/src/components/StickerPicker/index.d.ts.map +1 -0
- package/lib/typescript/src/components/messages/stickerMessage/index.d.ts +3 -0
- package/lib/typescript/src/components/messages/stickerMessage/index.d.ts.map +1 -0
- package/lib/typescript/src/config/api-endpoints.d.ts +4 -0
- package/lib/typescript/src/config/api-endpoints.d.ts.map +1 -1
- package/lib/typescript/src/hooks/conversation/useGetConversationDetail.d.ts +2 -1
- package/lib/typescript/src/hooks/conversation/useGetConversationDetail.d.ts.map +1 -1
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts +5 -3
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/query-keys.d.ts +11 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
- package/lib/typescript/src/hooks/resourceCenter/useThreadResources.d.ts +21 -0
- package/lib/typescript/src/hooks/resourceCenter/useThreadResources.d.ts.map +1 -0
- package/lib/typescript/src/hooks/stickers/useFetchStickerByCategory.d.ts +3 -0
- package/lib/typescript/src/hooks/stickers/useFetchStickerByCategory.d.ts.map +1 -0
- package/lib/typescript/src/hooks/stickers/useStickerCategories.d.ts +3 -0
- package/lib/typescript/src/hooks/stickers/useStickerCategories.d.ts.map +1 -0
- package/lib/typescript/src/hooks/stickers/useStickerHistory.d.ts +3 -0
- package/lib/typescript/src/hooks/stickers/useStickerHistory.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useChatCompose.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useImageAttachment.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMediaViewer.d.ts +5 -1
- package/lib/typescript/src/hooks/useMediaViewer.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useSendAttachment.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/MediaView/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/ResourceCenter/FileResourceRow.d.ts +7 -0
- package/lib/typescript/src/screens/ResourceCenter/FileResourceRow.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/GridRenderer.d.ts +14 -0
- package/lib/typescript/src/screens/ResourceCenter/GridRenderer.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/GridThumbnail.d.ts +10 -0
- package/lib/typescript/src/screens/ResourceCenter/GridThumbnail.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/LinkResourceRow.d.ts +8 -0
- package/lib/typescript/src/screens/ResourceCenter/LinkResourceRow.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/ListRenderer.d.ts +16 -0
- package/lib/typescript/src/screens/ResourceCenter/ListRenderer.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/ResourceCenterTabBar.d.ts +3 -0
- package/lib/typescript/src/screens/ResourceCenter/ResourceCenterTabBar.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/ResourceCenterTabScene.d.ts +16 -0
- package/lib/typescript/src/screens/ResourceCenter/ResourceCenterTabScene.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/ResourceEmptyState.d.ts +6 -0
- package/lib/typescript/src/screens/ResourceCenter/ResourceEmptyState.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/index.d.ts +4 -0
- package/lib/typescript/src/screens/ResourceCenter/index.d.ts.map +1 -0
- package/lib/typescript/src/screens/ResourceCenter/types.d.ts +28 -0
- package/lib/typescript/src/screens/ResourceCenter/types.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +2 -2
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/hooks/useChatComposerAnimation.d.ts +2 -1
- package/lib/typescript/src/screens/chat-detail/hooks/useChatComposerAnimation.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/hooks/useChatComposerState.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/hooks/useChatComposerState.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts.map +1 -1
- package/lib/typescript/src/services/attachmentOrchestrator.d.ts.map +1 -1
- package/lib/typescript/src/services/endpoints.d.ts +4 -1
- package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
- package/lib/typescript/src/services/resourceCenter.d.ts +9 -0
- package/lib/typescript/src/services/resourceCenter.d.ts.map +1 -0
- package/lib/typescript/src/store/conversation.d.ts +0 -3
- package/lib/typescript/src/store/conversation.d.ts.map +1 -1
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
- package/lib/typescript/src/types/attachment.d.ts +2 -0
- package/lib/typescript/src/types/attachment.d.ts.map +1 -1
- package/lib/typescript/src/types/chat.d.ts +66 -15
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/lib/typescript/src/types/sticker.d.ts +21 -0
- package/lib/typescript/src/types/sticker.d.ts.map +1 -0
- package/lib/typescript/src/utils/conversation.d.ts +1 -2
- package/lib/typescript/src/utils/conversation.d.ts.map +1 -1
- package/lib/typescript/src/utils/messageUtils.d.ts.map +1 -1
- package/lib/typescript/src/utils/url.d.ts +7 -0
- package/lib/typescript/src/utils/url.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/assets/images/index.ts +1 -0
- package/src/assets/images/resource-center-empty-box.png +0 -0
- package/src/components/MediaViewerModal.tsx +8 -3
- package/src/components/MergedImageGrid.tsx +1 -0
- package/src/components/StickerPicker/StickerCategoryTabs.tsx +103 -0
- package/src/components/StickerPicker/StickerPickerPlaceholder.tsx +16 -0
- package/src/components/StickerPicker/StickerPickerRowItem.tsx +43 -0
- package/src/components/StickerPicker/StickerSectionList.tsx +141 -0
- package/src/components/StickerPicker/constants.ts +20 -0
- package/src/components/StickerPicker/index.tsx +166 -0
- package/src/components/messages/stickerMessage/index.tsx +26 -0
- package/src/config/api-endpoints.ts +8 -0
- package/src/core/notification/pushToken.ts +7 -7
- package/src/hooks/conversation/useGetConversationDetail.ts +20 -1
- package/src/hooks/flows/useGetConversationFlowMainMenu.ts +1 -1
- package/src/hooks/message/useSendMessage.ts +49 -27
- package/src/hooks/query-keys.ts +16 -0
- package/src/hooks/resourceCenter/useThreadResources.ts +124 -0
- package/src/hooks/stickers/useFetchStickerByCategory.ts +15 -0
- package/src/hooks/stickers/useStickerCategories.ts +17 -0
- package/src/hooks/stickers/useStickerHistory.ts +19 -0
- package/src/hooks/useChatCompose.ts +0 -19
- package/src/hooks/useImageAttachment.ts +1 -2
- package/src/hooks/useMediaViewer.ts +21 -7
- package/src/hooks/useSendAttachment.ts +4 -1
- package/src/index.tsx +2 -0
- package/src/screens/MediaView/index.tsx +117 -54
- package/src/screens/ResourceCenter/FileResourceRow.tsx +99 -0
- package/src/screens/ResourceCenter/GridRenderer.tsx +104 -0
- package/src/screens/ResourceCenter/GridThumbnail.tsx +98 -0
- package/src/screens/ResourceCenter/LinkResourceRow.tsx +96 -0
- package/src/screens/ResourceCenter/ListRenderer.tsx +81 -0
- package/src/screens/ResourceCenter/ResourceCenterTabBar.tsx +89 -0
- package/src/screens/ResourceCenter/ResourceCenterTabScene.tsx +142 -0
- package/src/screens/ResourceCenter/ResourceEmptyState.tsx +39 -0
- package/src/screens/ResourceCenter/index.tsx +129 -0
- package/src/screens/ResourceCenter/types.ts +56 -0
- package/src/screens/chat-detail/ChatComposer.tsx +106 -19
- package/src/screens/chat-detail/ChatDetail.tsx +5 -19
- package/src/screens/chat-detail/hooks/useChatComposerAnimation.ts +21 -5
- package/src/screens/chat-detail/hooks/useChatComposerState.ts +7 -0
- package/src/screens/chat-detail/legend/LegendChatMessage.tsx +4 -5
- package/src/services/attachmentOrchestrator.ts +16 -3
- package/src/services/endpoints.ts +6 -1
- package/src/services/resourceCenter.ts +137 -0
- package/src/store/conversation.ts +0 -24
- package/src/translation/resources/i18n.ts +10 -0
- package/src/types/attachment.ts +3 -0
- package/src/types/chat.ts +80 -15
- package/src/types/sticker.ts +23 -0
- package/src/utils/conversation.ts +0 -28
- package/src/utils/messageUtils.ts +3 -0
- package/src/utils/url.ts +11 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useState, useCallback, useRef, useEffect, useMemo } from 'react';
|
|
2
|
+
import { KColors, KContainer } from '@droppii/libs';
|
|
3
|
+
import type {
|
|
4
|
+
StickerCategory,
|
|
5
|
+
StickerItem,
|
|
6
|
+
StickerRow,
|
|
7
|
+
} from '../../types/sticker';
|
|
8
|
+
import { useStickerCategories } from '../../hooks/stickers/useStickerCategories';
|
|
9
|
+
import { useStickerHistory } from '../../hooks/stickers/useStickerHistory';
|
|
10
|
+
import { useFetchStickerByCategory } from '../../hooks/stickers/useFetchStickerByCategory';
|
|
11
|
+
import {
|
|
12
|
+
RECENT_CATEGORY_ID,
|
|
13
|
+
STICKER_COLUMNS,
|
|
14
|
+
STICKER_PICKER_HEIGHT,
|
|
15
|
+
} from './constants';
|
|
16
|
+
import { StickerCategoryTabs } from './StickerCategoryTabs';
|
|
17
|
+
import {
|
|
18
|
+
StickerSectionList,
|
|
19
|
+
type StickerPickerSection,
|
|
20
|
+
} from './StickerSectionList';
|
|
21
|
+
import { trans } from '../../translation';
|
|
22
|
+
|
|
23
|
+
interface Props {
|
|
24
|
+
onSelectSticker: (sticker: StickerItem) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const chunkIntoRows = (items: StickerItem[], columns: number): StickerRow[] => {
|
|
28
|
+
const rows: StickerRow[] = [];
|
|
29
|
+
for (let i = 0; i < items.length; i += columns) {
|
|
30
|
+
rows.push(items.slice(i, i + columns));
|
|
31
|
+
}
|
|
32
|
+
return rows;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const makePlaceholderRows = (count: number, columns: number): StickerRow[] => {
|
|
36
|
+
const rows: StickerRow[] = [];
|
|
37
|
+
for (let i = 0; i < count; i += columns) {
|
|
38
|
+
const rowSize = Math.min(columns, count - i);
|
|
39
|
+
rows.push(Array.from({ length: rowSize }, () => null));
|
|
40
|
+
}
|
|
41
|
+
return rows;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const StickerPicker = ({ onSelectSticker }: Props) => {
|
|
45
|
+
const { data: categoriesData } = useStickerCategories();
|
|
46
|
+
const { data: recentStickers } = useStickerHistory();
|
|
47
|
+
const { mutateAsync: fetchStickersByCategory } = useFetchStickerByCategory();
|
|
48
|
+
|
|
49
|
+
const allCategories = useMemo<StickerCategory[]>(() => {
|
|
50
|
+
const recent: StickerCategory = {
|
|
51
|
+
id: RECENT_CATEGORY_ID,
|
|
52
|
+
name: trans('recent'),
|
|
53
|
+
icon: null,
|
|
54
|
+
stickerCount: 0,
|
|
55
|
+
};
|
|
56
|
+
return [recent, ...(categoriesData || [])];
|
|
57
|
+
}, [categoriesData]);
|
|
58
|
+
|
|
59
|
+
const [activeCategory, setActiveCategory] = useState(RECENT_CATEGORY_ID);
|
|
60
|
+
const [sectionDataMap, setSectionDataMap] = useState<
|
|
61
|
+
Record<string, StickerRow[]>
|
|
62
|
+
>({});
|
|
63
|
+
|
|
64
|
+
const loadedIdsRef = useRef(new Set<string>([RECENT_CATEGORY_ID]));
|
|
65
|
+
const sectionListRef = useRef<any>(null);
|
|
66
|
+
const suppressCategoryChangeRef = useRef(false);
|
|
67
|
+
const suppressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
68
|
+
|
|
69
|
+
// Populate recent section when history data arrives
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (recentStickers) {
|
|
72
|
+
setSectionDataMap((prev) => ({
|
|
73
|
+
...prev,
|
|
74
|
+
[RECENT_CATEGORY_ID]: chunkIntoRows(recentStickers, STICKER_COLUMNS),
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}, [recentStickers]);
|
|
78
|
+
|
|
79
|
+
// Cleanup suppress timer on unmount
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
return () => {
|
|
82
|
+
if (suppressTimerRef.current) clearTimeout(suppressTimerRef.current);
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
const sections = useMemo<StickerPickerSection[]>(
|
|
87
|
+
() =>
|
|
88
|
+
allCategories.map((cat) => ({
|
|
89
|
+
categoryId: cat.id,
|
|
90
|
+
title: cat.name,
|
|
91
|
+
data:
|
|
92
|
+
sectionDataMap[cat.id] ??
|
|
93
|
+
makePlaceholderRows(cat.stickerCount, STICKER_COLUMNS),
|
|
94
|
+
})),
|
|
95
|
+
[allCategories, sectionDataMap]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const handleSectionVisible = useCallback(
|
|
99
|
+
async (categoryId: string) => {
|
|
100
|
+
if (categoryId === RECENT_CATEGORY_ID) return;
|
|
101
|
+
if (loadedIdsRef.current.has(categoryId)) return;
|
|
102
|
+
loadedIdsRef.current.add(categoryId);
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const stickers = await fetchStickersByCategory(categoryId);
|
|
106
|
+
setSectionDataMap((prev) => ({
|
|
107
|
+
...prev,
|
|
108
|
+
[categoryId]: chunkIntoRows(stickers, STICKER_COLUMNS),
|
|
109
|
+
}));
|
|
110
|
+
} catch {
|
|
111
|
+
loadedIdsRef.current.delete(categoryId);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
[fetchStickersByCategory]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const handleActiveCategoryChange = useCallback((categoryId: string) => {
|
|
118
|
+
if (suppressCategoryChangeRef.current) return;
|
|
119
|
+
setActiveCategory(categoryId);
|
|
120
|
+
}, []);
|
|
121
|
+
|
|
122
|
+
const handleCategoryPress = useCallback(
|
|
123
|
+
(categoryId: string) => {
|
|
124
|
+
setActiveCategory(categoryId);
|
|
125
|
+
|
|
126
|
+
suppressCategoryChangeRef.current = true;
|
|
127
|
+
if (suppressTimerRef.current) clearTimeout(suppressTimerRef.current);
|
|
128
|
+
suppressTimerRef.current = setTimeout(() => {
|
|
129
|
+
suppressCategoryChangeRef.current = false;
|
|
130
|
+
}, 600);
|
|
131
|
+
|
|
132
|
+
const sectionIndex = allCategories.findIndex((c) => c.id === categoryId);
|
|
133
|
+
if (sectionIndex >= 0 && sectionListRef.current) {
|
|
134
|
+
try {
|
|
135
|
+
sectionListRef.current.scrollToLocation({
|
|
136
|
+
sectionIndex,
|
|
137
|
+
itemIndex: 0,
|
|
138
|
+
animated: true,
|
|
139
|
+
viewOffset: 0,
|
|
140
|
+
});
|
|
141
|
+
} catch {}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
[allCategories]
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<KContainer.View
|
|
149
|
+
style={{ height: STICKER_PICKER_HEIGHT }}
|
|
150
|
+
background={KColors.white}
|
|
151
|
+
>
|
|
152
|
+
<StickerCategoryTabs
|
|
153
|
+
categories={allCategories}
|
|
154
|
+
activeCategory={activeCategory}
|
|
155
|
+
onSelectCategory={handleCategoryPress}
|
|
156
|
+
/>
|
|
157
|
+
<StickerSectionList
|
|
158
|
+
ref={sectionListRef}
|
|
159
|
+
sections={sections}
|
|
160
|
+
onSectionVisible={handleSectionVisible}
|
|
161
|
+
onActiveCategoryChange={handleActiveCategoryChange}
|
|
162
|
+
onSelectSticker={onSelectSticker}
|
|
163
|
+
/>
|
|
164
|
+
</KContainer.View>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import type { BaseLegendMessageProps } from '../types';
|
|
3
|
+
import { KContainer, KImage } from '@droppii/libs';
|
|
4
|
+
import { StyleSheet } from 'react-native';
|
|
5
|
+
|
|
6
|
+
const STICKER_SIZE = 120;
|
|
7
|
+
export const StickerMessage = memo(({ message }: BaseLegendMessageProps) => {
|
|
8
|
+
return (
|
|
9
|
+
<KContainer.View style={styles.message}>
|
|
10
|
+
<KImage.Base
|
|
11
|
+
uri={message?.stickerElem?.content || ''}
|
|
12
|
+
width={STICKER_SIZE}
|
|
13
|
+
height={STICKER_SIZE}
|
|
14
|
+
/>
|
|
15
|
+
</KContainer.View>
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const styles = StyleSheet.create({
|
|
20
|
+
message: {
|
|
21
|
+
width: STICKER_SIZE,
|
|
22
|
+
height: STICKER_SIZE,
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -17,6 +17,10 @@ export interface ApiEndpoints {
|
|
|
17
17
|
imageUpload: string;
|
|
18
18
|
bot: string;
|
|
19
19
|
uploadFcmToken: string;
|
|
20
|
+
stickerCategories: string;
|
|
21
|
+
stickersByCategory: string;
|
|
22
|
+
stickerHistory: string;
|
|
23
|
+
messagesResources: string;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
const DEFAULT_ENDPOINTS: ApiEndpoints = {
|
|
@@ -25,6 +29,10 @@ const DEFAULT_ENDPOINTS: ApiEndpoints = {
|
|
|
25
29
|
imageUpload: '/uploader-service/v1/uploader/permanently',
|
|
26
30
|
bot: '/chat-service/v1/app/bots/',
|
|
27
31
|
uploadFcmToken: '/chat-service/third/fcm_update_token',
|
|
32
|
+
stickerCategories: '/chat-service/v1/app/sticker-categories',
|
|
33
|
+
stickersByCategory: '/chat-service/v1/app/sticker-categories',
|
|
34
|
+
stickerHistory: '/chat-service/v1/app/stickers/history',
|
|
35
|
+
messagesResources: '/chat-service/v1/app/messages/resources',
|
|
28
36
|
};
|
|
29
37
|
|
|
30
38
|
let endpoints: ApiEndpoints = { ...DEFAULT_ENDPOINTS };
|
|
@@ -16,13 +16,13 @@ const uploadFcmToken = async (
|
|
|
16
16
|
project: DChatProject,
|
|
17
17
|
expireTime: number
|
|
18
18
|
): Promise<void> => {
|
|
19
|
-
console.log('[chat-mobile] uploadFcmToken', {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
19
|
+
// console.log('[chat-mobile] uploadFcmToken', {
|
|
20
|
+
// platformID,
|
|
21
|
+
// fcmToken,
|
|
22
|
+
// account: userID,
|
|
23
|
+
// project,
|
|
24
|
+
// expireTime,
|
|
25
|
+
// });
|
|
26
26
|
const token = useUserStore.getState().token;
|
|
27
27
|
if (!token) {
|
|
28
28
|
console.warn(
|
|
@@ -3,7 +3,7 @@ import OpenIMSDK, { SessionType } from '@droppii/openim-rn-client-sdk';
|
|
|
3
3
|
import { useConversationStore } from '../../store/conversation';
|
|
4
4
|
import { apiInstance } from '../../services/apis';
|
|
5
5
|
import type { BaseResponse } from '../../types/auth';
|
|
6
|
-
import type { DBotStatus } from '../../types/chat';
|
|
6
|
+
import type { DBotStatus, DConversationTarget } from '../../types/chat';
|
|
7
7
|
import { conversationQueryKeys } from '../query-keys';
|
|
8
8
|
import { ENDPOINTS } from '../../services/endpoints';
|
|
9
9
|
|
|
@@ -46,6 +46,25 @@ export const useGetStatusConversationBot = (botId?: string) => {
|
|
|
46
46
|
refetchOnMount: 'always',
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
+
export const useGetConversationTarget = (conversationId?: string) =>
|
|
50
|
+
useQuery({
|
|
51
|
+
queryKey: conversationQueryKeys.conversationTarget(conversationId || ''),
|
|
52
|
+
queryFn: async () => {
|
|
53
|
+
try {
|
|
54
|
+
const res = await apiInstance?.get<BaseResponse<DConversationTarget>>(
|
|
55
|
+
ENDPOINTS.chatService.getConversationTarget(conversationId || '')
|
|
56
|
+
);
|
|
57
|
+
return res?.data?.data || undefined;
|
|
58
|
+
} catch {
|
|
59
|
+
return undefined; // fail-open: unresolved status => compose stays enabled
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
enabled: !!conversationId,
|
|
63
|
+
staleTime: 0,
|
|
64
|
+
gcTime: 0,
|
|
65
|
+
refetchOnMount: 'always',
|
|
66
|
+
});
|
|
67
|
+
|
|
49
68
|
export const useGetOneConversation = ({
|
|
50
69
|
targetUserId,
|
|
51
70
|
targetGroupId,
|
|
@@ -12,7 +12,7 @@ export const useGetConversationFlowMainMenu = (conversationId?: string) => {
|
|
|
12
12
|
const res = await apiInstance?.get<BaseResponse<InputButtonItem[]>>(
|
|
13
13
|
ENDPOINTS.chatService.conversationFlowMainMenu(conversationId || '')
|
|
14
14
|
);
|
|
15
|
-
return res?.data?.data ||
|
|
15
|
+
return res?.data?.data || ([] as InputButtonItem[]);
|
|
16
16
|
},
|
|
17
17
|
enabled: !!conversationId,
|
|
18
18
|
});
|
|
@@ -16,10 +16,7 @@ import {
|
|
|
16
16
|
type IMessageItemEx,
|
|
17
17
|
} from '../../types/chat';
|
|
18
18
|
import { useChatContext, useChatDetailContext } from '../../context';
|
|
19
|
-
import {
|
|
20
|
-
generateContentBasedOnMessageType,
|
|
21
|
-
getBotId,
|
|
22
|
-
} from '../../utils/conversation';
|
|
19
|
+
import { getBotId } from '../../utils/conversation';
|
|
23
20
|
import { markMessageRevoked, useMessageStore } from '../../store/message';
|
|
24
21
|
import uuid from 'react-native-uuid';
|
|
25
22
|
|
|
@@ -27,34 +24,36 @@ import type { IUrlMetadata } from '../../types/common';
|
|
|
27
24
|
import type { IRunConversationFlowPayload } from '../../types/flows';
|
|
28
25
|
import { DeviceEventEmitter } from 'react-native';
|
|
29
26
|
import { ChatEvent } from '../../types/events';
|
|
27
|
+
import type { StickerItem } from '../../types/sticker';
|
|
28
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
29
|
+
import { stickerQueryKeys } from '../query-keys';
|
|
30
|
+
import { getMessagePreview } from '../../utils/messageUtils';
|
|
30
31
|
|
|
31
32
|
const buildSendParams = (
|
|
32
33
|
message: MessageItem,
|
|
33
34
|
recvID: string,
|
|
34
35
|
groupID: string,
|
|
35
|
-
extendMessageInfo: IMessageItemEx
|
|
36
|
-
plainText: string
|
|
36
|
+
extendMessageInfo: IMessageItemEx
|
|
37
37
|
) => ({
|
|
38
38
|
groupID,
|
|
39
39
|
recvID,
|
|
40
40
|
message: { ...message, ex: JSON.stringify(extendMessageInfo) || '{}' },
|
|
41
|
-
offlinePushInfo: generateOfflinePushInfo(message
|
|
41
|
+
offlinePushInfo: generateOfflinePushInfo(message),
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
export const useSendMessage = () => {
|
|
45
45
|
const applicationType = useChatContext().applicationType;
|
|
46
46
|
const pushNewMessage = useMessageStore((state) => state.pushNewMessage);
|
|
47
47
|
const updateOneMessage = useMessageStore((state) => state.updateOneMessage);
|
|
48
|
-
const deleteOneMessage = useMessageStore((state) => state.deleteOneMessage);
|
|
49
48
|
const { quotedMessage, setQuotedMessage } = useChatDetailContext();
|
|
49
|
+
const queryClient = useQueryClient();
|
|
50
50
|
|
|
51
51
|
const dispatchSend = useCallback(
|
|
52
52
|
async (
|
|
53
53
|
message: MessageItem,
|
|
54
54
|
recvID: string,
|
|
55
55
|
groupID: string,
|
|
56
|
-
extendMessageInfo: IMessageItemEx
|
|
57
|
-
plainText: string
|
|
56
|
+
extendMessageInfo: IMessageItemEx
|
|
58
57
|
) => {
|
|
59
58
|
pushNewMessage({ ...message, status: MessageStatus.Sending });
|
|
60
59
|
|
|
@@ -63,12 +62,10 @@ export const useSendMessage = () => {
|
|
|
63
62
|
message,
|
|
64
63
|
recvID,
|
|
65
64
|
groupID,
|
|
66
|
-
extendMessageInfo
|
|
67
|
-
plainText
|
|
65
|
+
extendMessageInfo
|
|
68
66
|
);
|
|
69
67
|
// console.log('[useSendMessage] dispatchSend params', sendParams);
|
|
70
68
|
const sent = await OpenIMSDK.sendMessage(sendParams);
|
|
71
|
-
deleteOneMessage(message.clientMsgID);
|
|
72
69
|
pushNewMessage(sent);
|
|
73
70
|
} catch {
|
|
74
71
|
updateOneMessage({ ...message, status: MessageStatus.Failed });
|
|
@@ -76,7 +73,7 @@ export const useSendMessage = () => {
|
|
|
76
73
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
77
74
|
DeviceEventEmitter.emit(ChatEvent.ScrollToBottom);
|
|
78
75
|
},
|
|
79
|
-
[pushNewMessage, updateOneMessage
|
|
76
|
+
[pushNewMessage, updateOneMessage]
|
|
80
77
|
);
|
|
81
78
|
|
|
82
79
|
const sendMessage = useCallback(
|
|
@@ -85,11 +82,13 @@ export const useSendMessage = () => {
|
|
|
85
82
|
urlMetadata,
|
|
86
83
|
flow,
|
|
87
84
|
customMessage,
|
|
85
|
+
sticker,
|
|
88
86
|
}: {
|
|
89
87
|
plainText?: string;
|
|
90
88
|
urlMetadata?: IUrlMetadata;
|
|
91
89
|
flow?: IRunConversationFlowPayload;
|
|
92
90
|
customMessage?: CustomMessagePayload;
|
|
91
|
+
sticker?: StickerItem;
|
|
93
92
|
}) => {
|
|
94
93
|
const currentConversation = useConversationStore
|
|
95
94
|
.getState()
|
|
@@ -143,23 +142,39 @@ export const useSendMessage = () => {
|
|
|
143
142
|
messageList.push(message);
|
|
144
143
|
}
|
|
145
144
|
|
|
145
|
+
//sticker msg
|
|
146
|
+
if (!!sticker && !!sticker?.file?.fullUrl) {
|
|
147
|
+
let stickerMessage = await createStickerMessage(sticker?.file?.fullUrl);
|
|
148
|
+
if (!stickerMessage) return;
|
|
149
|
+
messageList.push(stickerMessage);
|
|
150
|
+
}
|
|
151
|
+
|
|
146
152
|
for (const message of messageList) {
|
|
147
153
|
const extendMessageInfo: IMessageItemEx = {
|
|
148
154
|
applicationType,
|
|
149
155
|
urlMetadata,
|
|
150
156
|
flow,
|
|
157
|
+
stickerId: sticker?.id,
|
|
151
158
|
};
|
|
152
159
|
|
|
153
160
|
await dispatchSend(
|
|
154
161
|
message,
|
|
155
162
|
recvID || '',
|
|
156
163
|
groupID || '',
|
|
157
|
-
extendMessageInfo
|
|
158
|
-
plainText || ''
|
|
164
|
+
extendMessageInfo
|
|
159
165
|
);
|
|
160
166
|
}
|
|
167
|
+
if (!!sticker && !!sticker?.id) {
|
|
168
|
+
queryClient.invalidateQueries({ queryKey: stickerQueryKeys.recent() });
|
|
169
|
+
}
|
|
161
170
|
},
|
|
162
|
-
[
|
|
171
|
+
[
|
|
172
|
+
applicationType,
|
|
173
|
+
dispatchSend,
|
|
174
|
+
quotedMessage,
|
|
175
|
+
setQuotedMessage,
|
|
176
|
+
queryClient,
|
|
177
|
+
]
|
|
163
178
|
);
|
|
164
179
|
|
|
165
180
|
const retryMessage = useCallback(
|
|
@@ -185,7 +200,7 @@ export const useSendMessage = () => {
|
|
|
185
200
|
recvID: recvID || '',
|
|
186
201
|
groupID: groupID || '',
|
|
187
202
|
message,
|
|
188
|
-
offlinePushInfo: generateOfflinePushInfo(message
|
|
203
|
+
offlinePushInfo: generateOfflinePushInfo(message),
|
|
189
204
|
};
|
|
190
205
|
|
|
191
206
|
try {
|
|
@@ -196,11 +211,9 @@ export const useSendMessage = () => {
|
|
|
196
211
|
message,
|
|
197
212
|
recvID || '',
|
|
198
213
|
groupID || '',
|
|
199
|
-
JSON.parse(message.ex || '{}') as IMessageItemEx
|
|
200
|
-
''
|
|
214
|
+
JSON.parse(message.ex || '{}') as IMessageItemEx
|
|
201
215
|
)
|
|
202
216
|
);
|
|
203
|
-
deleteOneMessage(message.clientMsgID);
|
|
204
217
|
pushNewMessage(sent);
|
|
205
218
|
} catch {
|
|
206
219
|
updateOneMessage({ ...message, status: MessageStatus.Failed });
|
|
@@ -208,7 +221,7 @@ export const useSendMessage = () => {
|
|
|
208
221
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
209
222
|
DeviceEventEmitter.emit(ChatEvent.ScrollToBottom);
|
|
210
223
|
},
|
|
211
|
-
[pushNewMessage, updateOneMessage
|
|
224
|
+
[pushNewMessage, updateOneMessage]
|
|
212
225
|
);
|
|
213
226
|
|
|
214
227
|
const revokeMessage = useCallback(async (message: MessageItem) => {
|
|
@@ -232,16 +245,13 @@ export const useSendMessage = () => {
|
|
|
232
245
|
};
|
|
233
246
|
};
|
|
234
247
|
|
|
235
|
-
export const generateOfflinePushInfo = (
|
|
236
|
-
contentType: MessageType,
|
|
237
|
-
plainText: string
|
|
238
|
-
) => {
|
|
248
|
+
export const generateOfflinePushInfo = (message: MessageItem) => {
|
|
239
249
|
const conversationData = useConversationStore
|
|
240
250
|
?.getState?.()
|
|
241
251
|
?.getCurrentConversation();
|
|
242
252
|
const operatorUserID = useUserStore.getState().user?.userID || '';
|
|
243
253
|
const title = conversationData?.showName || 'Droppii';
|
|
244
|
-
const desc =
|
|
254
|
+
const desc = getMessagePreview(message);
|
|
245
255
|
return {
|
|
246
256
|
title,
|
|
247
257
|
desc,
|
|
@@ -310,3 +320,15 @@ export const createQuotedMessage = async (params: QuoteMsgParams) => {
|
|
|
310
320
|
});
|
|
311
321
|
return quotedMessage;
|
|
312
322
|
};
|
|
323
|
+
|
|
324
|
+
export const createStickerMessage = async (sticker: string) => {
|
|
325
|
+
let stickerMessage = await OpenIMSDK.createStickerMessage(sticker, uuid.v4())
|
|
326
|
+
.then((data) => {
|
|
327
|
+
return data;
|
|
328
|
+
})
|
|
329
|
+
.catch(({ errCode, errMsg }) => {
|
|
330
|
+
console.error('createStickerMessage', errCode, errMsg);
|
|
331
|
+
return null;
|
|
332
|
+
});
|
|
333
|
+
return stickerMessage;
|
|
334
|
+
};
|
package/src/hooks/query-keys.ts
CHANGED
|
@@ -12,6 +12,8 @@ export const conversationQueryKeys = {
|
|
|
12
12
|
detail: (conversationId: string) =>
|
|
13
13
|
[...conversationQueryKeys.details(), conversationId] as const,
|
|
14
14
|
getStatusBot: (botId: string) => ['getStatusBot', botId] as const,
|
|
15
|
+
conversationTarget: (conversationId: string) =>
|
|
16
|
+
['conversationTarget', conversationId] as const,
|
|
15
17
|
flow: (conversationId: string) => ['conversationFlow', conversationId],
|
|
16
18
|
flowMainMenu: (conversationId: string) => [
|
|
17
19
|
'conversationFlowMainMenu',
|
|
@@ -34,3 +36,17 @@ export const usersQueryKeys = {
|
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
export type ConversationQueryKeys = typeof conversationQueryKeys;
|
|
39
|
+
|
|
40
|
+
export const stickerQueryKeys = {
|
|
41
|
+
all: ['stickers'] as const,
|
|
42
|
+
categories: () => [...stickerQueryKeys.all, 'categories'] as const,
|
|
43
|
+
byCategory: (categoryId: string) =>
|
|
44
|
+
[...stickerQueryKeys.all, 'category', categoryId] as const,
|
|
45
|
+
recent: () => [...stickerQueryKeys.all, 'recent'] as const,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const resourceCenterQueryKeys = {
|
|
49
|
+
all: ['threadResources'] as const,
|
|
50
|
+
byType: (recvID: string, contentType: number) =>
|
|
51
|
+
[...resourceCenterQueryKeys.all, recvID, contentType] as const,
|
|
52
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { resourceCenterQueryKeys } from '../query-keys';
|
|
4
|
+
import { useChatContext } from '../../context';
|
|
5
|
+
import { ResourceCenterService } from '../../services/resourceCenter';
|
|
6
|
+
import type {
|
|
7
|
+
DThreadResource,
|
|
8
|
+
DThreadResourceContentType,
|
|
9
|
+
} from '../../types/chat';
|
|
10
|
+
|
|
11
|
+
const PAGE_SIZE = 15;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* U5 resolved against a real staging response: revoked (recalled) messages ARE
|
|
15
|
+
* still returned by `/messages/resources` with `isRevoked: true` — BE does NOT
|
|
16
|
+
* pre-filter them. This client-side check is load-bearing, not defense-in-depth.
|
|
17
|
+
* `deleted`/`hidden` flags weren't observed in the tested rows — if BE adds them
|
|
18
|
+
* later, extend this predicate.
|
|
19
|
+
*/
|
|
20
|
+
const isVisibleResource = (item: DThreadResource): boolean => !item.isRevoked;
|
|
21
|
+
|
|
22
|
+
export const useThreadResources = (
|
|
23
|
+
recvID: string,
|
|
24
|
+
contentType: DThreadResourceContentType,
|
|
25
|
+
chatType: 'SINGLE' | 'GROUP'
|
|
26
|
+
) => {
|
|
27
|
+
const { applicationType } = useChatContext();
|
|
28
|
+
const queryClient = useQueryClient();
|
|
29
|
+
const queryKey = resourceCenterQueryKeys.byType(recvID, contentType);
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
data,
|
|
33
|
+
isLoading,
|
|
34
|
+
isError,
|
|
35
|
+
hasNextPage,
|
|
36
|
+
fetchNextPage,
|
|
37
|
+
isFetchingNextPage,
|
|
38
|
+
refetch,
|
|
39
|
+
} = useInfiniteQuery({
|
|
40
|
+
queryKey,
|
|
41
|
+
// `initialPageParam` is a react-query v5-only option — this library's
|
|
42
|
+
// `@tanstack/react-query` peer dep is unpinned (`"*"`), so a host app on v4
|
|
43
|
+
// (confirmed: biz-mobile pins 4.40.1) silently ignores this option and the
|
|
44
|
+
// first fetch's `pageParam` comes back `undefined`, not `1`. The `?? 1`
|
|
45
|
+
// fallback below is what actually makes page 1 work under v4 — do not remove
|
|
46
|
+
// it even though it looks redundant next to `initialPageParam`.
|
|
47
|
+
initialPageParam: 1,
|
|
48
|
+
queryFn: ({ pageParam }) =>
|
|
49
|
+
ResourceCenterService.fetchThreadResources({
|
|
50
|
+
recvID,
|
|
51
|
+
contentType,
|
|
52
|
+
chatType,
|
|
53
|
+
page: pageParam ?? 1,
|
|
54
|
+
pageSize: PAGE_SIZE,
|
|
55
|
+
applicationType,
|
|
56
|
+
}),
|
|
57
|
+
getNextPageParam: (lastPage) =>
|
|
58
|
+
lastPage.hasMore ? lastPage.page + 1 : undefined,
|
|
59
|
+
enabled: !!recvID && !!chatType,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// De-dupe by `id` across pages — offset pagination (`page`/`pageSize`) can hand
|
|
63
|
+
// back the same item twice if new messages land in the thread between page
|
|
64
|
+
// fetches (classic offset-pagination drift), which LegendList's `keyExtractor`
|
|
65
|
+
// requires be unique or it throws ("overlapping key" / missing items & gaps).
|
|
66
|
+
const items = useMemo(() => {
|
|
67
|
+
const seen = new Set<string>();
|
|
68
|
+
const deduped: DThreadResource[] = [];
|
|
69
|
+
for (const page of data?.pages ?? []) {
|
|
70
|
+
for (const item of page.items) {
|
|
71
|
+
if (seen.has(item.id)) continue;
|
|
72
|
+
seen.add(item.id);
|
|
73
|
+
if (isVisibleResource(item)) deduped.push(item);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return deduped;
|
|
77
|
+
}, [data]);
|
|
78
|
+
|
|
79
|
+
// Pull-to-refresh should (a) only re-fetch page 1, not every already-loaded
|
|
80
|
+
// page, and (b) keep the currently-shown items visible while that fetch is in
|
|
81
|
+
// flight — no flash to empty/loading. Neither `refetch()` nor `resetQueries()`
|
|
82
|
+
// give us both:
|
|
83
|
+
// - `refetch()` on an infinite query re-fetches ALL loaded pages (wasteful).
|
|
84
|
+
// - `resetQueries()` clears cached data FIRST, then fetches — causes exactly
|
|
85
|
+
// the empty-state flash we don't want.
|
|
86
|
+
// - `refetch({ refetchPage })` (page-1-only) is a react-query v4-only option,
|
|
87
|
+
// removed in v5 — another cross-version footgun like `initialPageParam`.
|
|
88
|
+
// So: fetch page 1 directly via the service, then splice it into the cache
|
|
89
|
+
// with `setQueryData` — `data`/`items` never go empty in between, and exactly
|
|
90
|
+
// one request is made regardless of how many pages were already loaded.
|
|
91
|
+
const [isRefreshingFirstPage, setIsRefreshingFirstPage] = useState(false);
|
|
92
|
+
|
|
93
|
+
const refreshFirstPage = useCallback(async () => {
|
|
94
|
+
setIsRefreshingFirstPage(true);
|
|
95
|
+
try {
|
|
96
|
+
const firstPage = await ResourceCenterService.fetchThreadResources({
|
|
97
|
+
recvID,
|
|
98
|
+
contentType,
|
|
99
|
+
chatType,
|
|
100
|
+
page: 1,
|
|
101
|
+
pageSize: PAGE_SIZE,
|
|
102
|
+
applicationType,
|
|
103
|
+
});
|
|
104
|
+
queryClient.setQueryData(queryKey, {
|
|
105
|
+
pages: [firstPage],
|
|
106
|
+
pageParams: [1],
|
|
107
|
+
});
|
|
108
|
+
} finally {
|
|
109
|
+
setIsRefreshingFirstPage(false);
|
|
110
|
+
}
|
|
111
|
+
}, [queryClient, queryKey, recvID, contentType, chatType, applicationType]);
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
items,
|
|
115
|
+
isLoading,
|
|
116
|
+
isError,
|
|
117
|
+
hasMore: !!hasNextPage,
|
|
118
|
+
loadMore: fetchNextPage,
|
|
119
|
+
isFetchingNextPage,
|
|
120
|
+
isRefetching: isRefreshingFirstPage,
|
|
121
|
+
refetch,
|
|
122
|
+
refreshFirstPage,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { apiInstance } from '../../services/apis';
|
|
3
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
4
|
+
import type { BaseResponse } from '../../types/auth';
|
|
5
|
+
import type { StickerItem } from '../../types/sticker';
|
|
6
|
+
|
|
7
|
+
export const useFetchStickerByCategory = () =>
|
|
8
|
+
useMutation({
|
|
9
|
+
mutationFn: async (categoryId: string) => {
|
|
10
|
+
const res = await apiInstance?.get<BaseResponse<StickerItem[]>>(
|
|
11
|
+
ENDPOINTS.chatService.stickersByCategoryId(categoryId)
|
|
12
|
+
);
|
|
13
|
+
return res?.data?.data || [];
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { apiInstance } from '../../services/apis';
|
|
3
|
+
import { stickerQueryKeys } from '../query-keys';
|
|
4
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
5
|
+
import type { BaseResponse } from '../../types/auth';
|
|
6
|
+
import type { StickerCategory } from '../../types/sticker';
|
|
7
|
+
|
|
8
|
+
export const useStickerCategories = () =>
|
|
9
|
+
useQuery({
|
|
10
|
+
queryKey: stickerQueryKeys.categories(),
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const res = await apiInstance?.get<BaseResponse<StickerCategory[]>>(
|
|
13
|
+
ENDPOINTS.chatService.stickerCategories()
|
|
14
|
+
);
|
|
15
|
+
return res?.data?.data || [];
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { apiInstance } from '../../services/apis';
|
|
3
|
+
import { stickerQueryKeys } from '../query-keys';
|
|
4
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
5
|
+
import type { BaseResponse } from '../../types/auth';
|
|
6
|
+
import type { StickerItem } from '../../types/sticker';
|
|
7
|
+
|
|
8
|
+
export const useStickerHistory = () =>
|
|
9
|
+
useQuery({
|
|
10
|
+
queryKey: stickerQueryKeys.recent(),
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const res = await apiInstance?.get<BaseResponse<StickerItem[]>>(
|
|
13
|
+
ENDPOINTS.chatService.stickerHistory()
|
|
14
|
+
);
|
|
15
|
+
return res?.data?.data || [];
|
|
16
|
+
},
|
|
17
|
+
staleTime: 0,
|
|
18
|
+
gcTime: 0,
|
|
19
|
+
});
|