@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.
Files changed (294) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +101 -0
  3. package/lib/module/assets/images/icon_bot.png +0 -0
  4. package/lib/module/assets/images/index.js +9 -0
  5. package/lib/module/assets/images/index.js.map +1 -0
  6. package/lib/module/assets/images/tag_bot.png +0 -0
  7. package/lib/module/assets/images/tag_mall.png +0 -0
  8. package/lib/module/build-ignore.d.js +2 -0
  9. package/lib/module/build-ignore.d.js.map +1 -0
  10. package/lib/module/components/Avatar/Avatar.js +81 -0
  11. package/lib/module/components/Avatar/Avatar.js.map +1 -0
  12. package/lib/module/components/Avatar/Avatar.types.js +2 -0
  13. package/lib/module/components/Avatar/Avatar.types.js.map +1 -0
  14. package/lib/module/components/Avatar/Avatar.utils.js +44 -0
  15. package/lib/module/components/Avatar/Avatar.utils.js.map +1 -0
  16. package/lib/module/components/Avatar/AvatarBadge.js +28 -0
  17. package/lib/module/components/Avatar/AvatarBadge.js.map +1 -0
  18. package/lib/module/components/Avatar/DoubleAvatar.js +74 -0
  19. package/lib/module/components/Avatar/DoubleAvatar.js.map +1 -0
  20. package/lib/module/components/Avatar/SingleAvatar.js +53 -0
  21. package/lib/module/components/Avatar/SingleAvatar.js.map +1 -0
  22. package/lib/module/components/Avatar/index.js +7 -0
  23. package/lib/module/components/Avatar/index.js.map +1 -0
  24. package/lib/module/components/ThreadCard/AvatarSection.js +37 -0
  25. package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -0
  26. package/lib/module/components/ThreadCard/NamePrefixIcon.js +36 -0
  27. package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -0
  28. package/lib/module/components/ThreadCard/ThreadCard.js +132 -0
  29. package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -0
  30. package/lib/module/components/ThreadCard/UnreadBadge.js +35 -0
  31. package/lib/module/components/ThreadCard/UnreadBadge.js.map +1 -0
  32. package/lib/module/components/ThreadCard/index.js +7 -0
  33. package/lib/module/components/ThreadCard/index.js.map +1 -0
  34. package/lib/module/components/ThreadCard/thread-card.utils.js +51 -0
  35. package/lib/module/components/ThreadCard/thread-card.utils.js.map +1 -0
  36. package/lib/module/core/index.js +11 -0
  37. package/lib/module/core/index.js.map +1 -0
  38. package/lib/module/core/useChatListener.js +62 -0
  39. package/lib/module/core/useChatListener.js.map +1 -0
  40. package/lib/module/core/useUserListener.js +72 -0
  41. package/lib/module/core/useUserListener.js.map +1 -0
  42. package/lib/module/hooks/query-keys.js +10 -0
  43. package/lib/module/hooks/query-keys.js.map +1 -0
  44. package/lib/module/hooks/useChatMessages.js +163 -0
  45. package/lib/module/hooks/useChatMessages.js.map +1 -0
  46. package/lib/module/hooks/useConversationList.js +51 -0
  47. package/lib/module/hooks/useConversationList.js.map +1 -0
  48. package/lib/module/index.js +14 -0
  49. package/lib/module/index.js.map +1 -0
  50. package/lib/module/package.json +1 -0
  51. package/lib/module/screens/chat-detail/ChatAttachmentPanel.js +106 -0
  52. package/lib/module/screens/chat-detail/ChatAttachmentPanel.js.map +1 -0
  53. package/lib/module/screens/chat-detail/ChatComposer.js +288 -0
  54. package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -0
  55. package/lib/module/screens/chat-detail/ChatDay.js +65 -0
  56. package/lib/module/screens/chat-detail/ChatDay.js.map +1 -0
  57. package/lib/module/screens/chat-detail/ChatDetail.js +104 -0
  58. package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -0
  59. package/lib/module/screens/chat-detail/ChatDetailHeader.js +92 -0
  60. package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -0
  61. package/lib/module/screens/chat-detail/ChatList.js +145 -0
  62. package/lib/module/screens/chat-detail/ChatList.js.map +1 -0
  63. package/lib/module/screens/chat-detail/ChatLoadEarlier.js +23 -0
  64. package/lib/module/screens/chat-detail/ChatLoadEarlier.js.map +1 -0
  65. package/lib/module/screens/chat-detail/ChatQuickActions.js +85 -0
  66. package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -0
  67. package/lib/module/screens/chat-detail/ChatScrollToBottom.js +12 -0
  68. package/lib/module/screens/chat-detail/ChatScrollToBottom.js.map +1 -0
  69. package/lib/module/screens/chat-detail/ChatTextBubble.js +62 -0
  70. package/lib/module/screens/chat-detail/ChatTextBubble.js.map +1 -0
  71. package/lib/module/screens/chat-detail/constants.js +59 -0
  72. package/lib/module/screens/chat-detail/constants.js.map +1 -0
  73. package/lib/module/screens/chat-detail/index.js +12 -0
  74. package/lib/module/screens/chat-detail/index.js.map +1 -0
  75. package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js +24 -0
  76. package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js.map +1 -0
  77. package/lib/module/screens/chat-detail/messages/types.js +4 -0
  78. package/lib/module/screens/chat-detail/messages/types.js.map +1 -0
  79. package/lib/module/screens/chat-detail/types.js +4 -0
  80. package/lib/module/screens/chat-detail/types.js.map +1 -0
  81. package/lib/module/screens/chat-detail/useChatActionPress.js +11 -0
  82. package/lib/module/screens/chat-detail/useChatActionPress.js.map +1 -0
  83. package/lib/module/screens/inbox/Inbox.js +134 -0
  84. package/lib/module/screens/inbox/Inbox.js.map +1 -0
  85. package/lib/module/screens/inbox/MessagesTab.js +58 -0
  86. package/lib/module/screens/inbox/MessagesTab.js.map +1 -0
  87. package/lib/module/screens/inbox/index.js +5 -0
  88. package/lib/module/screens/inbox/index.js.map +1 -0
  89. package/lib/module/services/apis.js +41 -0
  90. package/lib/module/services/apis.js.map +1 -0
  91. package/lib/module/services/index.js +5 -0
  92. package/lib/module/services/index.js.map +1 -0
  93. package/lib/module/services/message.js +38 -0
  94. package/lib/module/services/message.js.map +1 -0
  95. package/lib/module/store/conversation.js +89 -0
  96. package/lib/module/store/conversation.js.map +1 -0
  97. package/lib/module/store/index.js +6 -0
  98. package/lib/module/store/index.js.map +1 -0
  99. package/lib/module/store/storeConfig.js +19 -0
  100. package/lib/module/store/storeConfig.js.map +1 -0
  101. package/lib/module/store/user.js +25 -0
  102. package/lib/module/store/user.js.map +1 -0
  103. package/lib/module/translation/index.js +24 -0
  104. package/lib/module/translation/index.js.map +1 -0
  105. package/lib/module/translation/resources/i18n.js +10 -0
  106. package/lib/module/translation/resources/i18n.js.map +1 -0
  107. package/lib/module/types/auth.js +9 -0
  108. package/lib/module/types/auth.js.map +1 -0
  109. package/lib/module/types/chat.js +26 -0
  110. package/lib/module/types/chat.js.map +1 -0
  111. package/lib/module/types/message.js +16 -0
  112. package/lib/module/types/message.js.map +1 -0
  113. package/lib/module/utils/conversation.js +61 -0
  114. package/lib/module/utils/conversation.js.map +1 -0
  115. package/lib/module/utils/giftedChatMessage.js +90 -0
  116. package/lib/module/utils/giftedChatMessage.js.map +1 -0
  117. package/lib/module/utils/message.js +68 -0
  118. package/lib/module/utils/message.js.map +1 -0
  119. package/lib/module/utils/resolveMessageType.js +44 -0
  120. package/lib/module/utils/resolveMessageType.js.map +1 -0
  121. package/lib/typescript/package.json +1 -0
  122. package/lib/typescript/src/assets/images/index.d.ts +7 -0
  123. package/lib/typescript/src/assets/images/index.d.ts.map +1 -0
  124. package/lib/typescript/src/components/Avatar/Avatar.d.ts +4 -0
  125. package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -0
  126. package/lib/typescript/src/components/Avatar/Avatar.types.d.ts +18 -0
  127. package/lib/typescript/src/components/Avatar/Avatar.types.d.ts.map +1 -0
  128. package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts +14 -0
  129. package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts.map +1 -0
  130. package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts +7 -0
  131. package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts.map +1 -0
  132. package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts +13 -0
  133. package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -0
  134. package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts +12 -0
  135. package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts.map +1 -0
  136. package/lib/typescript/src/components/Avatar/index.d.ts +6 -0
  137. package/lib/typescript/src/components/Avatar/index.d.ts.map +1 -0
  138. package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +8 -0
  139. package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -0
  140. package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +8 -0
  141. package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -0
  142. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts +11 -0
  143. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -0
  144. package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts +6 -0
  145. package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts.map +1 -0
  146. package/lib/typescript/src/components/ThreadCard/index.d.ts +5 -0
  147. package/lib/typescript/src/components/ThreadCard/index.d.ts.map +1 -0
  148. package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts +4 -0
  149. package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts.map +1 -0
  150. package/lib/typescript/src/core/index.d.ts +3 -0
  151. package/lib/typescript/src/core/index.d.ts.map +1 -0
  152. package/lib/typescript/src/core/useChatListener.d.ts +2 -0
  153. package/lib/typescript/src/core/useChatListener.d.ts.map +1 -0
  154. package/lib/typescript/src/core/useUserListener.d.ts +2 -0
  155. package/lib/typescript/src/core/useUserListener.d.ts.map +1 -0
  156. package/lib/typescript/src/hooks/query-keys.d.ts +9 -0
  157. package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -0
  158. package/lib/typescript/src/hooks/useChatMessages.d.ts +21 -0
  159. package/lib/typescript/src/hooks/useChatMessages.d.ts.map +1 -0
  160. package/lib/typescript/src/hooks/useConversationList.d.ts +8 -0
  161. package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -0
  162. package/lib/typescript/src/index.d.ts +14 -0
  163. package/lib/typescript/src/index.d.ts.map +1 -0
  164. package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +3 -0
  165. package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -0
  166. package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +3 -0
  167. package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -0
  168. package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +3 -0
  169. package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +1 -0
  170. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +4 -0
  171. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -0
  172. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +4 -0
  173. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -0
  174. package/lib/typescript/src/screens/chat-detail/ChatList.d.ts +3 -0
  175. package/lib/typescript/src/screens/chat-detail/ChatList.d.ts.map +1 -0
  176. package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +3 -0
  177. package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -0
  178. package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +3 -0
  179. package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -0
  180. package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts +2 -0
  181. package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts.map +1 -0
  182. package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts +3 -0
  183. package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts.map +1 -0
  184. package/lib/typescript/src/screens/chat-detail/constants.d.ts +17 -0
  185. package/lib/typescript/src/screens/chat-detail/constants.d.ts.map +1 -0
  186. package/lib/typescript/src/screens/chat-detail/index.d.ts +13 -0
  187. package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -0
  188. package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts +3 -0
  189. package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts.map +1 -0
  190. package/lib/typescript/src/screens/chat-detail/messages/types.d.ts +13 -0
  191. package/lib/typescript/src/screens/chat-detail/messages/types.d.ts.map +1 -0
  192. package/lib/typescript/src/screens/chat-detail/types.d.ts +86 -0
  193. package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -0
  194. package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts +3 -0
  195. package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts.map +1 -0
  196. package/lib/typescript/src/screens/inbox/Inbox.d.ts +10 -0
  197. package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -0
  198. package/lib/typescript/src/screens/inbox/MessagesTab.d.ts +7 -0
  199. package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -0
  200. package/lib/typescript/src/screens/inbox/index.d.ts +3 -0
  201. package/lib/typescript/src/screens/inbox/index.d.ts.map +1 -0
  202. package/lib/typescript/src/services/apis.d.ts +12 -0
  203. package/lib/typescript/src/services/apis.d.ts.map +1 -0
  204. package/lib/typescript/src/services/index.d.ts +3 -0
  205. package/lib/typescript/src/services/index.d.ts.map +1 -0
  206. package/lib/typescript/src/services/message.d.ts +21 -0
  207. package/lib/typescript/src/services/message.d.ts.map +1 -0
  208. package/lib/typescript/src/store/conversation.d.ts +24 -0
  209. package/lib/typescript/src/store/conversation.d.ts.map +1 -0
  210. package/lib/typescript/src/store/index.d.ts +4 -0
  211. package/lib/typescript/src/store/index.d.ts.map +1 -0
  212. package/lib/typescript/src/store/storeConfig.d.ts +4 -0
  213. package/lib/typescript/src/store/storeConfig.d.ts.map +1 -0
  214. package/lib/typescript/src/store/user.d.ts +12 -0
  215. package/lib/typescript/src/store/user.d.ts.map +1 -0
  216. package/lib/typescript/src/translation/index.d.ts +4 -0
  217. package/lib/typescript/src/translation/index.d.ts.map +1 -0
  218. package/lib/typescript/src/translation/resources/i18n.d.ts +5 -0
  219. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -0
  220. package/lib/typescript/src/types/auth.d.ts +24 -0
  221. package/lib/typescript/src/types/auth.d.ts.map +1 -0
  222. package/lib/typescript/src/types/chat.d.ts +99 -0
  223. package/lib/typescript/src/types/chat.d.ts.map +1 -0
  224. package/lib/typescript/src/types/message.d.ts +15 -0
  225. package/lib/typescript/src/types/message.d.ts.map +1 -0
  226. package/lib/typescript/src/utils/conversation.d.ts +10 -0
  227. package/lib/typescript/src/utils/conversation.d.ts.map +1 -0
  228. package/lib/typescript/src/utils/giftedChatMessage.d.ts +10 -0
  229. package/lib/typescript/src/utils/giftedChatMessage.d.ts.map +1 -0
  230. package/lib/typescript/src/utils/message.d.ts +15 -0
  231. package/lib/typescript/src/utils/message.d.ts.map +1 -0
  232. package/lib/typescript/src/utils/resolveMessageType.d.ts +4 -0
  233. package/lib/typescript/src/utils/resolveMessageType.d.ts.map +1 -0
  234. package/package.json +209 -0
  235. package/src/assets/images/icon_bot.png +0 -0
  236. package/src/assets/images/index.ts +7 -0
  237. package/src/assets/images/tag_bot.png +0 -0
  238. package/src/assets/images/tag_mall.png +0 -0
  239. package/src/build-ignore.d.ts +24 -0
  240. package/src/components/Avatar/Avatar.tsx +105 -0
  241. package/src/components/Avatar/Avatar.types.ts +17 -0
  242. package/src/components/Avatar/Avatar.utils.ts +49 -0
  243. package/src/components/Avatar/AvatarBadge.tsx +29 -0
  244. package/src/components/Avatar/DoubleAvatar.tsx +89 -0
  245. package/src/components/Avatar/SingleAvatar.tsx +74 -0
  246. package/src/components/Avatar/index.ts +5 -0
  247. package/src/components/ThreadCard/AvatarSection.tsx +42 -0
  248. package/src/components/ThreadCard/NamePrefixIcon.tsx +45 -0
  249. package/src/components/ThreadCard/ThreadCard.tsx +145 -0
  250. package/src/components/ThreadCard/UnreadBadge.tsx +35 -0
  251. package/src/components/ThreadCard/index.ts +4 -0
  252. package/src/components/ThreadCard/thread-card.utils.ts +68 -0
  253. package/src/core/index.ts +10 -0
  254. package/src/core/useChatListener.ts +85 -0
  255. package/src/core/useUserListener.ts +86 -0
  256. package/src/hooks/query-keys.ts +11 -0
  257. package/src/hooks/useChatMessages.ts +243 -0
  258. package/src/hooks/useConversationList.ts +57 -0
  259. package/src/index.tsx +36 -0
  260. package/src/screens/chat-detail/ChatAttachmentPanel.tsx +142 -0
  261. package/src/screens/chat-detail/ChatComposer.tsx +412 -0
  262. package/src/screens/chat-detail/ChatDay.tsx +73 -0
  263. package/src/screens/chat-detail/ChatDetail.tsx +118 -0
  264. package/src/screens/chat-detail/ChatDetailHeader.tsx +114 -0
  265. package/src/screens/chat-detail/ChatList.tsx +187 -0
  266. package/src/screens/chat-detail/ChatLoadEarlier.tsx +20 -0
  267. package/src/screens/chat-detail/ChatQuickActions.tsx +108 -0
  268. package/src/screens/chat-detail/ChatScrollToBottom.tsx +8 -0
  269. package/src/screens/chat-detail/ChatTextBubble.tsx +73 -0
  270. package/src/screens/chat-detail/constants.ts +76 -0
  271. package/src/screens/chat-detail/index.ts +33 -0
  272. package/src/screens/chat-detail/messages/ChatMessageBubble.tsx +24 -0
  273. package/src/screens/chat-detail/messages/types.ts +14 -0
  274. package/src/screens/chat-detail/types.ts +97 -0
  275. package/src/screens/chat-detail/useChatActionPress.ts +17 -0
  276. package/src/screens/inbox/Inbox.tsx +164 -0
  277. package/src/screens/inbox/MessagesTab.tsx +62 -0
  278. package/src/screens/inbox/index.ts +2 -0
  279. package/src/services/apis.ts +60 -0
  280. package/src/services/index.ts +2 -0
  281. package/src/services/message.ts +61 -0
  282. package/src/store/conversation.ts +116 -0
  283. package/src/store/index.ts +3 -0
  284. package/src/store/storeConfig.ts +19 -0
  285. package/src/store/user.ts +26 -0
  286. package/src/translation/index.ts +30 -0
  287. package/src/translation/resources/i18n.ts +8 -0
  288. package/src/types/auth.ts +25 -0
  289. package/src/types/chat.ts +118 -0
  290. package/src/types/message.ts +17 -0
  291. package/src/utils/conversation.ts +106 -0
  292. package/src/utils/giftedChatMessage.ts +137 -0
  293. package/src/utils/message.ts +136 -0
  294. 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,2 @@
1
+ export { default as Inbox } from './Inbox';
2
+ export { MessagesTab } from './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,2 @@
1
+ export { ChatAPI } from './apis';
2
+ export { ChatMessageAPI } from './message';
@@ -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,3 @@
1
+ export * from './storeConfig';
2
+ export * from './user';
3
+ export * from './conversation';
@@ -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,8 @@
1
+ const i18nKey: Record<string, string> = {
2
+ thread_card_bot_crm_name: 'Droppii Hỗ Trợ',
3
+ thread_card_fallback_name: 'Người dùng',
4
+ };
5
+
6
+ export default {
7
+ vi: i18nKey,
8
+ };
@@ -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
+ }