@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,164 @@
|
|
|
1
|
+
import { memo, useCallback, useState } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { TabView } from 'react-native-tab-view';
|
|
4
|
+
import { KContainer, KImage, KLabel, KColors } from '@droppii/libs';
|
|
5
|
+
import { MessagesTab } from './MessagesTab';
|
|
6
|
+
|
|
7
|
+
interface InboxProps {
|
|
8
|
+
applicationType: string;
|
|
9
|
+
onPressThread?: (item: string) => void;
|
|
10
|
+
onPressSearch?: () => void;
|
|
11
|
+
onPressEdit?: () => void;
|
|
12
|
+
onPressGroup?: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type TabRoute = { key: string; title: string };
|
|
16
|
+
|
|
17
|
+
const Inbox = memo(
|
|
18
|
+
({
|
|
19
|
+
applicationType,
|
|
20
|
+
onPressThread,
|
|
21
|
+
onPressSearch,
|
|
22
|
+
onPressEdit,
|
|
23
|
+
onPressGroup,
|
|
24
|
+
}: InboxProps) => {
|
|
25
|
+
const [index, setIndex] = useState(0);
|
|
26
|
+
const [routes] = useState<TabRoute[]>([
|
|
27
|
+
{ key: 'messages', title: 'Tin nhắn' },
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const renderScene = useCallback(
|
|
31
|
+
({ route }: { route: TabRoute }) => {
|
|
32
|
+
if (route.key === 'messages') {
|
|
33
|
+
return (
|
|
34
|
+
<MessagesTab
|
|
35
|
+
applicationType={applicationType}
|
|
36
|
+
onPressThread={onPressThread}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
},
|
|
42
|
+
[applicationType, onPressThread]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const renderTabBar = useCallback(
|
|
46
|
+
(props: { navigationState: { index: number; routes: TabRoute[] } }) => (
|
|
47
|
+
<KContainer.View row alignItems="center" style={styles.tabBar}>
|
|
48
|
+
{/* Tab labels */}
|
|
49
|
+
<KContainer.View row flex>
|
|
50
|
+
{props.navigationState.routes.map((route, i) => {
|
|
51
|
+
const isActive = props.navigationState.index === i;
|
|
52
|
+
return (
|
|
53
|
+
<KContainer.Touchable
|
|
54
|
+
key={route.key}
|
|
55
|
+
onPress={() => setIndex(i)}
|
|
56
|
+
paddingV="0.75rem"
|
|
57
|
+
marginR="1rem"
|
|
58
|
+
style={styles.tabItem}
|
|
59
|
+
activeOpacity={0.7}
|
|
60
|
+
>
|
|
61
|
+
<KLabel.Text
|
|
62
|
+
typo="TextNmBold"
|
|
63
|
+
color={
|
|
64
|
+
isActive
|
|
65
|
+
? KColors.palette.primary.w400
|
|
66
|
+
: KColors.palette.gray.w500
|
|
67
|
+
}
|
|
68
|
+
>
|
|
69
|
+
{route.title}
|
|
70
|
+
</KLabel.Text>
|
|
71
|
+
{isActive && (
|
|
72
|
+
<KContainer.View style={styles.activeIndicator} />
|
|
73
|
+
)}
|
|
74
|
+
</KContainer.Touchable>
|
|
75
|
+
);
|
|
76
|
+
})}
|
|
77
|
+
</KContainer.View>
|
|
78
|
+
|
|
79
|
+
{/* Action buttons */}
|
|
80
|
+
<KContainer.View row alignItems="center" style={styles.actionGroup}>
|
|
81
|
+
<KContainer.Touchable
|
|
82
|
+
onPress={onPressSearch}
|
|
83
|
+
padding="0.5rem"
|
|
84
|
+
activeOpacity={0.7}
|
|
85
|
+
>
|
|
86
|
+
<KImage.VectorIcons
|
|
87
|
+
name="magnify"
|
|
88
|
+
provider="MaterialCommunityIcons"
|
|
89
|
+
size={24}
|
|
90
|
+
color={KColors.palette.primary.w400}
|
|
91
|
+
/>
|
|
92
|
+
</KContainer.Touchable>
|
|
93
|
+
<KContainer.Touchable
|
|
94
|
+
onPress={onPressEdit}
|
|
95
|
+
padding="0.5rem"
|
|
96
|
+
activeOpacity={0.7}
|
|
97
|
+
>
|
|
98
|
+
<KImage.VectorIcons
|
|
99
|
+
name="square-edit-outline"
|
|
100
|
+
provider="MaterialCommunityIcons"
|
|
101
|
+
size={24}
|
|
102
|
+
color={KColors.palette.primary.w400}
|
|
103
|
+
/>
|
|
104
|
+
</KContainer.Touchable>
|
|
105
|
+
<KContainer.Touchable
|
|
106
|
+
onPress={onPressGroup}
|
|
107
|
+
padding="0.5rem"
|
|
108
|
+
activeOpacity={0.7}
|
|
109
|
+
>
|
|
110
|
+
<KImage.VectorIcons
|
|
111
|
+
name="account-group-outline"
|
|
112
|
+
provider="MaterialCommunityIcons"
|
|
113
|
+
size={24}
|
|
114
|
+
color={KColors.palette.primary.w400}
|
|
115
|
+
/>
|
|
116
|
+
</KContainer.Touchable>
|
|
117
|
+
</KContainer.View>
|
|
118
|
+
</KContainer.View>
|
|
119
|
+
),
|
|
120
|
+
[onPressSearch, onPressEdit, onPressGroup]
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<KContainer.Page flex edges={['top', 'bottom']}>
|
|
125
|
+
<TabView
|
|
126
|
+
navigationState={{ index, routes }}
|
|
127
|
+
renderScene={renderScene}
|
|
128
|
+
renderTabBar={renderTabBar}
|
|
129
|
+
onIndexChange={setIndex}
|
|
130
|
+
swipeEnabled={routes.length > 1}
|
|
131
|
+
/>
|
|
132
|
+
</KContainer.Page>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
Inbox.displayName = 'Inbox';
|
|
138
|
+
|
|
139
|
+
export default Inbox;
|
|
140
|
+
|
|
141
|
+
const styles = StyleSheet.create({
|
|
142
|
+
tabBar: {
|
|
143
|
+
borderBottomWidth: 0.5,
|
|
144
|
+
borderBottomColor: KColors.palette.gray.w100,
|
|
145
|
+
paddingHorizontal: 12,
|
|
146
|
+
},
|
|
147
|
+
tabItem: {
|
|
148
|
+
position: 'relative',
|
|
149
|
+
paddingTop: 2,
|
|
150
|
+
paddingBottom: 0,
|
|
151
|
+
},
|
|
152
|
+
activeIndicator: {
|
|
153
|
+
position: 'absolute',
|
|
154
|
+
bottom: 0,
|
|
155
|
+
left: 0,
|
|
156
|
+
right: 0,
|
|
157
|
+
height: 3,
|
|
158
|
+
borderRadius: 4,
|
|
159
|
+
backgroundColor: KColors.palette.primary.w400,
|
|
160
|
+
},
|
|
161
|
+
actionGroup: {
|
|
162
|
+
gap: 4,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { memo, useCallback } from 'react';
|
|
2
|
+
import { GestureResponderEvent } from 'react-native';
|
|
3
|
+
import { KContainer, KDivider, KLabel, KColors } from '@droppii/libs';
|
|
4
|
+
import { useConversationList } from '../../hooks/useConversationList';
|
|
5
|
+
import { ThreadCard } from '../../components/ThreadCard';
|
|
6
|
+
import { useConversationStore } from '../../store';
|
|
7
|
+
|
|
8
|
+
interface MessagesTabProps {
|
|
9
|
+
applicationType: string;
|
|
10
|
+
onPressThread?: (item: string) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Separator = () => <KDivider type="line" size="hairline" />;
|
|
14
|
+
const keyExtractor = (item: string) => item;
|
|
15
|
+
|
|
16
|
+
export const MessagesTab = memo(
|
|
17
|
+
({ applicationType, onPressThread }: MessagesTabProps) => {
|
|
18
|
+
const data = useConversationStore((state) => state.list);
|
|
19
|
+
|
|
20
|
+
const { isLoading, refetch, isRefetching } = useConversationList({
|
|
21
|
+
applicationType,
|
|
22
|
+
page: 1,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const handleThreadPress = useCallback(
|
|
26
|
+
(params: { item: string; event: GestureResponderEvent }) => {
|
|
27
|
+
onPressThread?.(params.item);
|
|
28
|
+
},
|
|
29
|
+
[onPressThread]
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const renderItem = useCallback(
|
|
33
|
+
({ item }: { item: string }) => (
|
|
34
|
+
<ThreadCard item={item} onPress={handleThreadPress} />
|
|
35
|
+
),
|
|
36
|
+
[handleThreadPress]
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const EmptyComponent = isLoading ? null : (
|
|
40
|
+
<KContainer.View center flex paddingV="3rem">
|
|
41
|
+
<KLabel.Text typo="TextSmNormal" color={KColors.palette.gray.w400}>
|
|
42
|
+
Không có tin nhắn nào
|
|
43
|
+
</KLabel.Text>
|
|
44
|
+
</KContainer.View>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<KContainer.FlatList
|
|
49
|
+
data={data}
|
|
50
|
+
renderItem={renderItem}
|
|
51
|
+
keyExtractor={keyExtractor}
|
|
52
|
+
ItemSeparatorComponent={Separator}
|
|
53
|
+
ListEmptyComponent={EmptyComponent}
|
|
54
|
+
refreshing={isRefetching}
|
|
55
|
+
onRefresh={refetch}
|
|
56
|
+
showsVerticalScrollIndicator={false}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
MessagesTab.displayName = 'MessagesTab';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
import type {
|
|
3
|
+
DConversationItem,
|
|
4
|
+
DConversationQueryParams,
|
|
5
|
+
} from '../types/chat';
|
|
6
|
+
import OpenIMSDK, { LoginStatus } from '@droppii/openim-rn-client-sdk';
|
|
7
|
+
import type { BaseResponse, GetOpenIMTokenResponse } from '../types/auth';
|
|
8
|
+
import { Platform } from 'react-native';
|
|
9
|
+
|
|
10
|
+
let apiInstance: AxiosInstance | null = null;
|
|
11
|
+
|
|
12
|
+
export namespace ChatAPI {
|
|
13
|
+
export function initApiInstance(api: AxiosInstance): void {
|
|
14
|
+
apiInstance = api;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getLoginStatus = async (operationID?: string) => {
|
|
18
|
+
return (await OpenIMSDK.getLoginStatus(operationID)) === LoginStatus.Logged;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const login = async (
|
|
22
|
+
instance: AxiosInstance,
|
|
23
|
+
operationID?: string
|
|
24
|
+
) => {
|
|
25
|
+
const isLoggedIn = await getLoginStatus(operationID);
|
|
26
|
+
|
|
27
|
+
if (isLoggedIn) return;
|
|
28
|
+
|
|
29
|
+
const response = await instance.post<BaseResponse<GetOpenIMTokenResponse>>(
|
|
30
|
+
`/chat-service/v1/auth/token?platform=${Platform.OS.toUpperCase()}`
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const token = response?.data?.data;
|
|
34
|
+
|
|
35
|
+
if (token == null) return;
|
|
36
|
+
|
|
37
|
+
return OpenIMSDK.login({ userID: token.id, token: token.token });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const logout = async (operationID?: string) => {
|
|
41
|
+
return OpenIMSDK.logout(operationID);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const getUser = async (operationID?: string | undefined) => {
|
|
45
|
+
return OpenIMSDK.getSelfUserInfo(operationID);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export async function queryConversations(params: DConversationQueryParams) {
|
|
49
|
+
if (!apiInstance) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'apiInstance is not initialized. Call initApiInstance() first.'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const response = await apiInstance.post<BaseResponse<DConversationItem[]>>(
|
|
55
|
+
'/chat-service/v1/app/conversations/query',
|
|
56
|
+
params
|
|
57
|
+
);
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import OpenIMSDK, {
|
|
2
|
+
ViewType,
|
|
3
|
+
type AdvancedGetMessageResult,
|
|
4
|
+
type MessageItem,
|
|
5
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
6
|
+
import type { DMessageItem } from '../types/chat';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_PAGE_SIZE = 20;
|
|
9
|
+
|
|
10
|
+
export type HistoryMessageResult = AdvancedGetMessageResult & {
|
|
11
|
+
lastMinSeq?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export namespace ChatMessageAPI {
|
|
15
|
+
export async function fetchHistoryMessages(
|
|
16
|
+
conversationID: string,
|
|
17
|
+
options?: {
|
|
18
|
+
count?: number;
|
|
19
|
+
startClientMsgID?: string;
|
|
20
|
+
lastMinSeq?: number;
|
|
21
|
+
}
|
|
22
|
+
): Promise<HistoryMessageResult> {
|
|
23
|
+
return OpenIMSDK.getAdvancedHistoryMessageList({
|
|
24
|
+
conversationID,
|
|
25
|
+
count: options?.count ?? DEFAULT_PAGE_SIZE,
|
|
26
|
+
startClientMsgID: options?.startClientMsgID ?? '',
|
|
27
|
+
viewType: ViewType.History,
|
|
28
|
+
// ...(options?.startClientMsgID
|
|
29
|
+
// ? { lastMinSeq: options.lastMinSeq ?? 0 }
|
|
30
|
+
// : {}),
|
|
31
|
+
} as Parameters<
|
|
32
|
+
typeof OpenIMSDK.getAdvancedHistoryMessageList
|
|
33
|
+
>[0]) as Promise<HistoryMessageResult>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function sendTextMessage(params: {
|
|
37
|
+
text: string;
|
|
38
|
+
recvID?: string;
|
|
39
|
+
groupID?: string;
|
|
40
|
+
}): Promise<DMessageItem> {
|
|
41
|
+
const message = await OpenIMSDK.createTextMessage(params.text);
|
|
42
|
+
|
|
43
|
+
const sentMessage = await OpenIMSDK.sendMessage({
|
|
44
|
+
recvID: params.recvID ?? '',
|
|
45
|
+
groupID: params.groupID ?? '',
|
|
46
|
+
message,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return sentMessage;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function markConversationAsRead(conversationID: string) {
|
|
53
|
+
return OpenIMSDK.markConversationMessageAsRead(conversationID);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function getCurrentUserId() {
|
|
57
|
+
return OpenIMSDK.getLoginUserID();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type { MessageItem };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import {
|
|
3
|
+
dConversationCompare,
|
|
4
|
+
mergeOpenIMIntoConversation,
|
|
5
|
+
} from '../utils/conversation';
|
|
6
|
+
import type { DConversationItem } from '../types/chat';
|
|
7
|
+
import type {
|
|
8
|
+
ConversationItem,
|
|
9
|
+
MessageItem,
|
|
10
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
11
|
+
|
|
12
|
+
type ConversationID = string;
|
|
13
|
+
|
|
14
|
+
export interface ConversationStore {
|
|
15
|
+
currentConversationId?: ConversationID;
|
|
16
|
+
setCurrentConversation(id: ConversationID): void;
|
|
17
|
+
getCurrentConversation(): DConversationItem | undefined;
|
|
18
|
+
list: ConversationID[];
|
|
19
|
+
map: Record<ConversationID, DConversationItem>;
|
|
20
|
+
/** Signal incremented when a truly new conversation arrives and a full refetch is needed. */
|
|
21
|
+
newConversationSignal: number;
|
|
22
|
+
updateConversations(conversations: DConversationItem[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Patches existing conversations with real-time data from OpenIM events.
|
|
25
|
+
* Returns true if any conversation was not found in the store (triggers refetch).
|
|
26
|
+
*/
|
|
27
|
+
mergeOpenIMConversations(conversations: ConversationItem[]): boolean;
|
|
28
|
+
removeConversation(id: ConversationID): void;
|
|
29
|
+
updateLastMessage(id: ConversationID, message: MessageItem): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const useConversationStore = create<ConversationStore>()((set, get) => ({
|
|
33
|
+
list: [],
|
|
34
|
+
map: {},
|
|
35
|
+
newConversationSignal: 0,
|
|
36
|
+
setCurrentConversation(id) {
|
|
37
|
+
set({ currentConversationId: id });
|
|
38
|
+
},
|
|
39
|
+
getCurrentConversation() {
|
|
40
|
+
const id = get().currentConversationId;
|
|
41
|
+
if (id == null) return;
|
|
42
|
+
|
|
43
|
+
return get().map[id];
|
|
44
|
+
},
|
|
45
|
+
updateConversations(conversations) {
|
|
46
|
+
const newMap = conversations.reduce(
|
|
47
|
+
(pre, curr) => {
|
|
48
|
+
pre[curr.conversationId] = curr;
|
|
49
|
+
return pre;
|
|
50
|
+
},
|
|
51
|
+
{ ...get().map }
|
|
52
|
+
);
|
|
53
|
+
const newList = Object.keys(newMap).sort((a, b) =>
|
|
54
|
+
dConversationCompare(newMap[a]!, newMap[b]!)
|
|
55
|
+
);
|
|
56
|
+
set({
|
|
57
|
+
map: newMap,
|
|
58
|
+
list: newList,
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
mergeOpenIMConversations(conversations) {
|
|
62
|
+
const currentMap = get().map;
|
|
63
|
+
let hasUnknown = false;
|
|
64
|
+
let changed = false;
|
|
65
|
+
|
|
66
|
+
const nextMap = { ...currentMap };
|
|
67
|
+
for (const openim of conversations) {
|
|
68
|
+
const existing = currentMap[openim.conversationID];
|
|
69
|
+
if (existing == null) {
|
|
70
|
+
hasUnknown = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
nextMap[openim.conversationID] = mergeOpenIMIntoConversation(
|
|
74
|
+
existing,
|
|
75
|
+
openim
|
|
76
|
+
);
|
|
77
|
+
changed = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (changed) {
|
|
81
|
+
const newList = Object.keys(nextMap).sort((a, b) =>
|
|
82
|
+
dConversationCompare(nextMap[a]!, nextMap[b]!)
|
|
83
|
+
);
|
|
84
|
+
set({ map: nextMap, list: newList });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (hasUnknown) {
|
|
88
|
+
set((s) => ({ newConversationSignal: s.newConversationSignal + 1 }));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return hasUnknown;
|
|
92
|
+
},
|
|
93
|
+
removeConversation(id) {
|
|
94
|
+
const newMap = { ...get().map };
|
|
95
|
+
delete newMap[id];
|
|
96
|
+
|
|
97
|
+
set({
|
|
98
|
+
map: newMap,
|
|
99
|
+
list: get().list.filter((item) => item !== id),
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
updateLastMessage(id, message) {
|
|
103
|
+
const conversation = get().map[id];
|
|
104
|
+
if (conversation == null) return;
|
|
105
|
+
set({
|
|
106
|
+
map: {
|
|
107
|
+
[id]: { ...conversation, lastMessage: message },
|
|
108
|
+
...get().map,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
export const useConversation = (id: string): DConversationItem | undefined => {
|
|
115
|
+
return useConversationStore((state) => state.map[id]);
|
|
116
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
2
|
+
import { createJSONStorage, type StateStorage } from 'zustand/middleware';
|
|
3
|
+
|
|
4
|
+
const storage = createMMKV();
|
|
5
|
+
|
|
6
|
+
export const stateStorage: StateStorage<void> = {
|
|
7
|
+
setItem: (key, value) => {
|
|
8
|
+
return storage.set(key, value);
|
|
9
|
+
},
|
|
10
|
+
getItem: (key) => {
|
|
11
|
+
const value = storage.getString(key);
|
|
12
|
+
return value ?? null;
|
|
13
|
+
},
|
|
14
|
+
removeItem: (key) => {
|
|
15
|
+
return storage.remove(key);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const zustandStorage = createJSONStorage(() => stateStorage);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { LoginStatus, type SelfUserInfo } from '@droppii/openim-rn-client-sdk';
|
|
3
|
+
import { SyncStatus } from '../types/auth';
|
|
4
|
+
|
|
5
|
+
export interface UserStore {
|
|
6
|
+
user?: SelfUserInfo;
|
|
7
|
+
setUser: (user: SelfUserInfo) => void;
|
|
8
|
+
connectStatus: LoginStatus;
|
|
9
|
+
updateConnectStatus: (status: LoginStatus) => void;
|
|
10
|
+
syncStatus: SyncStatus;
|
|
11
|
+
updateSyncStatus: (status: SyncStatus) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const useUserStore = create<UserStore>()((set) => ({
|
|
15
|
+
connectStatus: LoginStatus.Logout,
|
|
16
|
+
syncStatus: SyncStatus.Loading,
|
|
17
|
+
setUser(user) {
|
|
18
|
+
set({ user });
|
|
19
|
+
},
|
|
20
|
+
updateConnectStatus(connectStatus) {
|
|
21
|
+
set({ connectStatus });
|
|
22
|
+
},
|
|
23
|
+
updateSyncStatus(syncStatus) {
|
|
24
|
+
set({ syncStatus });
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import i18n from './resources/i18n';
|
|
2
|
+
|
|
3
|
+
export const replaceAll = (
|
|
4
|
+
target: string | undefined,
|
|
5
|
+
oldStr: string,
|
|
6
|
+
newStr: string
|
|
7
|
+
) => {
|
|
8
|
+
return typeof target === 'string'
|
|
9
|
+
? target?.replace(new RegExp(oldStr, 'g'), newStr) || newStr
|
|
10
|
+
: '';
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const replaceMulti = (target: string | undefined, param: any) => {
|
|
14
|
+
if (typeof target !== 'string') {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
let out = target;
|
|
18
|
+
for (const key in param) {
|
|
19
|
+
if (key) {
|
|
20
|
+
const textReplace = '{{' + key + '}}';
|
|
21
|
+
out = replaceAll(out, textReplace, String(param[key]));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const trans = (key: string, params?: Record<string, any>) => {
|
|
28
|
+
const text = i18n?.vi?.[key] || '';
|
|
29
|
+
return params ? replaceMulti(text, params) : text;
|
|
30
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type BaseResponse<T = unknown> = {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
message: string | null;
|
|
4
|
+
metadata: unknown;
|
|
5
|
+
pageable: Pageable;
|
|
6
|
+
data: T;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type Pageable = {
|
|
10
|
+
pageNumber: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
totalPages: number;
|
|
13
|
+
totalElements: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type GetOpenIMTokenResponse = {
|
|
17
|
+
id: string;
|
|
18
|
+
token: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export enum SyncStatus {
|
|
22
|
+
Loading = 0,
|
|
23
|
+
Success = 1,
|
|
24
|
+
Failed = 2,
|
|
25
|
+
}
|