@droppii-org/chat-mobile 0.2.4 → 0.2.7

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 (212) hide show
  1. package/lib/module/components/ThreadCard/AvatarSection.js +4 -4
  2. package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -1
  3. package/lib/module/components/ThreadCard/NamePrefixIcon.js +13 -16
  4. package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -1
  5. package/lib/module/components/ThreadCard/ThreadCard.js +13 -33
  6. package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -1
  7. package/lib/module/config/feature-flags.js +38 -0
  8. package/lib/module/config/feature-flags.js.map +1 -0
  9. package/lib/module/context/ChatContext.js +7 -6
  10. package/lib/module/context/ChatContext.js.map +1 -1
  11. package/lib/module/hooks/message/useSendMessage.js +101 -0
  12. package/lib/module/hooks/message/useSendMessage.js.map +1 -0
  13. package/lib/module/hooks/query-keys.js +4 -0
  14. package/lib/module/hooks/query-keys.js.map +1 -1
  15. package/lib/module/hooks/useChatMessages.js +54 -91
  16. package/lib/module/hooks/useChatMessages.js.map +1 -1
  17. package/lib/module/hooks/useConversationList.js +29 -17
  18. package/lib/module/hooks/useConversationList.js.map +1 -1
  19. package/lib/module/hooks/useLinkPreview/useFetchUrlMetadata.js +17 -0
  20. package/lib/module/hooks/useLinkPreview/useFetchUrlMetadata.js.map +1 -0
  21. package/lib/module/hooks/useLinkPreview/useLinkPreview.js +35 -0
  22. package/lib/module/hooks/useLinkPreview/useLinkPreview.js.map +1 -0
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/screens/chat-detail/ChatComposer.js +20 -4
  25. package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -1
  26. package/lib/module/screens/chat-detail/ChatDetail.js +116 -22
  27. package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
  28. package/lib/module/screens/chat-detail/ChatDetailHeader.js +5 -8
  29. package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -1
  30. package/lib/module/screens/chat-detail/ChatLinkPreview.js +79 -0
  31. package/lib/module/screens/chat-detail/ChatLinkPreview.js.map +1 -0
  32. package/lib/module/screens/chat-detail/ChatList.js +2 -0
  33. package/lib/module/screens/chat-detail/ChatList.js.map +1 -1
  34. package/lib/module/screens/chat-detail/ChatListLegend.js +350 -0
  35. package/lib/module/screens/chat-detail/ChatListLegend.js.map +1 -0
  36. package/lib/module/screens/chat-detail/ChatQuickActions.js +12 -2
  37. package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -1
  38. package/lib/module/screens/chat-detail/conversationHeader.utils.js +29 -0
  39. package/lib/module/screens/chat-detail/conversationHeader.utils.js.map +1 -0
  40. package/lib/module/screens/chat-detail/index.js +1 -0
  41. package/lib/module/screens/chat-detail/index.js.map +1 -1
  42. package/lib/module/screens/chat-detail/legend/LegendChatDay.js +57 -0
  43. package/lib/module/screens/chat-detail/legend/LegendChatDay.js.map +1 -0
  44. package/lib/module/screens/chat-detail/legend/LegendChatLoadEarlier.js +21 -0
  45. package/lib/module/screens/chat-detail/legend/LegendChatLoadEarlier.js.map +1 -0
  46. package/lib/module/screens/chat-detail/legend/LegendChatMessage.js +34 -0
  47. package/lib/module/screens/chat-detail/legend/LegendChatMessage.js.map +1 -0
  48. package/lib/module/screens/chat-detail/legend/LegendChatScrollToBottom.js +58 -0
  49. package/lib/module/screens/chat-detail/legend/LegendChatScrollToBottom.js.map +1 -0
  50. package/lib/module/screens/chat-detail/legend/message-types.js +244 -0
  51. package/lib/module/screens/chat-detail/legend/message-types.js.map +1 -0
  52. package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js.map +1 -1
  53. package/lib/module/services/apis.js +1 -1
  54. package/lib/module/services/apis.js.map +1 -1
  55. package/lib/module/services/endpoints.js +8 -0
  56. package/lib/module/services/endpoints.js.map +1 -0
  57. package/lib/module/store/conversation.js +1 -1
  58. package/lib/module/store/conversation.js.map +1 -1
  59. package/lib/module/store/message.js +45 -0
  60. package/lib/module/store/message.js.map +1 -0
  61. package/lib/module/translation/resources/i18n.js +7 -1
  62. package/lib/module/translation/resources/i18n.js.map +1 -1
  63. package/lib/module/types/chat.js +2 -7
  64. package/lib/module/types/chat.js.map +1 -1
  65. package/lib/module/types/common.js +2 -0
  66. package/lib/module/types/common.js.map +1 -0
  67. package/lib/module/utils/conversation.js +34 -13
  68. package/lib/module/utils/conversation.js.map +1 -1
  69. package/lib/module/utils/legendListMessage.js +77 -0
  70. package/lib/module/utils/legendListMessage.js.map +1 -0
  71. package/lib/module/utils/message.js +5 -8
  72. package/lib/module/utils/message.js.map +1 -1
  73. package/lib/module/utils/url.js +7 -0
  74. package/lib/module/utils/url.js.map +1 -0
  75. package/lib/typescript/src/components/Avatar/Avatar.d.ts +1 -1
  76. package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -1
  77. package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts +1 -1
  78. package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts.map +1 -1
  79. package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts +1 -1
  80. package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -1
  81. package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts +1 -1
  82. package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts.map +1 -1
  83. package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +2 -2
  84. package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -1
  85. package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +3 -4
  86. package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -1
  87. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts +1 -1
  88. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -1
  89. package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts +1 -1
  90. package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts.map +1 -1
  91. package/lib/typescript/src/config/feature-flags.d.ts +12 -0
  92. package/lib/typescript/src/config/feature-flags.d.ts.map +1 -0
  93. package/lib/typescript/src/context/ChatContext.d.ts +1 -1
  94. package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
  95. package/lib/typescript/src/hooks/message/useSendMessage.d.ts +12 -0
  96. package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -0
  97. package/lib/typescript/src/hooks/query-keys.d.ts +4 -0
  98. package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
  99. package/lib/typescript/src/hooks/useChatMessages.d.ts +3 -1
  100. package/lib/typescript/src/hooks/useChatMessages.d.ts.map +1 -1
  101. package/lib/typescript/src/hooks/useConversationList.d.ts +2 -1
  102. package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -1
  103. package/lib/typescript/src/hooks/useLinkPreview/useFetchUrlMetadata.d.ts +3 -0
  104. package/lib/typescript/src/hooks/useLinkPreview/useFetchUrlMetadata.d.ts.map +1 -0
  105. package/lib/typescript/src/hooks/useLinkPreview/useLinkPreview.d.ts +7 -0
  106. package/lib/typescript/src/hooks/useLinkPreview/useLinkPreview.d.ts.map +1 -0
  107. package/lib/typescript/src/index.d.ts +1 -1
  108. package/lib/typescript/src/index.d.ts.map +1 -1
  109. package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +1 -1
  110. package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -1
  111. package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +1 -1
  112. package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -1
  113. package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +1 -1
  114. package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +1 -1
  115. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +1 -1
  116. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -1
  117. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +1 -1
  118. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -1
  119. package/lib/typescript/src/screens/chat-detail/ChatLinkPreview.d.ts +9 -0
  120. package/lib/typescript/src/screens/chat-detail/ChatLinkPreview.d.ts.map +1 -0
  121. package/lib/typescript/src/screens/chat-detail/ChatList.d.ts +1 -1
  122. package/lib/typescript/src/screens/chat-detail/ChatList.d.ts.map +1 -1
  123. package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts +3 -0
  124. package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts.map +1 -0
  125. package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +1 -1
  126. package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -1
  127. package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +1 -1
  128. package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -1
  129. package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts +1 -1
  130. package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts.map +1 -1
  131. package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts +1 -1
  132. package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts.map +1 -1
  133. package/lib/typescript/src/screens/chat-detail/conversationHeader.utils.d.ts +6 -0
  134. package/lib/typescript/src/screens/chat-detail/conversationHeader.utils.d.ts.map +1 -0
  135. package/lib/typescript/src/screens/chat-detail/index.d.ts +2 -1
  136. package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -1
  137. package/lib/typescript/src/screens/chat-detail/legend/LegendChatDay.d.ts +6 -0
  138. package/lib/typescript/src/screens/chat-detail/legend/LegendChatDay.d.ts.map +1 -0
  139. package/lib/typescript/src/screens/chat-detail/legend/LegendChatLoadEarlier.d.ts +6 -0
  140. package/lib/typescript/src/screens/chat-detail/legend/LegendChatLoadEarlier.d.ts.map +1 -0
  141. package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts +13 -0
  142. package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts.map +1 -0
  143. package/lib/typescript/src/screens/chat-detail/legend/LegendChatScrollToBottom.d.ts +6 -0
  144. package/lib/typescript/src/screens/chat-detail/legend/LegendChatScrollToBottom.d.ts.map +1 -0
  145. package/lib/typescript/src/screens/chat-detail/legend/message-types.d.ts +13 -0
  146. package/lib/typescript/src/screens/chat-detail/legend/message-types.d.ts.map +1 -0
  147. package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts +1 -1
  148. package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts.map +1 -1
  149. package/lib/typescript/src/screens/chat-detail/types.d.ts +33 -7
  150. package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -1
  151. package/lib/typescript/src/screens/inbox/Inbox.d.ts +1 -1
  152. package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -1
  153. package/lib/typescript/src/screens/inbox/MessagesTab.d.ts +1 -1
  154. package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -1
  155. package/lib/typescript/src/services/apis.d.ts +1 -0
  156. package/lib/typescript/src/services/apis.d.ts.map +1 -1
  157. package/lib/typescript/src/services/endpoints.d.ts +6 -0
  158. package/lib/typescript/src/services/endpoints.d.ts.map +1 -0
  159. package/lib/typescript/src/store/message.d.ts +3 -0
  160. package/lib/typescript/src/store/message.d.ts.map +1 -0
  161. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
  162. package/lib/typescript/src/types/chat.d.ts +28 -27
  163. package/lib/typescript/src/types/chat.d.ts.map +1 -1
  164. package/lib/typescript/src/types/common.d.ts +7 -0
  165. package/lib/typescript/src/types/common.d.ts.map +1 -0
  166. package/lib/typescript/src/utils/conversation.d.ts +3 -2
  167. package/lib/typescript/src/utils/conversation.d.ts.map +1 -1
  168. package/lib/typescript/src/utils/legendListMessage.d.ts +23 -0
  169. package/lib/typescript/src/utils/legendListMessage.d.ts.map +1 -0
  170. package/lib/typescript/src/utils/message.d.ts.map +1 -1
  171. package/lib/typescript/src/utils/url.d.ts +2 -0
  172. package/lib/typescript/src/utils/url.d.ts.map +1 -0
  173. package/package.json +5 -3
  174. package/src/components/ThreadCard/AvatarSection.tsx +5 -8
  175. package/src/components/ThreadCard/NamePrefixIcon.tsx +27 -38
  176. package/src/components/ThreadCard/ThreadCard.tsx +16 -30
  177. package/src/config/feature-flags.ts +49 -0
  178. package/src/context/ChatContext.tsx +12 -4
  179. package/src/hooks/message/useSendMessage.ts +136 -0
  180. package/src/hooks/query-keys.ts +5 -0
  181. package/src/hooks/useChatMessages.ts +90 -118
  182. package/src/hooks/useConversationList.ts +34 -16
  183. package/src/hooks/useLinkPreview/useFetchUrlMetadata.ts +18 -0
  184. package/src/hooks/useLinkPreview/useLinkPreview.ts +31 -0
  185. package/src/index.tsx +1 -0
  186. package/src/screens/chat-detail/ChatComposer.tsx +23 -2
  187. package/src/screens/chat-detail/ChatDetail.tsx +163 -30
  188. package/src/screens/chat-detail/ChatDetailHeader.tsx +4 -10
  189. package/src/screens/chat-detail/ChatLinkPreview.tsx +86 -0
  190. package/src/screens/chat-detail/ChatList.tsx +3 -0
  191. package/src/screens/chat-detail/ChatListLegend.tsx +403 -0
  192. package/src/screens/chat-detail/ChatQuickActions.tsx +19 -2
  193. package/src/screens/chat-detail/conversationHeader.utils.ts +49 -0
  194. package/src/screens/chat-detail/index.ts +7 -0
  195. package/src/screens/chat-detail/legend/LegendChatDay.tsx +70 -0
  196. package/src/screens/chat-detail/legend/LegendChatLoadEarlier.tsx +21 -0
  197. package/src/screens/chat-detail/legend/LegendChatMessage.tsx +48 -0
  198. package/src/screens/chat-detail/legend/LegendChatScrollToBottom.tsx +56 -0
  199. package/src/screens/chat-detail/legend/message-types.tsx +304 -0
  200. package/src/screens/chat-detail/messages/ChatMessageBubble.tsx +0 -1
  201. package/src/screens/chat-detail/types.ts +45 -7
  202. package/src/services/apis.ts +1 -1
  203. package/src/services/endpoints.ts +5 -0
  204. package/src/store/conversation.ts +1 -1
  205. package/src/store/message.ts +44 -0
  206. package/src/translation/resources/i18n.ts +6 -0
  207. package/src/types/chat.ts +31 -30
  208. package/src/types/common.ts +6 -0
  209. package/src/utils/conversation.ts +44 -17
  210. package/src/utils/legendListMessage.ts +97 -0
  211. package/src/utils/message.ts +10 -12
  212. package/src/utils/url.ts +5 -0
@@ -1,8 +1,8 @@
1
1
  import { memo } from 'react';
2
2
  import { Image, StyleSheet } from 'react-native';
3
3
  import { KContainer, KImage, KColors } from '@droppii/libs';
4
- import { DChatCategory, DChatType } from '../../types/chat';
5
4
  import Images from '../../assets/images';
5
+ import { PeerType } from '@droppii/openim-rn-client-sdk';
6
6
 
7
7
  const styles = StyleSheet.create({
8
8
  icon: {
@@ -12,46 +12,35 @@ const styles = StyleSheet.create({
12
12
  });
13
13
 
14
14
  interface NamePrefixIconProps {
15
- chatCategory?: DChatCategory;
16
- chatType?: DChatType;
15
+ peerType?: PeerType | string;
17
16
  }
18
17
 
19
- export const NamePrefixIcon = memo(
20
- ({ chatCategory, chatType }: NamePrefixIconProps) => {
21
- if (chatCategory === DChatCategory.BIZ_BOT_CRM) {
22
- return (
23
- <KContainer.View marginR="0.25rem">
24
- <Image source={Images.ICON_DROPPII} style={styles.icon} />
25
- </KContainer.View>
26
- );
27
- }
28
- if (chatCategory === DChatCategory.BIZ_BOT_PDP) {
29
- return (
30
- <KContainer.View marginR="0.25rem">
31
- <KImage.VectorIcons
32
- name="robot-outline"
33
- provider="MaterialCommunityIcons"
34
- size={14}
35
- color={KColors.palette.primary.w400}
36
- />
37
- </KContainer.View>
38
- );
39
- }
40
-
41
- if (chatType === DChatType.GROUP) {
42
- return (
43
- <KContainer.View marginR="0.25rem">
44
- <KImage.VectorIcons
45
- name="user-two-b"
46
- size={14}
47
- color={KColors.black}
48
- />
49
- </KContainer.View>
50
- );
51
- }
18
+ export const NamePrefixIcon = memo(({ peerType }: NamePrefixIconProps) => {
19
+ if (peerType === PeerType.Bot) {
20
+ return (
21
+ <KContainer.View marginR="0.25rem">
22
+ <Image source={Images.ICON_DROPPII} style={styles.icon} />
23
+ </KContainer.View>
24
+ );
25
+ }
52
26
 
53
- return null;
27
+ if (peerType === PeerType.Group) {
28
+ return (
29
+ <KContainer.View marginR="0.25rem">
30
+ <KImage.VectorIcons name="user-two-b" size={14} color={KColors.black} />
31
+ </KContainer.View>
32
+ );
54
33
  }
55
- );
34
+
35
+ // if (peerType === DChatPeerType.CUSTOMER) {
36
+ // return (
37
+ // <KContainer.View marginR="0.25rem">
38
+ // <Image source={Images.ICON_DROPPII} style={styles.icon} />
39
+ // </KContainer.View>
40
+ // );
41
+ // }
42
+
43
+ return null;
44
+ });
56
45
 
57
46
  NamePrefixIcon.displayName = 'NamePrefixIcon';
@@ -1,12 +1,10 @@
1
1
  import { memo, useCallback } from 'react';
2
- import { StyleSheet, type GestureResponderEvent } from 'react-native';
2
+ import { type GestureResponderEvent } from 'react-native';
3
3
  import { KContainer, KImage, KLabel, KColors } from '@droppii/libs';
4
- import { DChatCategory } from '../../types/chat';
5
4
  import { AvatarSection } from './AvatarSection';
6
5
  import { NamePrefixIcon } from './NamePrefixIcon';
7
6
  import { UnreadBadge } from './UnreadBadge';
8
7
  import { formatTimestamp, getLastMessageText } from './thread-card.utils';
9
- import Images from '../../assets/images';
10
8
  import { useConversation, useUserStore } from '../../store';
11
9
 
12
10
  interface ThreadCardProps {
@@ -16,19 +14,20 @@ interface ThreadCardProps {
16
14
 
17
15
  const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
18
16
  const {
19
- peer,
20
- chatCategory,
17
+ peerType,
18
+ showName,
19
+ faceURL,
21
20
  lastMessage,
22
21
  unreadCount = 0,
23
- isMuted,
24
- pinnedAt,
22
+ recvMsgOpt,
23
+ isPinned,
25
24
  applicationType,
26
- chatType,
27
25
  latestMsgSendTime,
28
26
  } = useConversation(item) ?? {};
29
27
 
30
- const fullName = peer?.fullName ?? peer?.username ?? '';
28
+ const fullName = showName ?? '';
31
29
  const hasUnread = unreadCount > 0;
30
+ const isMuted = (recvMsgOpt ?? 0) !== 0;
32
31
  const timestamp = formatTimestamp(
33
32
  latestMsgSendTime ?? lastMessage?.sendTime ?? null
34
33
  );
@@ -52,30 +51,25 @@ const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
52
51
  activeOpacity={0.7}
53
52
  >
54
53
  <AvatarSection
55
- avatar={peer?.avatar ?? null}
54
+ avatar={faceURL ?? null}
56
55
  fullName={fullName}
57
- chatCategory={chatCategory}
56
+ peerType={peerType}
58
57
  applicationType={applicationType}
59
- chatType={chatType}
60
58
  />
61
59
 
62
60
  {/* Chat-Content */}
63
61
  <KContainer.View flex marginL="0.5rem" paddingB={2}>
64
62
  {/* Row-Title */}
65
63
  <KContainer.View row alignItems="center">
66
- <NamePrefixIcon chatCategory={chatCategory} chatType={chatType} />
67
- <KContainer.VisibleView
68
- visible={
69
- // chatCategory === DChatCategory.BIZ_BOT_CRM ||
70
- chatCategory === DChatCategory.BIZ_BOT_PDP
71
- }
72
- >
64
+ <NamePrefixIcon peerType={peerType} />
65
+ {/* For verified PDP (configuration details to be defined later) */}
66
+ {/* <KContainer.VisibleView visible={peerType === DChatPeerType.BOT}>
73
67
  <KImage.Base
74
68
  uri={Images.ICON_BOT}
75
69
  size={14}
76
70
  style={styles.botIcon}
77
71
  />
78
- </KContainer.VisibleView>
72
+ </KContainer.VisibleView> */}
79
73
  <KLabel.Text
80
74
  typo={hasUnread ? 'TextMdBold' : 'TextMdNormal'}
81
75
  numberOfLines={1}
@@ -84,7 +78,7 @@ const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
84
78
  >
85
79
  {fullName}
86
80
  </KLabel.Text>
87
- <KContainer.VisibleView visible={!!isMuted}>
81
+ <KContainer.VisibleView visible={isMuted}>
88
82
  <KContainer.View marginL="0.25rem">
89
83
  <KImage.VectorIcons
90
84
  name="bell-off"
@@ -115,7 +109,7 @@ const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
115
109
  >
116
110
  {lastMessageText}
117
111
  </KLabel.Text>
118
- <KContainer.VisibleView visible={Boolean(pinnedAt)}>
112
+ <KContainer.VisibleView visible={Boolean(isPinned)}>
119
113
  <KContainer.View marginL="0.5rem">
120
114
  <KImage.VectorIcons
121
115
  name="pin-outline"
@@ -135,11 +129,3 @@ const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
135
129
  ThreadCard.displayName = 'ThreadCard';
136
130
 
137
131
  export default ThreadCard;
138
-
139
- const styles = StyleSheet.create({
140
- botIcon: {
141
- width: 16,
142
- height: 16,
143
- marginRight: 4,
144
- },
145
- });
@@ -0,0 +1,49 @@
1
+ export interface FeatureFlags {
2
+ USE_LEGEND_LIST_CHAT: boolean;
3
+ CHAT_LIST_VARIANT: 'gifted' | 'legend';
4
+ ENABLE_PERFORMANCE_METRICS: boolean;
5
+ METRICS_SAMPLE_RATE: number;
6
+ }
7
+
8
+ const DEFAULT_FLAGS: FeatureFlags = {
9
+ USE_LEGEND_LIST_CHAT: false,
10
+ CHAT_LIST_VARIANT: 'legend',
11
+ ENABLE_PERFORMANCE_METRICS: true,
12
+ METRICS_SAMPLE_RATE: 1.0,
13
+ };
14
+
15
+ let flags: FeatureFlags = { ...DEFAULT_FLAGS };
16
+
17
+ export const getFeatureFlag = <K extends keyof FeatureFlags>(
18
+ flag: K
19
+ ): FeatureFlags[K] => {
20
+ return flags[flag];
21
+ };
22
+
23
+ export const setFeatureFlag = <K extends keyof FeatureFlags>(
24
+ flag: K,
25
+ value: FeatureFlags[K]
26
+ ) => {
27
+ flags[flag] = value;
28
+ notifyListeners();
29
+ };
30
+
31
+ export const resetFlags = () => {
32
+ flags = { ...DEFAULT_FLAGS };
33
+ notifyListeners();
34
+ };
35
+
36
+ const listeners = new Set<() => void>();
37
+
38
+ export const onFlagsChange = (callback: () => void) => {
39
+ listeners.add(callback);
40
+ return () => {
41
+ listeners.delete(callback);
42
+ };
43
+ };
44
+
45
+ const notifyListeners = () => {
46
+ listeners.forEach((cb) => cb());
47
+ };
48
+
49
+ export const getAllFlags = (): FeatureFlags => ({ ...flags });
@@ -13,11 +13,19 @@ export const useChatContext = (): ChatContextType => {
13
13
  return context;
14
14
  };
15
15
 
16
- const ChatProviderInner = ({ logGA, children }: ChatProviderProps) => {
17
- const value = useMemo(() => ({ logGA }), [logGA]);
16
+ const ChatProviderInner = ({
17
+ logGA,
18
+ children,
19
+ applicationType,
20
+ }: ChatProviderProps) => {
21
+ const value = useMemo(
22
+ () => ({ logGA, applicationType }),
23
+ [logGA, applicationType]
24
+ );
18
25
 
19
26
  return <ChatContext.Provider value={value}>{children}</ChatContext.Provider>;
20
27
  };
21
28
 
22
- export const ChatProvider = ({ enabled, ...props }: ChatProviderProps) =>
23
- enabled ? <ChatProviderInner {...props} /> : props.children;
29
+ export const ChatProvider = ({ ...props }: ChatProviderProps) => (
30
+ <ChatProviderInner {...props} />
31
+ );
@@ -0,0 +1,136 @@
1
+ import { useCallback } from 'react';
2
+ import type { UploadFileItem } from 'react-native-fs';
3
+ import { useConversationStore } from '../../store';
4
+ import type {
5
+ MessageItem,
6
+ MessageType,
7
+ OfflinePush,
8
+ } from '@droppii/openim-rn-client-sdk';
9
+ import { extractUrls } from '../../utils/url';
10
+ import OpenIMSDK from '@droppii/openim-rn-client-sdk';
11
+ import type { IMessageItemEx } from '../../types/chat';
12
+ import { useChatContext } from '../../context';
13
+ import { generateContentBasedOnMessageType } from '../../utils/conversation';
14
+ import { useMessageStore } from '../../store/message';
15
+ import type { IUrlMetadata } from '../../types/common';
16
+
17
+ export const useSendMessage = () => {
18
+ const applicationType = useChatContext().applicationType;
19
+ const pushNewMessage = useMessageStore((state) => state.pushNewMessage);
20
+
21
+ const sendMessage = useCallback(
22
+ async ({
23
+ plainText,
24
+ files,
25
+ urlMetadata,
26
+ }: {
27
+ plainText?: string;
28
+ files?: UploadFileItem[]; //TODO
29
+ urlMetadata?: IUrlMetadata;
30
+ }) => {
31
+ const { userID: recvID, groupID } =
32
+ useConversationStore.getState().getCurrentConversation() || {};
33
+ if (!recvID && !groupID) return;
34
+
35
+ const messageList: MessageItem[] = [];
36
+
37
+ for (const file of files || []) {
38
+ if (!file) continue;
39
+ }
40
+
41
+ if (!!plainText && plainText.trim() !== '') {
42
+ const urls = extractUrls(plainText);
43
+ const isUrlMessage = urls.length > 0;
44
+ let message: MessageItem | null = null;
45
+ if (isUrlMessage) {
46
+ message = await createUrlTextMessage(plainText, urls);
47
+ } else {
48
+ message = await createTextMessage(plainText);
49
+ }
50
+ if (!message) return;
51
+ messageList.push(message);
52
+ }
53
+
54
+ for (const message of messageList) {
55
+ const extendMessageInfo: IMessageItemEx = {
56
+ applicationType,
57
+ urlMetadata,
58
+ };
59
+
60
+ const successMessage = await OpenIMSDK.sendMessage({
61
+ groupID: groupID || '',
62
+ recvID: recvID || '',
63
+ message: {
64
+ ...message,
65
+ ex: JSON.stringify(extendMessageInfo) || '{}',
66
+ },
67
+ offlinePushInfo: generateOfflinePushInfo(
68
+ message.contentType,
69
+ plainText || ''
70
+ ),
71
+ });
72
+
73
+ pushNewMessage(successMessage);
74
+ }
75
+ },
76
+ [applicationType, pushNewMessage]
77
+ );
78
+
79
+ return {
80
+ sendMessage,
81
+ };
82
+ };
83
+
84
+ const generateOfflinePushInfo = (
85
+ contentType: MessageType,
86
+ plainText: string
87
+ ) => {
88
+ const conversationData = useConversationStore
89
+ ?.getState?.()
90
+ ?.getCurrentConversation();
91
+ const title = conversationData?.showName || 'Droppii';
92
+ const desc = generateContentBasedOnMessageType(contentType, plainText);
93
+ return {
94
+ title,
95
+ desc,
96
+ ex: JSON.stringify({
97
+ icon: conversationData?.faceURL || '',
98
+ conversationId: conversationData?.conversationId || '',
99
+ title,
100
+ desc,
101
+ }),
102
+ iOSPushSound: 'default',
103
+ iOSBadgeCount: true,
104
+ } as OfflinePush;
105
+ };
106
+
107
+ export const createTextMessage = async (text: string) => {
108
+ let textMessage = await OpenIMSDK.createTextMessage(
109
+ text,
110
+ new Date().getTime().toString()
111
+ )
112
+ .then((data) => {
113
+ return data;
114
+ })
115
+ .catch(({ errCode, errMsg }) => {
116
+ console.error('createTextMessage', errCode, errMsg);
117
+ return null;
118
+ });
119
+ return textMessage;
120
+ };
121
+
122
+ export const createUrlTextMessage = async (text: string, urls: string[]) => {
123
+ let urlTextMessage = await OpenIMSDK.createUrlTextMessage(
124
+ text,
125
+ urls,
126
+ new Date().getTime().toString()
127
+ )
128
+ .then((data) => {
129
+ return data;
130
+ })
131
+ .catch(({ errCode, errMsg }) => {
132
+ console.error('createUrlTextMessage', errCode, errMsg);
133
+ return null;
134
+ });
135
+ return urlTextMessage;
136
+ };
@@ -1,3 +1,8 @@
1
+ export const commonQueryKeys = {
2
+ all: ['common'] as const,
3
+ urlMetadata: (url: string) => ['list', url] as const,
4
+ };
5
+
1
6
  export const conversationQueryKeys = {
2
7
  all: ['conversations'] as const,
3
8
  lists: () => [...conversationQueryKeys.all, 'list'] as const,