@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,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
+ });