@ethora/chat-component-rn 26.4.1

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 (273) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +148 -0
  3. package/empty-shim.js +15 -0
  4. package/index.js +13 -0
  5. package/metro.js +72 -0
  6. package/package.json +99 -0
  7. package/src/api.config.ts +34 -0
  8. package/src/assets/BG.png +0 -0
  9. package/src/assets/BG.tsx +56 -0
  10. package/src/assets/File.svg +4 -0
  11. package/src/assets/ForzaCare.png +0 -0
  12. package/src/assets/ForzaCare.tsx +27 -0
  13. package/src/assets/icons.tsx +685 -0
  14. package/src/assets/images.tsx +41 -0
  15. package/src/assets/test.xml +243 -0
  16. package/src/components/AuthForms/Login.tsx +295 -0
  17. package/src/components/AuthForms/LoginAnonym.tsx +68 -0
  18. package/src/components/AuthForms/Register.tsx +8 -0
  19. package/src/components/ContextMenu/ContextMenuComponents.tsx +87 -0
  20. package/src/components/DropdownMenu/DropdownMenu.tsx +244 -0
  21. package/src/components/ExampleComponents/CustomMessage.tsx +92 -0
  22. package/src/components/ExampleComponents/CustomTypingIndicatorExamples.tsx +239 -0
  23. package/src/components/Header/HeaderRoomList.tsx +104 -0
  24. package/src/components/InputComponents/AudioInput.tsx +24 -0
  25. package/src/components/InputComponents/AudioRecorder.tsx +100 -0
  26. package/src/components/InputComponents/MediaInput.tsx +114 -0
  27. package/src/components/InputComponents/RecordingIndicator.tsx +77 -0
  28. package/src/components/InputComponents/Search.tsx +135 -0
  29. package/src/components/InputComponents/TextInput.tsx +66 -0
  30. package/src/components/MainComponents/ChatHeader.tsx +163 -0
  31. package/src/components/MainComponents/ChatRoom.tsx +392 -0
  32. package/src/components/MainComponents/ChatWrapper.tsx +318 -0
  33. package/src/components/MainComponents/ChooseChatMessage.tsx +44 -0
  34. package/src/components/MainComponents/ConnectionBanner.tsx +33 -0
  35. package/src/components/MainComponents/EditWrapper.tsx +72 -0
  36. package/src/components/MainComponents/LoginWrapper.tsx +134 -0
  37. package/src/components/MainComponents/MediaMessage.tsx +55 -0
  38. package/src/components/MainComponents/MessageContainer.tsx +122 -0
  39. package/src/components/MainComponents/MessageList.tsx +429 -0
  40. package/src/components/MainComponents/NoMessagesPlaceholder.tsx +49 -0
  41. package/src/components/MainComponents/ProfileImagePlaceholder.tsx +143 -0
  42. package/src/components/MainComponents/RNStyled.tsx +34 -0
  43. package/src/components/MainComponents/ReduxWrapper.tsx +40 -0
  44. package/src/components/MainComponents/RoomList.tsx +246 -0
  45. package/src/components/MainComponents/Select.tsx +165 -0
  46. package/src/components/MainComponents/Switch.tsx +73 -0
  47. package/src/components/MainComponents/SystemMessage.tsx +42 -0
  48. package/src/components/Menu/HeaderRoomListMenu.tsx +169 -0
  49. package/src/components/MenuRoom/MenuRoom.tsx +46 -0
  50. package/src/components/MessageBubble/Avatar.tsx +84 -0
  51. package/src/components/MessageBubble/BottomReplyContainer.tsx +117 -0
  52. package/src/components/MessageBubble/CustomDivider.tsx +10 -0
  53. package/src/components/MessageBubble/DeletedMessage.tsx +36 -0
  54. package/src/components/MessageBubble/Message.tsx +400 -0
  55. package/src/components/MessageBubble/MessageInteractions.tsx +247 -0
  56. package/src/components/MessageBubble/MessageReaction.tsx +149 -0
  57. package/src/components/MessageBubble/MessageReply.tsx +50 -0
  58. package/src/components/MessageBubble/MessageTranslations.tsx +30 -0
  59. package/src/components/Modals/AddMembersModal/AddMembersModal.tsx +142 -0
  60. package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +471 -0
  61. package/src/components/Modals/ChatProfileModal/DeleteChatModal.tsx +91 -0
  62. package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +298 -0
  63. package/src/components/Modals/Modal/Modal.tsx +52 -0
  64. package/src/components/Modals/ModalHeaderComponent.tsx +41 -0
  65. package/src/components/Modals/ModalSelectMedia/ModalSelectMedia.tsx +285 -0
  66. package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +103 -0
  67. package/src/components/Modals/NewChatModal/ModalContent.tsx +151 -0
  68. package/src/components/Modals/NewChatModal/NewChatModal.tsx +391 -0
  69. package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +136 -0
  70. package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +134 -0
  71. package/src/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.tsx +63 -0
  72. package/src/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.tsx +115 -0
  73. package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +121 -0
  74. package/src/components/Modals/SettingsModals/ManageDataModal/StyledComponents.ts +0 -0
  75. package/src/components/Modals/SettingsModals/ProfileShares/ProfileShares.tsx +65 -0
  76. package/src/components/Modals/SettingsModals/Referrals/Referrals.tsx +90 -0
  77. package/src/components/Modals/SettingsModals/SharedStyledComponents.ts +74 -0
  78. package/src/components/Modals/SettingsModals/Visibility/RadioInput.tsx +59 -0
  79. package/src/components/Modals/SettingsModals/Visibility/StyledComponents.ts +32 -0
  80. package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +146 -0
  81. package/src/components/Modals/UserProfileModal/EditUserModal.tsx +163 -0
  82. package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +410 -0
  83. package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +85 -0
  84. package/src/components/Modals/styledModalComponents.tsx +181 -0
  85. package/src/components/OperationalModal/OperationalModal.tsx +78 -0
  86. package/src/components/RoomComponents/ChatRoomItem.tsx +219 -0
  87. package/src/components/RoomComponents/LastMessageItem.tsx +47 -0
  88. package/src/components/RoomComponents/styled/LastAudioMessage.tsx +62 -0
  89. package/src/components/RoomComponents/styled/LastMessageEmoji.tsx +26 -0
  90. package/src/components/RoomComponents/styled/LastMessageFile.tsx +54 -0
  91. package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +54 -0
  92. package/src/components/RoomComponents/styled/LastMessageVideo.tsx +70 -0
  93. package/src/components/RoomComponents/styled/LastTextMessage.tsx +65 -0
  94. package/src/components/RoomComponents/styled/StyledRoomComponents.ts +53 -0
  95. package/src/components/SortDropDown/index.tsx +76 -0
  96. package/src/components/Thread/ThreadHeader.tsx +41 -0
  97. package/src/components/Thread/ThreadWrapper.tsx +270 -0
  98. package/src/components/Toast/Toast.tsx +128 -0
  99. package/src/components/Toast/index.ts +13 -0
  100. package/src/components/UsersList/StyledComponents.ts +30 -0
  101. package/src/components/UsersList/UsersList.tsx +112 -0
  102. package/src/components/styled/ActionButton.tsx +40 -0
  103. package/src/components/styled/AudioMessage.tsx +82 -0
  104. package/src/components/styled/Button.tsx +107 -0
  105. package/src/components/styled/ChatWrapperBox.tsx +9 -0
  106. package/src/components/styled/DateLabel.tsx +77 -0
  107. package/src/components/styled/Loader.tsx +65 -0
  108. package/src/components/styled/MediaFilePreview.tsx +42 -0
  109. package/src/components/styled/MediaModal.tsx +54 -0
  110. package/src/components/styled/MessageImage.tsx +54 -0
  111. package/src/components/styled/NewMessageLabel.tsx +50 -0
  112. package/src/components/styled/RoomListComponents/index.tsx +164 -0
  113. package/src/components/styled/SendInput.tsx +297 -0
  114. package/src/components/styled/StyledComponents.ts +320 -0
  115. package/src/components/styled/StyledInput.tsx +101 -0
  116. package/src/components/styled/StyledInputComponents/AudioComponents.tsx +1 -0
  117. package/src/components/styled/StyledInputComponents/Composing.tsx +97 -0
  118. package/src/components/styled/StyledInputComponents/CustomTypingIndicator.tsx +261 -0
  119. package/src/components/styled/StyledInputComponents/MediaComponents.tsx +90 -0
  120. package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +131 -0
  121. package/src/components/styled/StyledInputComponents/VideoComponents.tsx +49 -0
  122. package/src/components/styled/TreadLabel.tsx +50 -0
  123. package/src/components/styled/UnsupportedType.tsx +95 -0
  124. package/src/components/styled/VideoMessage.tsx +68 -0
  125. package/src/context/MessageNotificationContext.tsx +335 -0
  126. package/src/context/PushNotificationProvider.tsx +78 -0
  127. package/src/context/ToastContext.tsx +63 -0
  128. package/src/context/toastProvider.tsx +0 -0
  129. package/src/context/xmppProvider.tsx +364 -0
  130. package/src/helpers/block_scroll.ts +95 -0
  131. package/src/helpers/chatAutoEnterer.ts +46 -0
  132. package/src/helpers/checkUniqueUsers.tsx +31 -0
  133. package/src/helpers/constants/CHAT_TYPES.ts +6 -0
  134. package/src/helpers/constants/LANGUAGE_OPTIONS.ts +14 -0
  135. package/src/helpers/constants/LOCAL_STORAGE.ts +3 -0
  136. package/src/helpers/constants/MESSAGE_INTERACTIONS.ts +29 -0
  137. package/src/helpers/constants/MODAL_TYPES.ts +57 -0
  138. package/src/helpers/constants/PLATFORM_CONSTANTS.ts +3 -0
  139. package/src/helpers/createMainMessageForThread.ts +23 -0
  140. package/src/helpers/createMessageFromXml.ts +118 -0
  141. package/src/helpers/createRoomFromApi.tsx +27 -0
  142. package/src/helpers/createUserNameFromSetUser.ts +15 -0
  143. package/src/helpers/dateComparison.ts +12 -0
  144. package/src/helpers/debounce.ts +10 -0
  145. package/src/helpers/ensureScopedChatCache.ts +61 -0
  146. package/src/helpers/extractUniqueMembersFromRooms.ts +45 -0
  147. package/src/helpers/formatNumberWithCommas.ts +3 -0
  148. package/src/helpers/getBooleanFromString.ts +7 -0
  149. package/src/helpers/getDataFromXml.ts +80 -0
  150. package/src/helpers/getNumberFromString.ts +5 -0
  151. package/src/helpers/getRoomsWithRetry.ts +45 -0
  152. package/src/helpers/getTintedColor.ts +28 -0
  153. package/src/helpers/getUnnamedUsers.ts +39 -0
  154. package/src/helpers/handleCopyClick.ts +3 -0
  155. package/src/helpers/handleXmppError.ts +14 -0
  156. package/src/helpers/hashcolor.ts +34 -0
  157. package/src/helpers/historyPreloadScheduler.ts +264 -0
  158. package/src/helpers/initRoomsPresence.ts +32 -0
  159. package/src/helpers/initXmppRooms.tsx +71 -0
  160. package/src/helpers/insertMessageWithDelimiter.ts +96 -0
  161. package/src/helpers/isChatIdPresentInArray.ts +54 -0
  162. package/src/helpers/localStorageUser.ts +9 -0
  163. package/src/helpers/markdownParser.tsx +295 -0
  164. package/src/helpers/nanoToMs.ts +3 -0
  165. package/src/helpers/parseMessageBody.tsx +516 -0
  166. package/src/helpers/parseUrls.tsx +42 -0
  167. package/src/helpers/resolveInitBeforeLoadUser.ts +240 -0
  168. package/src/helpers/storeConsole.ts +26 -0
  169. package/src/helpers/transformTranslatations.ts +16 -0
  170. package/src/helpers/updateMessagesTillLast.tsx +104 -0
  171. package/src/helpers/updatedChatLastTimestamps.ts +29 -0
  172. package/src/helpers/validator.ts +20 -0
  173. package/src/helpers/walletUsername.ts +12 -0
  174. package/src/hooks/hooks.ts +6 -0
  175. package/src/hooks/useChatSettingState.tsx +38 -0
  176. package/src/hooks/useChatWrapperInit.ts +266 -0
  177. package/src/hooks/useComposing.tsx +59 -0
  178. package/src/hooks/useCustomTypingIndicator.tsx +193 -0
  179. package/src/hooks/useEventHandlers.tsx +81 -0
  180. package/src/hooks/useGetNewArchRoom.tsx +57 -0
  181. package/src/hooks/useHeapSender.tsx +88 -0
  182. package/src/hooks/useLocalStorage.tsx +53 -0
  183. package/src/hooks/useLogout.tsx +31 -0
  184. package/src/hooks/useMessageHeapState.tsx +11 -0
  185. package/src/hooks/useMessageLoaderQueue.tsx +90 -0
  186. package/src/hooks/useMessageQueue.ts +146 -0
  187. package/src/hooks/usePendingNotification.ts +49 -0
  188. package/src/hooks/usePrevious.tsx +15 -0
  189. package/src/hooks/usePushNotifications.ts +106 -0
  190. package/src/hooks/useQRCodeChatHandler.ts +58 -0
  191. package/src/hooks/useRoomInitialization.tsx +160 -0
  192. package/src/hooks/useRoomState.tsx +47 -0
  193. package/src/hooks/useRoomUrl.tsx +41 -0
  194. package/src/hooks/useSendMessage.tsx +306 -0
  195. package/src/hooks/useUnreadMessagesCounter.ts +55 -0
  196. package/src/hooks/useXmppInitialization.ts +148 -0
  197. package/src/main.ts +45 -0
  198. package/src/networking/api-requests/auth.api.ts +140 -0
  199. package/src/networking/api-requests/push.api.ts +55 -0
  200. package/src/networking/api-requests/roomMembers.api.ts +20 -0
  201. package/src/networking/api-requests/rooms.api.ts +142 -0
  202. package/src/networking/api-requests/user.api.ts +65 -0
  203. package/src/networking/apiClient.ts +149 -0
  204. package/src/networking/helpers/refreshChecker.ts +13 -0
  205. package/src/networking/stanzaHandlers.ts +418 -0
  206. package/src/networking/xmpp/actionSetTimestampToPrivateStore.xmpp.ts +37 -0
  207. package/src/networking/xmpp/allRoomPresences.xmpp.ts +10 -0
  208. package/src/networking/xmpp/createPrivateRoom.xmpp.ts +26 -0
  209. package/src/networking/xmpp/createRoom.xmpp.ts +35 -0
  210. package/src/networking/xmpp/createRoomPresence.xmpp.ts +74 -0
  211. package/src/networking/xmpp/createTimeoutPromise.xmpp.ts +15 -0
  212. package/src/networking/xmpp/deleteMessage.xmpp.ts +19 -0
  213. package/src/networking/xmpp/editMessage.xmpp.ts +46 -0
  214. package/src/networking/xmpp/getChatsPrivateStoreRequest.xmpp.ts +57 -0
  215. package/src/networking/xmpp/getHistory.xmpp.ts +140 -0
  216. package/src/networking/xmpp/getLastMessageArchive.xmpp.ts +24 -0
  217. package/src/networking/xmpp/getRoomInfo.xmpp.ts +15 -0
  218. package/src/networking/xmpp/getRoomMembers.xmpp.ts +13 -0
  219. package/src/networking/xmpp/getRooms.xmpp.ts +43 -0
  220. package/src/networking/xmpp/getRoomsPaged.xmpp.ts +59 -0
  221. package/src/networking/xmpp/handlePong.xmpp.ts +7 -0
  222. package/src/networking/xmpp/handleStanzas.xmpp.ts +55 -0
  223. package/src/networking/xmpp/inviteRoomRequest.xmpp.ts +25 -0
  224. package/src/networking/xmpp/leaveTheRoom.xmpp.ts +15 -0
  225. package/src/networking/xmpp/listenerManager.ts +116 -0
  226. package/src/networking/xmpp/presenceInRoom.xmpp.ts +57 -0
  227. package/src/networking/xmpp/roomConfig.xmpp.ts +71 -0
  228. package/src/networking/xmpp/sendMediaMessage.xmpp.ts +97 -0
  229. package/src/networking/xmpp/sendMessageReaction.xmpp.ts +41 -0
  230. package/src/networking/xmpp/sendPing.xmpp.ts +21 -0
  231. package/src/networking/xmpp/sendTextMessage.xmpp.ts +99 -0
  232. package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +44 -0
  233. package/src/networking/xmpp/sendTypingRequest.xmpp.ts +26 -0
  234. package/src/networking/xmpp/setChatsPrivateStoreRequest.xmpp.ts +48 -0
  235. package/src/networking/xmpp/setMeAsOwner.xmpp.ts +52 -0
  236. package/src/networking/xmpp/setRoomImage.xmpp.ts +26 -0
  237. package/src/networking/xmpp/setVCard.xmpp.ts +19 -0
  238. package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +75 -0
  239. package/src/networking/xmppClient.ts +603 -0
  240. package/src/roomStore/Middleware/logoutMiddleware.tsx +24 -0
  241. package/src/roomStore/Middleware/newMessageMidlleware.tsx +87 -0
  242. package/src/roomStore/Middleware/reactionsMiddleware.tsx +77 -0
  243. package/src/roomStore/Middleware/testMiddleware.tsx +20 -0
  244. package/src/roomStore/Middleware/unreadMidlleware.tsx +58 -0
  245. package/src/roomStore/chatSettingsSlice.ts +178 -0
  246. package/src/roomStore/index.ts +68 -0
  247. package/src/roomStore/persistence.ts +152 -0
  248. package/src/roomStore/roomHeapSlice.ts +37 -0
  249. package/src/roomStore/roomsSlice.ts +353 -0
  250. package/src/services/pushNotifications.ts +170 -0
  251. package/src/services/pushSubscriptionService.ts +145 -0
  252. package/src/types/messages.ts +61 -0
  253. package/src/types/models/action.model.ts +30 -0
  254. package/src/types/models/config.model.ts +16 -0
  255. package/src/types/models/customComponents.model.ts +53 -0
  256. package/src/types/models/language.model.ts +11 -0
  257. package/src/types/models/media.model.ts +5 -0
  258. package/src/types/models/message.model.ts +69 -0
  259. package/src/types/models/modal.model.ts +9 -0
  260. package/src/types/models/room.model.ts +120 -0
  261. package/src/types/models/user.model.ts +90 -0
  262. package/src/types/models/xmpp.model.ts +155 -0
  263. package/src/types/types.ts +505 -0
  264. package/src/utils/PriorityQueue.ts +47 -0
  265. package/src/utils/actionHelpers.ts +40 -0
  266. package/src/utils/actionLogger.ts +64 -0
  267. package/src/utils/clientRegistry.ts +80 -0
  268. package/src/utils/devLogger.ts +197 -0
  269. package/src/utils/messageNotificationManager.ts +108 -0
  270. package/src/utils/resendMessage.ts +87 -0
  271. package/src/utils/toastEmitter.ts +27 -0
  272. package/src/utils/xmppMemoryMonitor.ts +63 -0
  273. package/src/version.ts +1 -0
@@ -0,0 +1,516 @@
1
+ import React from 'react';
2
+ import {
3
+ Text,
4
+ View,
5
+ Pressable,
6
+ Linking,
7
+ Platform,
8
+ ScrollView,
9
+ StyleProp,
10
+ ViewStyle,
11
+ } from 'react-native';
12
+
13
+ let elementKeyCounter = 0;
14
+
15
+ export const decodeHTMLEntities = (text: string) => {
16
+ const entities: Record<string, string> = {
17
+ '&amp;': '&',
18
+ '&lt;': '<',
19
+ '&gt;': '>',
20
+ '&quot;': '"',
21
+ '&#39;': "'",
22
+ '&nbsp;': ' ',
23
+ '&ndash;': '–',
24
+ '&mdash;': '—',
25
+ '&hellip;': '…',
26
+ '&#8209;': '-',
27
+ };
28
+ return text.replace(/&[a-zA-Z0-9#]+;/g, (m) => entities[m] || m);
29
+ };
30
+
31
+ const styles = {
32
+ bold: { fontWeight: 'bold' as const },
33
+ italic: { fontStyle: 'italic' as const },
34
+ strike: { textDecorationLine: 'line-through' as const },
35
+ link: { color: '#0a66c2', textDecorationLine: 'underline' as const },
36
+
37
+ codeInlineBox: {
38
+ backgroundColor: '#f1f3f4',
39
+ borderRadius: 3,
40
+ paddingVertical: 1,
41
+ paddingHorizontal: 4,
42
+ },
43
+ codeInlineText: {
44
+ fontFamily: Platform.select({ ios: 'Menlo', android: 'monospace' }),
45
+ fontSize: 13,
46
+ color: '#333',
47
+ },
48
+
49
+ codeBlock: {
50
+ backgroundColor: '#f6f8fa',
51
+ padding: 12,
52
+ borderRadius: 6,
53
+ borderWidth: 1,
54
+ borderColor: '#e1e4e8',
55
+ marginVertical: 8,
56
+ } as const,
57
+ codeBlockText: {
58
+ fontFamily: Platform.select({ ios: 'Menlo', android: 'monospace' }),
59
+ fontSize: 14,
60
+ color: '#24292f',
61
+ lineHeight: 20,
62
+ },
63
+
64
+ h: [
65
+ { fontWeight: 'bold' as const, fontSize: 32, marginTop: 24, marginBottom: 16 },
66
+ { fontWeight: 'bold' as const, fontSize: 24, marginTop: 20, marginBottom: 14 },
67
+ { fontWeight: 'bold' as const, fontSize: 20, marginTop: 16, marginBottom: 12 },
68
+ { fontWeight: 'bold' as const, fontSize: 18, marginTop: 14, marginBottom: 10 },
69
+ { fontWeight: 'bold' as const, fontSize: 16, marginTop: 12, marginBottom: 8 },
70
+ { fontWeight: 'bold' as const, fontSize: 14, marginTop: 12, marginBottom: 8 },
71
+ ],
72
+
73
+ quote: {
74
+ borderLeftWidth: 3,
75
+ borderLeftColor: '#ccc',
76
+ paddingLeft: 10,
77
+ marginVertical: 4,
78
+ },
79
+
80
+ paragraph: { marginVertical: 6 },
81
+
82
+ hr: { height: 1, backgroundColor: '#e1e4e8', marginVertical: 20 },
83
+
84
+ listItemRow: { flexDirection: 'row' as const, alignItems: 'flex-start' as const },
85
+ listMarker: { minWidth: 22, paddingTop: 2 },
86
+
87
+ checkboxRow: { flexDirection: 'row' as const, alignItems: 'flex-start' as const },
88
+ checkboxBox: {
89
+ width: 16,
90
+ height: 16,
91
+ marginRight: 8,
92
+ marginTop: 2,
93
+ borderRadius: 3,
94
+ borderWidth: 1,
95
+ borderColor: '#bbb',
96
+ backgroundColor: '#fff',
97
+ alignItems: 'center' as const,
98
+ justifyContent: 'center' as const,
99
+ },
100
+ checkboxTick: { fontSize: 12, color: '#0a66c2' },
101
+
102
+ tableContainer: { marginVertical: 12 } as StyleProp<ViewStyle>,
103
+ tableInner: {
104
+ borderWidth: 1,
105
+ borderColor: '#d0d7de',
106
+ borderRadius: 6,
107
+ overflow: 'hidden' as const,
108
+ backgroundColor: '#fff',
109
+ },
110
+ tableRow: { flexDirection: 'row' as const },
111
+ th: {
112
+ flex: 1,
113
+ paddingVertical: 10,
114
+ paddingHorizontal: 12,
115
+ backgroundColor: '#f6f8fa',
116
+ borderRightWidth: 1,
117
+ borderRightColor: '#d0d7de',
118
+ },
119
+ td: {
120
+ flex: 1,
121
+ paddingVertical: 10,
122
+ paddingHorizontal: 12,
123
+ borderTopWidth: 1,
124
+ borderTopColor: '#e7e9ec',
125
+ borderRightWidth: 1,
126
+ borderRightColor: '#eef0f2',
127
+ },
128
+ lastCell: { borderRightWidth: 0 },
129
+ cellText: { color: '#24292f', fontSize: 14, lineHeight: 20 } as const,
130
+ };
131
+
132
+ const renderTextWithLinks = (text: string) => {
133
+ const urlRegex =
134
+ /(https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-\._~:\/?#[\]@!\$&'()\*\+,;=.]+)/g;
135
+ const nodes: Array<string | JSX.Element> = [];
136
+ let lastIndex = 0;
137
+
138
+ if (!text) {return nodes;}
139
+
140
+ let match: RegExpExecArray | null;
141
+ while ((match = urlRegex.exec(text)) !== null) {
142
+ const url = match[0];
143
+ const start = match.index;
144
+
145
+ if (start > lastIndex) {nodes.push(text.slice(lastIndex, start));}
146
+
147
+ nodes.push(
148
+ <Pressable key={`link-${elementKeyCounter++}`} onPress={() => Linking.openURL(url)}>
149
+ <Text style={styles.link}>{url}</Text>
150
+ </Pressable>
151
+ );
152
+
153
+ lastIndex = start + url.length;
154
+ }
155
+
156
+ if (lastIndex < text.length) {nodes.push(text.slice(lastIndex));}
157
+ return nodes;
158
+ };
159
+
160
+ const parseInline = (txt: string): (string | JSX.Element)[] => {
161
+ const elements: (string | JSX.Element)[] = [];
162
+ let remaining = decodeHTMLEntities(txt);
163
+
164
+ const pattern = /(\*\*\*|\*\*|\*|`)(.*?)\1/;
165
+
166
+ while (remaining.length > 0) {
167
+ const match = remaining.match(pattern);
168
+ if (!match) {
169
+ elements.push(...renderTextWithLinks(remaining));
170
+ break;
171
+ }
172
+
173
+ const fullMatch = match[0];
174
+ const matchIndex = match.index ?? 0;
175
+ const delimiter = match[1];
176
+ const content = match[2];
177
+
178
+ if (matchIndex > 0) {
179
+ elements.push(...renderTextWithLinks(remaining.substring(0, matchIndex)));
180
+ }
181
+
182
+ if (delimiter === '`') {
183
+ elements.push(
184
+ <View key={`code-${elementKeyCounter++}`} style={styles.codeInlineBox}>
185
+ <Text style={styles.codeInlineText}>{content}</Text>
186
+ </View>
187
+ );
188
+ } else if (delimiter === '***') {
189
+ elements.push(
190
+ <Text key={`bi-${elementKeyCounter++}`} style={styles.bold}>
191
+ <Text key={`i-${elementKeyCounter++}`} style={styles.italic}>
192
+ {parseInline(content)}
193
+ </Text>
194
+ </Text>
195
+ );
196
+ } else if (delimiter === '**') {
197
+ elements.push(
198
+ <Text key={`b-${elementKeyCounter++}`} style={styles.bold}>
199
+ {parseInline(content)}
200
+ </Text>
201
+ );
202
+ } else if (delimiter === '*') {
203
+ elements.push(
204
+ <Text key={`i-${elementKeyCounter++}`} style={styles.italic}>
205
+ {parseInline(content)}
206
+ </Text>
207
+ );
208
+ }
209
+
210
+ remaining = remaining.substring(matchIndex + fullMatch.length);
211
+ }
212
+
213
+ return elements;
214
+ };
215
+
216
+ const isTableSeparatorLine = (line: string) => {
217
+ const trimmed = line.trim();
218
+ return (
219
+ /^\|?[\s]*[\-\:]+[\s\|\-\:]*\|?[\s]*$/.test(trimmed) && trimmed.includes('-')
220
+ );
221
+ };
222
+
223
+ const parseTableRow = (line: string) => {
224
+ const decodedLine = decodeHTMLEntities(line.trim()).replace(/\u00A0/g, ' ');
225
+ const cleaned = decodedLine.replace(/^\||\|$/g, '');
226
+ const cells = cleaned
227
+ .split(/(?<!\\)\|/)
228
+ .map((c) => c.replace(/\\\|/g, '|').trim());
229
+ return cells.length > 0 ? cells : [''];
230
+ };
231
+
232
+ const renderMarkdownTableRN = (
233
+ headers: string[],
234
+ separator: string[],
235
+ dataRows: string[][]
236
+ ) => {
237
+ const aligns: Array<'left' | 'center' | 'right'> = headers.map((_, idx) => {
238
+ const seg = (separator[idx] || '').trim();
239
+ const left = seg.startsWith(':');
240
+ const right = seg.endsWith(':');
241
+ if (left && right) {return 'center';}
242
+ if (right) {return 'right';}
243
+ return 'left';
244
+ });
245
+
246
+ return (
247
+ <ScrollView
248
+ key={`table-${elementKeyCounter++}`}
249
+ horizontal
250
+ bounces={false}
251
+ showsHorizontalScrollIndicator={false}
252
+ style={styles.tableContainer}
253
+ >
254
+ <View style={styles.tableInner}>
255
+ <View style={styles.tableRow}>
256
+ {headers.map((h, cIdx) => (
257
+ <View
258
+ key={`th-${elementKeyCounter++}-${cIdx}`}
259
+ style={[styles.th, cIdx === headers.length - 1 && styles.lastCell]}
260
+ >
261
+ <Text
262
+ style={[
263
+ styles.cellText,
264
+ { fontWeight: '700', textAlign: aligns[cIdx] },
265
+ ]}
266
+ >
267
+ {parseInline(h)}
268
+ </Text>
269
+ </View>
270
+ ))}
271
+ </View>
272
+
273
+ {dataRows.map((row, rIdx) => (
274
+ <View key={`tr-${elementKeyCounter++}-${rIdx}`} style={styles.tableRow}>
275
+ {headers.map((_, cIdx) => {
276
+ const cell = row[cIdx] ?? '';
277
+ return (
278
+ <View
279
+ key={`td-${elementKeyCounter++}-${cIdx}`}
280
+ style={[styles.td, cIdx === headers.length - 1 && styles.lastCell]}
281
+ >
282
+ <Text style={[styles.cellText, { textAlign: aligns[cIdx] }]}>
283
+ {parseInline(cell)}
284
+ </Text>
285
+ </View>
286
+ );
287
+ })}
288
+ </View>
289
+ ))}
290
+ </View>
291
+ </ScrollView>
292
+ );
293
+ };
294
+
295
+ export const parseMessageBody = (text: string): JSX.Element => {
296
+ if (typeof text !== 'string') {
297
+ return <View />;
298
+ }
299
+
300
+ const lines = text.split('\n');
301
+ const elements: JSX.Element[] = [];
302
+ elementKeyCounter = 0;
303
+
304
+ let listBuffer: Array<{
305
+ type: 'ul' | 'checkbox';
306
+ content: string;
307
+ depth: number;
308
+ checked?: boolean;
309
+ }> = [];
310
+
311
+ let inCodeBlock = false;
312
+ let codeLang = '';
313
+ let codeLines: string[] = [];
314
+
315
+ const flushList = () => {
316
+ if (listBuffer.length === 0) {return;}
317
+
318
+ const renderListItems = (items: typeof listBuffer, depth: number): JSX.Element[] => {
319
+ const result: JSX.Element[] = [];
320
+ let i = 0;
321
+
322
+ while (i < items.length) {
323
+ const item = items[i];
324
+
325
+ if (item.depth === depth) {
326
+ const subItems: typeof listBuffer = [];
327
+ let j = i + 1;
328
+ while (j < items.length && items[j].depth > depth) {
329
+ subItems.push(items[j]);
330
+ j++;
331
+ }
332
+
333
+ const nested = subItems.length > 0 ? renderListItems(subItems, depth + 1) : null;
334
+
335
+ let contentEl: JSX.Element;
336
+ if (item.type === 'checkbox') {
337
+ contentEl = (
338
+ <View key={`checkbox-${elementKeyCounter++}`} style={styles.checkboxRow}>
339
+ <View style={[styles.checkboxBox, item.checked && { backgroundColor: '#e8f3ff', borderColor: '#0a66c2' }]}>
340
+ {item.checked ? <Text style={styles.checkboxTick}>✓</Text> : null}
341
+ </View>
342
+ <Text style={{ flex: 1 }}>{parseInline(item.content)}</Text>
343
+ </View>
344
+ );
345
+ } else {
346
+ contentEl = (
347
+ <View key={`ulitem-${elementKeyCounter++}`} style={styles.listItemRow}>
348
+ <Text style={styles.listMarker}>{'\u2022'}</Text>
349
+ <Text style={{ flex: 1 }}>{parseInline(item.content)}</Text>
350
+ </View>
351
+ );
352
+ }
353
+
354
+ result.push(
355
+ <View key={`liwrap-${elementKeyCounter++}`} style={{ marginBottom: 6, marginLeft: depth * 16 }}>
356
+ {contentEl}
357
+ {nested}
358
+ </View>
359
+ );
360
+ i = j;
361
+ } else {
362
+ i++;
363
+ }
364
+ }
365
+ return result;
366
+ };
367
+
368
+ const listContent = renderListItems(listBuffer, 0);
369
+ elements.push(
370
+ <View key={`list-${elementKeyCounter++}`} style={{ marginVertical: 8 }}>
371
+ {listContent}
372
+ </View>
373
+ );
374
+
375
+ listBuffer = [];
376
+ };
377
+
378
+ for (let i = 0; i < lines.length; i++) {
379
+ const line = lines[i];
380
+ const trimmedLine = line.trim();
381
+
382
+ if (trimmedLine.startsWith('```')) {
383
+ flushList();
384
+ inCodeBlock = !inCodeBlock;
385
+ if (!inCodeBlock) {
386
+ elements.push(
387
+ <View key={`pre-${elementKeyCounter++}`} style={styles.codeBlock}>
388
+ <Text style={styles.codeBlockText} selectable>
389
+ {codeLines.join('\n')}
390
+ </Text>
391
+ </View>
392
+ );
393
+ codeLang = '';
394
+ } else {
395
+ codeLang = trimmedLine.slice(3).trim();
396
+ codeLines = [];
397
+ }
398
+ continue;
399
+ }
400
+ if (inCodeBlock) {
401
+ codeLines.push(line);
402
+ continue;
403
+ }
404
+
405
+ const headingMatch = trimmedLine.match(/^(#{1,6})\s+(.*)/);
406
+ if (headingMatch) {
407
+ flushList();
408
+ const level = Math.min(6, Math.max(1, headingMatch[1].length));
409
+ const content = headingMatch[2];
410
+ elements.push(
411
+ <Text key={`h-${elementKeyCounter++}`} style={styles.h[level - 1]}>
412
+ {parseInline(content)}
413
+ </Text>
414
+ );
415
+ continue;
416
+ }
417
+
418
+ if (/^(\*|\-|\_){3,}$/.test(trimmedLine)) {
419
+ flushList();
420
+ elements.push(<View key={`hr-${elementKeyCounter++}`} style={styles.hr} />);
421
+ continue;
422
+ }
423
+
424
+ if (
425
+ trimmedLine.includes('|') &&
426
+ trimmedLine !== '' &&
427
+ !isTableSeparatorLine(trimmedLine) &&
428
+ !trimmedLine.match(/^\s*-?\s*\[[\sxX]\]/)
429
+ ) {
430
+ let separatorIndex = i + 1;
431
+ while (separatorIndex < lines.length && lines[separatorIndex].trim() === '') {
432
+ separatorIndex++;
433
+ }
434
+
435
+ if (separatorIndex < lines.length && isTableSeparatorLine(lines[separatorIndex].trim())) {
436
+ flushList();
437
+
438
+ const rows: string[][] = [];
439
+ const headers = parseTableRow(trimmedLine);
440
+ const headerCount = headers.length;
441
+ rows.push(headers);
442
+
443
+ const sep = parseTableRow(lines[separatorIndex].trim());
444
+
445
+ let current = separatorIndex + 1;
446
+ while (current < lines.length) {
447
+ const nextLine = lines[current].trim();
448
+ if (nextLine === '') {
449
+ current++;
450
+ continue;
451
+ }
452
+ if (
453
+ nextLine.includes('|') &&
454
+ !isTableSeparatorLine(nextLine) &&
455
+ !nextLine.match(/^\s*-?\s*\[[\sxX]\]/)
456
+ ) {
457
+ let rowCells = parseTableRow(nextLine);
458
+ while (rowCells.length < headerCount) {rowCells.push('');}
459
+ rowCells = rowCells.slice(0, headerCount);
460
+ rows.push(rowCells);
461
+ current++;
462
+ } else {
463
+ break;
464
+ }
465
+ }
466
+
467
+ const dataRows = rows.slice(1);
468
+ elements.push(renderMarkdownTableRN(headers, sep, dataRows));
469
+ i = current - 1;
470
+ continue;
471
+ }
472
+ }
473
+
474
+ const listMatch = line.match(/^(\s*)(?:-|\*|\+)?\s*(\[[\sxX]\])\s*(.*)/);
475
+ if (listMatch) {
476
+ const leadingSpace = listMatch[1];
477
+ const checkboxPart = listMatch[2];
478
+ const content = listMatch[3];
479
+ const depth = Math.floor(leadingSpace.length / 2);
480
+ const checked = checkboxPart.toLowerCase() === '[x]';
481
+ listBuffer.push({ type: 'checkbox', content: decodeHTMLEntities(content), depth, checked });
482
+ continue;
483
+ }
484
+
485
+ const bulletMatch = line.match(/^(\s*)([-*+])\s+(.*)/);
486
+ if (bulletMatch && bulletMatch[3].trim() !== '') {
487
+ const depth = Math.floor(bulletMatch[1].length / 2);
488
+ listBuffer.push({ type: 'ul', content: decodeHTMLEntities(bulletMatch[3]), depth });
489
+ continue;
490
+ }
491
+
492
+ if (trimmedLine !== '') {
493
+ flushList();
494
+ elements.push(
495
+ <View key={`p-${elementKeyCounter++}`} style={styles.paragraph}>
496
+ <Text>{parseInline(trimmedLine)}</Text>
497
+ </View>
498
+ );
499
+ } else {
500
+ flushList();
501
+ }
502
+ }
503
+
504
+ flushList();
505
+
506
+ return (
507
+ <View
508
+ style={{
509
+ }}
510
+ >
511
+ {elements}
512
+ </View>
513
+ );
514
+ };
515
+
516
+ export default parseMessageBody;
@@ -0,0 +1,42 @@
1
+ export const parseMessageBody = (text: string): (string | JSX.Element)[] => {
2
+ if (typeof text !== 'string') {return [text];}
3
+
4
+ const urlRegex =
5
+ /(https:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+)/g;
6
+ const parts: (string | JSX.Element)[] = [];
7
+ let lastIndex = 0;
8
+ let match: any;
9
+
10
+ while ((match = urlRegex.exec(text)) !== null) {
11
+ const index = match.index;
12
+ const url = match[0];
13
+
14
+ if (index > lastIndex) {
15
+ parts.push(text.substring(lastIndex, index));
16
+ }
17
+
18
+ parts.push(
19
+ <a
20
+ key={index}
21
+ href={url}
22
+ target="_blank"
23
+ rel="noopener noreferrer"
24
+ style={{ color: 'blue', textDecoration: 'underline' }}
25
+ >
26
+ {url}
27
+ </a>
28
+ );
29
+
30
+ lastIndex = index + url.length;
31
+ }
32
+
33
+ if (lastIndex < text.length) {
34
+ parts.push(text.substring(lastIndex));
35
+ }
36
+
37
+ if (parts.length === 0 && lastIndex === 0) {
38
+ return [text];
39
+ }
40
+
41
+ return parts;
42
+ };