@droppii-org/chat-mobile 0.2.0
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/LICENSE +20 -0
- package/README.md +101 -0
- package/lib/module/assets/images/icon_bot.png +0 -0
- package/lib/module/assets/images/index.js +9 -0
- package/lib/module/assets/images/index.js.map +1 -0
- package/lib/module/assets/images/tag_bot.png +0 -0
- package/lib/module/assets/images/tag_mall.png +0 -0
- package/lib/module/build-ignore.d.js +2 -0
- package/lib/module/build-ignore.d.js.map +1 -0
- package/lib/module/components/Avatar/Avatar.js +81 -0
- package/lib/module/components/Avatar/Avatar.js.map +1 -0
- package/lib/module/components/Avatar/Avatar.types.js +2 -0
- package/lib/module/components/Avatar/Avatar.types.js.map +1 -0
- package/lib/module/components/Avatar/Avatar.utils.js +44 -0
- package/lib/module/components/Avatar/Avatar.utils.js.map +1 -0
- package/lib/module/components/Avatar/AvatarBadge.js +28 -0
- package/lib/module/components/Avatar/AvatarBadge.js.map +1 -0
- package/lib/module/components/Avatar/DoubleAvatar.js +74 -0
- package/lib/module/components/Avatar/DoubleAvatar.js.map +1 -0
- package/lib/module/components/Avatar/SingleAvatar.js +53 -0
- package/lib/module/components/Avatar/SingleAvatar.js.map +1 -0
- package/lib/module/components/Avatar/index.js +7 -0
- package/lib/module/components/Avatar/index.js.map +1 -0
- package/lib/module/components/ThreadCard/AvatarSection.js +37 -0
- package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -0
- package/lib/module/components/ThreadCard/NamePrefixIcon.js +36 -0
- package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -0
- package/lib/module/components/ThreadCard/ThreadCard.js +132 -0
- package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -0
- package/lib/module/components/ThreadCard/UnreadBadge.js +35 -0
- package/lib/module/components/ThreadCard/UnreadBadge.js.map +1 -0
- package/lib/module/components/ThreadCard/index.js +7 -0
- package/lib/module/components/ThreadCard/index.js.map +1 -0
- package/lib/module/components/ThreadCard/thread-card.utils.js +51 -0
- package/lib/module/components/ThreadCard/thread-card.utils.js.map +1 -0
- package/lib/module/core/index.js +11 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/core/useChatListener.js +62 -0
- package/lib/module/core/useChatListener.js.map +1 -0
- package/lib/module/core/useUserListener.js +72 -0
- package/lib/module/core/useUserListener.js.map +1 -0
- package/lib/module/hooks/query-keys.js +10 -0
- package/lib/module/hooks/query-keys.js.map +1 -0
- package/lib/module/hooks/useChatMessages.js +163 -0
- package/lib/module/hooks/useChatMessages.js.map +1 -0
- package/lib/module/hooks/useConversationList.js +51 -0
- package/lib/module/hooks/useConversationList.js.map +1 -0
- package/lib/module/index.js +14 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/screens/chat-detail/ChatAttachmentPanel.js +106 -0
- package/lib/module/screens/chat-detail/ChatAttachmentPanel.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatComposer.js +288 -0
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatDay.js +65 -0
- package/lib/module/screens/chat-detail/ChatDay.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatDetail.js +104 -0
- package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatDetailHeader.js +92 -0
- package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatList.js +145 -0
- package/lib/module/screens/chat-detail/ChatList.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatLoadEarlier.js +23 -0
- package/lib/module/screens/chat-detail/ChatLoadEarlier.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatQuickActions.js +85 -0
- package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatScrollToBottom.js +12 -0
- package/lib/module/screens/chat-detail/ChatScrollToBottom.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatTextBubble.js +62 -0
- package/lib/module/screens/chat-detail/ChatTextBubble.js.map +1 -0
- package/lib/module/screens/chat-detail/constants.js +59 -0
- package/lib/module/screens/chat-detail/constants.js.map +1 -0
- package/lib/module/screens/chat-detail/index.js +12 -0
- package/lib/module/screens/chat-detail/index.js.map +1 -0
- package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js +24 -0
- package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js.map +1 -0
- package/lib/module/screens/chat-detail/messages/types.js +4 -0
- package/lib/module/screens/chat-detail/messages/types.js.map +1 -0
- package/lib/module/screens/chat-detail/types.js +4 -0
- package/lib/module/screens/chat-detail/types.js.map +1 -0
- package/lib/module/screens/chat-detail/useChatActionPress.js +11 -0
- package/lib/module/screens/chat-detail/useChatActionPress.js.map +1 -0
- package/lib/module/screens/inbox/Inbox.js +134 -0
- package/lib/module/screens/inbox/Inbox.js.map +1 -0
- package/lib/module/screens/inbox/MessagesTab.js +58 -0
- package/lib/module/screens/inbox/MessagesTab.js.map +1 -0
- package/lib/module/screens/inbox/index.js +5 -0
- package/lib/module/screens/inbox/index.js.map +1 -0
- package/lib/module/services/apis.js +41 -0
- package/lib/module/services/apis.js.map +1 -0
- package/lib/module/services/index.js +5 -0
- package/lib/module/services/index.js.map +1 -0
- package/lib/module/services/message.js +38 -0
- package/lib/module/services/message.js.map +1 -0
- package/lib/module/store/conversation.js +89 -0
- package/lib/module/store/conversation.js.map +1 -0
- package/lib/module/store/index.js +6 -0
- package/lib/module/store/index.js.map +1 -0
- package/lib/module/store/storeConfig.js +19 -0
- package/lib/module/store/storeConfig.js.map +1 -0
- package/lib/module/store/user.js +25 -0
- package/lib/module/store/user.js.map +1 -0
- package/lib/module/translation/index.js +24 -0
- package/lib/module/translation/index.js.map +1 -0
- package/lib/module/translation/resources/i18n.js +10 -0
- package/lib/module/translation/resources/i18n.js.map +1 -0
- package/lib/module/types/auth.js +9 -0
- package/lib/module/types/auth.js.map +1 -0
- package/lib/module/types/chat.js +26 -0
- package/lib/module/types/chat.js.map +1 -0
- package/lib/module/types/message.js +16 -0
- package/lib/module/types/message.js.map +1 -0
- package/lib/module/utils/conversation.js +61 -0
- package/lib/module/utils/conversation.js.map +1 -0
- package/lib/module/utils/giftedChatMessage.js +90 -0
- package/lib/module/utils/giftedChatMessage.js.map +1 -0
- package/lib/module/utils/message.js +68 -0
- package/lib/module/utils/message.js.map +1 -0
- package/lib/module/utils/resolveMessageType.js +44 -0
- package/lib/module/utils/resolveMessageType.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/assets/images/index.d.ts +7 -0
- package/lib/typescript/src/assets/images/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.d.ts +4 -0
- package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.types.d.ts +18 -0
- package/lib/typescript/src/components/Avatar/Avatar.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts +14 -0
- package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts +7 -0
- package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts +13 -0
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts +12 -0
- package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/index.d.ts +6 -0
- package/lib/typescript/src/components/Avatar/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +8 -0
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +8 -0
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts +11 -0
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts +6 -0
- package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/index.d.ts +5 -0
- package/lib/typescript/src/components/ThreadCard/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts +4 -0
- package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +3 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/core/useChatListener.d.ts +2 -0
- package/lib/typescript/src/core/useChatListener.d.ts.map +1 -0
- package/lib/typescript/src/core/useUserListener.d.ts +2 -0
- package/lib/typescript/src/core/useUserListener.d.ts.map +1 -0
- package/lib/typescript/src/hooks/query-keys.d.ts +9 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useChatMessages.d.ts +21 -0
- package/lib/typescript/src/hooks/useChatMessages.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useConversationList.d.ts +8 -0
- package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +14 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +4 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +4 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatList.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatList.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts +2 -0
- package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/constants.d.ts +17 -0
- package/lib/typescript/src/screens/chat-detail/constants.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/index.d.ts +13 -0
- package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/messages/types.d.ts +13 -0
- package/lib/typescript/src/screens/chat-detail/messages/types.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/types.d.ts +86 -0
- package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts.map +1 -0
- package/lib/typescript/src/screens/inbox/Inbox.d.ts +10 -0
- package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -0
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts +7 -0
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -0
- package/lib/typescript/src/screens/inbox/index.d.ts +3 -0
- package/lib/typescript/src/screens/inbox/index.d.ts.map +1 -0
- package/lib/typescript/src/services/apis.d.ts +12 -0
- package/lib/typescript/src/services/apis.d.ts.map +1 -0
- package/lib/typescript/src/services/index.d.ts +3 -0
- package/lib/typescript/src/services/index.d.ts.map +1 -0
- package/lib/typescript/src/services/message.d.ts +21 -0
- package/lib/typescript/src/services/message.d.ts.map +1 -0
- package/lib/typescript/src/store/conversation.d.ts +24 -0
- package/lib/typescript/src/store/conversation.d.ts.map +1 -0
- package/lib/typescript/src/store/index.d.ts +4 -0
- package/lib/typescript/src/store/index.d.ts.map +1 -0
- package/lib/typescript/src/store/storeConfig.d.ts +4 -0
- package/lib/typescript/src/store/storeConfig.d.ts.map +1 -0
- package/lib/typescript/src/store/user.d.ts +12 -0
- package/lib/typescript/src/store/user.d.ts.map +1 -0
- package/lib/typescript/src/translation/index.d.ts +4 -0
- package/lib/typescript/src/translation/index.d.ts.map +1 -0
- package/lib/typescript/src/translation/resources/i18n.d.ts +5 -0
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -0
- package/lib/typescript/src/types/auth.d.ts +24 -0
- package/lib/typescript/src/types/auth.d.ts.map +1 -0
- package/lib/typescript/src/types/chat.d.ts +99 -0
- package/lib/typescript/src/types/chat.d.ts.map +1 -0
- package/lib/typescript/src/types/message.d.ts +15 -0
- package/lib/typescript/src/types/message.d.ts.map +1 -0
- package/lib/typescript/src/utils/conversation.d.ts +10 -0
- package/lib/typescript/src/utils/conversation.d.ts.map +1 -0
- package/lib/typescript/src/utils/giftedChatMessage.d.ts +10 -0
- package/lib/typescript/src/utils/giftedChatMessage.d.ts.map +1 -0
- package/lib/typescript/src/utils/message.d.ts +15 -0
- package/lib/typescript/src/utils/message.d.ts.map +1 -0
- package/lib/typescript/src/utils/resolveMessageType.d.ts +4 -0
- package/lib/typescript/src/utils/resolveMessageType.d.ts.map +1 -0
- package/package.json +209 -0
- package/src/assets/images/icon_bot.png +0 -0
- package/src/assets/images/index.ts +7 -0
- package/src/assets/images/tag_bot.png +0 -0
- package/src/assets/images/tag_mall.png +0 -0
- package/src/build-ignore.d.ts +24 -0
- package/src/components/Avatar/Avatar.tsx +105 -0
- package/src/components/Avatar/Avatar.types.ts +17 -0
- package/src/components/Avatar/Avatar.utils.ts +49 -0
- package/src/components/Avatar/AvatarBadge.tsx +29 -0
- package/src/components/Avatar/DoubleAvatar.tsx +89 -0
- package/src/components/Avatar/SingleAvatar.tsx +74 -0
- package/src/components/Avatar/index.ts +5 -0
- package/src/components/ThreadCard/AvatarSection.tsx +42 -0
- package/src/components/ThreadCard/NamePrefixIcon.tsx +45 -0
- package/src/components/ThreadCard/ThreadCard.tsx +145 -0
- package/src/components/ThreadCard/UnreadBadge.tsx +35 -0
- package/src/components/ThreadCard/index.ts +4 -0
- package/src/components/ThreadCard/thread-card.utils.ts +68 -0
- package/src/core/index.ts +10 -0
- package/src/core/useChatListener.ts +85 -0
- package/src/core/useUserListener.ts +86 -0
- package/src/hooks/query-keys.ts +11 -0
- package/src/hooks/useChatMessages.ts +243 -0
- package/src/hooks/useConversationList.ts +57 -0
- package/src/index.tsx +36 -0
- package/src/screens/chat-detail/ChatAttachmentPanel.tsx +142 -0
- package/src/screens/chat-detail/ChatComposer.tsx +412 -0
- package/src/screens/chat-detail/ChatDay.tsx +73 -0
- package/src/screens/chat-detail/ChatDetail.tsx +118 -0
- package/src/screens/chat-detail/ChatDetailHeader.tsx +114 -0
- package/src/screens/chat-detail/ChatList.tsx +187 -0
- package/src/screens/chat-detail/ChatLoadEarlier.tsx +20 -0
- package/src/screens/chat-detail/ChatQuickActions.tsx +108 -0
- package/src/screens/chat-detail/ChatScrollToBottom.tsx +8 -0
- package/src/screens/chat-detail/ChatTextBubble.tsx +73 -0
- package/src/screens/chat-detail/constants.ts +76 -0
- package/src/screens/chat-detail/index.ts +33 -0
- package/src/screens/chat-detail/messages/ChatMessageBubble.tsx +24 -0
- package/src/screens/chat-detail/messages/types.ts +14 -0
- package/src/screens/chat-detail/types.ts +97 -0
- package/src/screens/chat-detail/useChatActionPress.ts +17 -0
- package/src/screens/inbox/Inbox.tsx +164 -0
- package/src/screens/inbox/MessagesTab.tsx +62 -0
- package/src/screens/inbox/index.ts +2 -0
- package/src/services/apis.ts +60 -0
- package/src/services/index.ts +2 -0
- package/src/services/message.ts +61 -0
- package/src/store/conversation.ts +116 -0
- package/src/store/index.ts +3 -0
- package/src/store/storeConfig.ts +19 -0
- package/src/store/user.ts +26 -0
- package/src/translation/index.ts +30 -0
- package/src/translation/resources/i18n.ts +8 -0
- package/src/types/auth.ts +25 -0
- package/src/types/chat.ts +118 -0
- package/src/types/message.ts +17 -0
- package/src/utils/conversation.ts +106 -0
- package/src/utils/giftedChatMessage.ts +137 -0
- package/src/utils/message.ts +136 -0
- package/src/utils/resolveMessageType.ts +49 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const conversationQueryKeys = {
|
|
2
|
+
all: ['conversations'] as const,
|
|
3
|
+
lists: () => [...conversationQueryKeys.all, 'list'] as const,
|
|
4
|
+
list: (applicationType: string) =>
|
|
5
|
+
[...conversationQueryKeys.lists(), applicationType] as const,
|
|
6
|
+
details: () => [...conversationQueryKeys.all, 'detail'] as const,
|
|
7
|
+
detail: (conversationId: string) =>
|
|
8
|
+
[...conversationQueryKeys.details(), conversationId] as const,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ConversationQueryKeys = typeof conversationQueryKeys;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import OpenIMSDK, {
|
|
2
|
+
OpenIMEvent,
|
|
3
|
+
type MessageItem,
|
|
4
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { ChatMessageAPI } from '../services/message';
|
|
7
|
+
import type { DMessageItem } from '../types/chat';
|
|
8
|
+
import {
|
|
9
|
+
belongsToConversation,
|
|
10
|
+
getHistoryPaginationAnchor,
|
|
11
|
+
hasNewHistoryMessages,
|
|
12
|
+
mergeMessages,
|
|
13
|
+
type HistoryPaginationAnchor,
|
|
14
|
+
} from '../utils/message';
|
|
15
|
+
|
|
16
|
+
type UseChatMessagesOptions = {
|
|
17
|
+
conversationId: string;
|
|
18
|
+
recvID?: string;
|
|
19
|
+
groupID?: string;
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function useChatMessages({
|
|
25
|
+
conversationId,
|
|
26
|
+
recvID = '',
|
|
27
|
+
groupID = '',
|
|
28
|
+
enabled = true,
|
|
29
|
+
pageSize = 20,
|
|
30
|
+
}: UseChatMessagesOptions) {
|
|
31
|
+
const [messages, setMessages] = useState<DMessageItem[]>([]);
|
|
32
|
+
const [currentUserId, setCurrentUserId] = useState<string>();
|
|
33
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
34
|
+
const [isLoadingEarlier, setIsLoadingEarlier] = useState(false);
|
|
35
|
+
const [hasMoreEarlier, setHasMoreEarlier] = useState(false);
|
|
36
|
+
const [error, setError] = useState<Error | null>(null);
|
|
37
|
+
|
|
38
|
+
const conversationIdRef = useRef(conversationId);
|
|
39
|
+
conversationIdRef.current = conversationId;
|
|
40
|
+
|
|
41
|
+
const isLoadingEarlierRef = useRef(false);
|
|
42
|
+
const messagesRef = useRef(messages);
|
|
43
|
+
const hasMoreEarlierRef = useRef(hasMoreEarlier);
|
|
44
|
+
const historyAnchorRef = useRef<HistoryPaginationAnchor | null>(null);
|
|
45
|
+
messagesRef.current = messages;
|
|
46
|
+
hasMoreEarlierRef.current = hasMoreEarlier;
|
|
47
|
+
|
|
48
|
+
const resetState = useCallback(() => {
|
|
49
|
+
setMessages([]);
|
|
50
|
+
setHasMoreEarlier(false);
|
|
51
|
+
setError(null);
|
|
52
|
+
isLoadingEarlierRef.current = false;
|
|
53
|
+
historyAnchorRef.current = null;
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
const loadInitialMessages = useCallback(async () => {
|
|
57
|
+
if (!conversationId) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setIsLoading(true);
|
|
62
|
+
setError(null);
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const [history, userId] = await Promise.all([
|
|
66
|
+
ChatMessageAPI.fetchHistoryMessages(conversationId, {
|
|
67
|
+
count: pageSize,
|
|
68
|
+
}),
|
|
69
|
+
ChatMessageAPI.getCurrentUserId(),
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
const initialMessages = history.messageList as DMessageItem[];
|
|
73
|
+
const oldestAnchor = getHistoryPaginationAnchor(initialMessages);
|
|
74
|
+
|
|
75
|
+
setCurrentUserId(userId);
|
|
76
|
+
setMessages(mergeMessages([], initialMessages));
|
|
77
|
+
historyAnchorRef.current = oldestAnchor
|
|
78
|
+
? {
|
|
79
|
+
clientMsgID: oldestAnchor.clientMsgID,
|
|
80
|
+
// lastMinSeq: resolveHistoryLastMinSeq(
|
|
81
|
+
// history,
|
|
82
|
+
// initialMessages.find(
|
|
83
|
+
// (message) => message.clientMsgID === oldestAnchor.clientMsgID
|
|
84
|
+
// )
|
|
85
|
+
// ),
|
|
86
|
+
}
|
|
87
|
+
: null;
|
|
88
|
+
setHasMoreEarlier(!history.isEnd && !!oldestAnchor);
|
|
89
|
+
|
|
90
|
+
ChatMessageAPI.markConversationAsRead(conversationId).catch(
|
|
91
|
+
() => undefined
|
|
92
|
+
);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
95
|
+
} finally {
|
|
96
|
+
setIsLoading(false);
|
|
97
|
+
}
|
|
98
|
+
}, [conversationId, pageSize]);
|
|
99
|
+
|
|
100
|
+
const onLoadEarlier = useCallback(async () => {
|
|
101
|
+
if (
|
|
102
|
+
!conversationId ||
|
|
103
|
+
isLoadingEarlierRef.current ||
|
|
104
|
+
!hasMoreEarlierRef.current ||
|
|
105
|
+
!messagesRef.current.length
|
|
106
|
+
) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
isLoadingEarlierRef.current = true;
|
|
111
|
+
setIsLoadingEarlier(true);
|
|
112
|
+
setError(null);
|
|
113
|
+
|
|
114
|
+
const anchor = historyAnchorRef.current;
|
|
115
|
+
if (!anchor?.clientMsgID) {
|
|
116
|
+
isLoadingEarlierRef.current = false;
|
|
117
|
+
setIsLoadingEarlier(false);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
const history = await ChatMessageAPI.fetchHistoryMessages(
|
|
123
|
+
conversationId,
|
|
124
|
+
{
|
|
125
|
+
count: pageSize,
|
|
126
|
+
startClientMsgID: anchor.clientMsgID,
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
const incoming = history.messageList as DMessageItem[];
|
|
130
|
+
const hasNewMessages = hasNewHistoryMessages(
|
|
131
|
+
messagesRef.current,
|
|
132
|
+
incoming
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (hasNewMessages) {
|
|
136
|
+
setMessages((current) => mergeMessages(current, incoming));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const nextAnchor = getHistoryPaginationAnchor(incoming);
|
|
140
|
+
historyAnchorRef.current = nextAnchor
|
|
141
|
+
? {
|
|
142
|
+
clientMsgID: nextAnchor.clientMsgID,
|
|
143
|
+
// lastMinSeq: resolveHistoryLastMinSeq(
|
|
144
|
+
// history,
|
|
145
|
+
// incoming.find(
|
|
146
|
+
// (message) => message.clientMsgID === nextAnchor.clientMsgID
|
|
147
|
+
// )
|
|
148
|
+
// ),
|
|
149
|
+
}
|
|
150
|
+
: null;
|
|
151
|
+
|
|
152
|
+
setHasMoreEarlier(!history.isEnd && hasNewMessages && !!nextAnchor);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
155
|
+
} finally {
|
|
156
|
+
isLoadingEarlierRef.current = false;
|
|
157
|
+
setIsLoadingEarlier(false);
|
|
158
|
+
}
|
|
159
|
+
}, [conversationId, pageSize]);
|
|
160
|
+
|
|
161
|
+
const sendTextMessage = useCallback(
|
|
162
|
+
async (text: string) => {
|
|
163
|
+
const trimmed = text.trim();
|
|
164
|
+
if (!trimmed) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const sentMessage = await ChatMessageAPI.sendTextMessage({
|
|
169
|
+
text: trimmed,
|
|
170
|
+
recvID,
|
|
171
|
+
groupID,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
setMessages((current) => mergeMessages(current, [sentMessage]));
|
|
175
|
+
},
|
|
176
|
+
[groupID, recvID]
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const appendIncomingMessages = useCallback(
|
|
180
|
+
(incoming: MessageItem[]) => {
|
|
181
|
+
const relevant = incoming.filter((message) =>
|
|
182
|
+
belongsToConversation(message, conversationIdRef.current, groupID)
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
if (!relevant.length) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
setMessages((current) =>
|
|
190
|
+
mergeMessages(current, relevant as DMessageItem[])
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
ChatMessageAPI.markConversationAsRead(conversationIdRef.current).catch(
|
|
194
|
+
() => undefined
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
[groupID]
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
resetState();
|
|
202
|
+
|
|
203
|
+
if (!enabled || !conversationId) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
loadInitialMessages();
|
|
208
|
+
}, [conversationId, enabled, loadInitialMessages, resetState]);
|
|
209
|
+
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (!enabled || !conversationId) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const handleNewMessages = (incoming: MessageItem[]) => {
|
|
216
|
+
appendIncomingMessages(incoming);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const handleNewMessage = (incoming: MessageItem) => {
|
|
220
|
+
appendIncomingMessages([incoming]);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
OpenIMSDK.on(OpenIMEvent.OnRecvNewMessages, handleNewMessages);
|
|
224
|
+
OpenIMSDK.on(OpenIMEvent.OnRecvNewMessage, handleNewMessage);
|
|
225
|
+
|
|
226
|
+
return () => {
|
|
227
|
+
OpenIMSDK.off(OpenIMEvent.OnRecvNewMessages, handleNewMessages);
|
|
228
|
+
OpenIMSDK.off(OpenIMEvent.OnRecvNewMessage, handleNewMessage);
|
|
229
|
+
};
|
|
230
|
+
}, [appendIncomingMessages, conversationId, enabled]);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
messages,
|
|
234
|
+
currentUserId,
|
|
235
|
+
isLoading,
|
|
236
|
+
isLoadingEarlier,
|
|
237
|
+
hasMoreEarlier,
|
|
238
|
+
error,
|
|
239
|
+
onLoadEarlier,
|
|
240
|
+
sendTextMessage,
|
|
241
|
+
refresh: loadInitialMessages,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import OpenIMSDK from '@droppii/openim-rn-client-sdk';
|
|
4
|
+
import { ChatAPI } from '../services';
|
|
5
|
+
import { conversationQueryKeys } from './query-keys';
|
|
6
|
+
import { useConversationStore } from '../store';
|
|
7
|
+
import { mergeOpenIMIntoConversation } from '../utils/conversation';
|
|
8
|
+
|
|
9
|
+
type Params = {
|
|
10
|
+
applicationType: string;
|
|
11
|
+
page: number;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function useConversationList({
|
|
16
|
+
applicationType,
|
|
17
|
+
page = 1,
|
|
18
|
+
enabled = true,
|
|
19
|
+
}: Params) {
|
|
20
|
+
const newConversationSignal = useConversationStore(
|
|
21
|
+
(s) => s.newConversationSignal
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const query = useQuery({
|
|
25
|
+
queryKey: [...conversationQueryKeys.list(applicationType), page],
|
|
26
|
+
enabled: enabled !== false,
|
|
27
|
+
queryFn: async () => {
|
|
28
|
+
const offset = (page - 1) * 20;
|
|
29
|
+
const [{ data: droppiiList }, openimList] = await Promise.all([
|
|
30
|
+
ChatAPI.queryConversations({ applicationType, page, pageSize: 20 }),
|
|
31
|
+
OpenIMSDK.getConversationListSplit({ offset, count: 20 }),
|
|
32
|
+
]);
|
|
33
|
+
const openimMap = new Map(openimList.map((c) => [c.conversationID, c]));
|
|
34
|
+
|
|
35
|
+
const merged = droppiiList.map((conv) => {
|
|
36
|
+
const openimConv = openimMap.get(conv.conversationId);
|
|
37
|
+
return openimConv
|
|
38
|
+
? mergeOpenIMIntoConversation(conv, openimConv)
|
|
39
|
+
: conv;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
useConversationStore.getState().updateConversations(merged);
|
|
43
|
+
return merged;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Refetch when a new conversation arrives from a realtime event that wasn't
|
|
48
|
+
// already in the store (signal is incremented by mergeOpenIMConversations).
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (newConversationSignal > 0) {
|
|
51
|
+
query.refetch();
|
|
52
|
+
}
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
}, [newConversationSignal]);
|
|
55
|
+
|
|
56
|
+
return query;
|
|
57
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { ChatAPI } from './services';
|
|
2
|
+
export * from './core';
|
|
3
|
+
export * from './store';
|
|
4
|
+
export * from './hooks/useConversationList';
|
|
5
|
+
export * from './hooks/useChatMessages';
|
|
6
|
+
export * from './types/chat';
|
|
7
|
+
export { Avatar } from './components/Avatar';
|
|
8
|
+
export { ThreadCard } from './components/ThreadCard';
|
|
9
|
+
export { Inbox } from './screens/inbox';
|
|
10
|
+
export {
|
|
11
|
+
ChatDetail,
|
|
12
|
+
ChatDetailHeader,
|
|
13
|
+
ChatList,
|
|
14
|
+
ChatComposer,
|
|
15
|
+
ChatQuickActions,
|
|
16
|
+
ChatAttachmentPanel,
|
|
17
|
+
DEFAULT_Chat_QUICK_ACTIONS,
|
|
18
|
+
DEFAULT_ATTACHMENT_ACTIONS,
|
|
19
|
+
} from './screens/chat-detail';
|
|
20
|
+
export type {
|
|
21
|
+
DChatActionItem,
|
|
22
|
+
DChatActionIconProvider,
|
|
23
|
+
DChatQuickAction,
|
|
24
|
+
DChatAttachmentAction,
|
|
25
|
+
ChatDetailProps,
|
|
26
|
+
ChatDetailHeaderProps,
|
|
27
|
+
ChatListProps,
|
|
28
|
+
ChatComposerProps,
|
|
29
|
+
ChatQuickActionsProps,
|
|
30
|
+
ChatAttachmentPanelProps,
|
|
31
|
+
} from './screens/chat-detail';
|
|
32
|
+
export type { DGiftedChatMessage } from './utils/giftedChatMessage';
|
|
33
|
+
export {
|
|
34
|
+
mapOpenIMMessageToGiftedChat,
|
|
35
|
+
mapOpenIMMessagesToGiftedChat,
|
|
36
|
+
} from './utils/giftedChatMessage';
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
2
|
+
import { FlatList, type ListRenderItem, StyleSheet } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
KContainer,
|
|
5
|
+
KImage,
|
|
6
|
+
KLabel,
|
|
7
|
+
KColors,
|
|
8
|
+
KSpacingValue,
|
|
9
|
+
} from '@droppii/libs';
|
|
10
|
+
import { ATTACHMENT_PANEL_COLUMNS } from './constants';
|
|
11
|
+
import { useChatActionPress } from './useChatActionPress';
|
|
12
|
+
import type { DChatAttachmentAction, ChatAttachmentPanelProps } from './types';
|
|
13
|
+
|
|
14
|
+
const AttachmentActionItem = memo(
|
|
15
|
+
({
|
|
16
|
+
action,
|
|
17
|
+
itemWidth,
|
|
18
|
+
onPress,
|
|
19
|
+
}: {
|
|
20
|
+
action: DChatAttachmentAction;
|
|
21
|
+
itemWidth: `${number}%`;
|
|
22
|
+
onPress: (action: DChatAttachmentAction) => void;
|
|
23
|
+
}) => {
|
|
24
|
+
const handlePress = useCallback(() => {
|
|
25
|
+
onPress(action);
|
|
26
|
+
}, [action, onPress]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<KContainer.Touchable
|
|
30
|
+
style={[styles.item, { width: itemWidth }]}
|
|
31
|
+
onPress={handlePress}
|
|
32
|
+
disabled={action.disabled}
|
|
33
|
+
activeOpacity={0.7}
|
|
34
|
+
>
|
|
35
|
+
<KContainer.View style={styles.iconCircle} center>
|
|
36
|
+
<KImage.VectorIcons
|
|
37
|
+
name={action.iconName}
|
|
38
|
+
provider={action.iconProvider ?? 'MaterialCommunityIcons'}
|
|
39
|
+
size={24}
|
|
40
|
+
color={
|
|
41
|
+
action.disabled ? KColors.palette.gray.w300 : KColors.gray.dark
|
|
42
|
+
}
|
|
43
|
+
/>
|
|
44
|
+
</KContainer.View>
|
|
45
|
+
<KLabel.Text
|
|
46
|
+
typo="TextXsMedium"
|
|
47
|
+
color={
|
|
48
|
+
action.disabled ? KColors.palette.gray.w300 : KColors.gray.dark
|
|
49
|
+
}
|
|
50
|
+
textAlign="center"
|
|
51
|
+
numberOfLines={2}
|
|
52
|
+
marginT="0.25rem"
|
|
53
|
+
>
|
|
54
|
+
{action.label}
|
|
55
|
+
</KLabel.Text>
|
|
56
|
+
</KContainer.Touchable>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
AttachmentActionItem.displayName = 'AttachmentActionItem';
|
|
62
|
+
|
|
63
|
+
export const ChatAttachmentPanel = memo(
|
|
64
|
+
({
|
|
65
|
+
actions,
|
|
66
|
+
columns = ATTACHMENT_PANEL_COLUMNS,
|
|
67
|
+
onActionPress,
|
|
68
|
+
renderAction,
|
|
69
|
+
}: ChatAttachmentPanelProps) => {
|
|
70
|
+
const handleActionPress = useChatActionPress(onActionPress);
|
|
71
|
+
|
|
72
|
+
const itemWidth = useMemo(
|
|
73
|
+
() => `${100 / columns}%` as `${number}%`,
|
|
74
|
+
[columns]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const renderItem = useCallback<ListRenderItem<DChatAttachmentAction>>(
|
|
78
|
+
({ item }) => {
|
|
79
|
+
const onPress = () => handleActionPress(item);
|
|
80
|
+
|
|
81
|
+
if (renderAction) {
|
|
82
|
+
return <>{renderAction(item, onPress)}</>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<AttachmentActionItem
|
|
87
|
+
action={item}
|
|
88
|
+
itemWidth={itemWidth}
|
|
89
|
+
onPress={handleActionPress}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
[handleActionPress, itemWidth, renderAction]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const keyExtractor = useCallback(
|
|
97
|
+
(item: DChatAttachmentAction) => item.id,
|
|
98
|
+
[]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
if (!actions?.length) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<KContainer.View background={KColors.white} flex>
|
|
107
|
+
<FlatList
|
|
108
|
+
data={actions}
|
|
109
|
+
renderItem={renderItem}
|
|
110
|
+
keyExtractor={keyExtractor}
|
|
111
|
+
numColumns={columns}
|
|
112
|
+
scrollEnabled={false}
|
|
113
|
+
contentContainerStyle={styles.grid}
|
|
114
|
+
columnWrapperStyle={columns > 1 ? styles.row : undefined}
|
|
115
|
+
/>
|
|
116
|
+
</KContainer.View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
ChatAttachmentPanel.displayName = 'ChatAttachmentPanel';
|
|
122
|
+
|
|
123
|
+
const styles = StyleSheet.create({
|
|
124
|
+
grid: {
|
|
125
|
+
paddingHorizontal: KSpacingValue['0.5rem'],
|
|
126
|
+
paddingTop: KSpacingValue['1.5rem'],
|
|
127
|
+
paddingBottom: KSpacingValue['0.5rem'],
|
|
128
|
+
},
|
|
129
|
+
row: {
|
|
130
|
+
justifyContent: 'flex-start',
|
|
131
|
+
},
|
|
132
|
+
item: {
|
|
133
|
+
alignItems: 'center',
|
|
134
|
+
marginBottom: KSpacingValue['1.5rem'],
|
|
135
|
+
},
|
|
136
|
+
iconCircle: {
|
|
137
|
+
width: 44,
|
|
138
|
+
height: 44,
|
|
139
|
+
borderRadius: 22,
|
|
140
|
+
backgroundColor: KColors.hexToRgba(KColors.gray.light, 0.1),
|
|
141
|
+
},
|
|
142
|
+
});
|