@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,400 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import {
3
+ View,
4
+ TouchableWithoutFeedback,
5
+ StyleSheet,
6
+ findNodeHandle,
7
+ UIManager,
8
+ Dimensions,
9
+ Text,
10
+ } from 'react-native';
11
+ import { useDispatch, useSelector } from 'react-redux';
12
+ import { RootState } from '../../roomStore';
13
+ import { Avatar } from './Avatar';
14
+ import MessageInteractions from './MessageInteractions';
15
+ import { BottomReplyContainer } from './BottomReplyContainer';
16
+ import { MessageReply } from './MessageReply';
17
+ import { DeletedMessage } from './DeletedMessage';
18
+ import {
19
+ setActiveModal,
20
+ setDeleteModal,
21
+ setSelectedUser,
22
+ } from '../../roomStore/chatSettingsSlice';
23
+ import { MODAL_TYPES } from '../../helpers/constants/MODAL_TYPES';
24
+ import { setActiveMessage, setEditAction } from '../../roomStore/roomsSlice';
25
+ import styled from 'styled-components/native';
26
+ import { IUser, MessageProps } from '../../types/types';
27
+ import MediaMessage from '../MainComponents/MediaMessage';
28
+ import MessageTranslations from './MessageTranslations';
29
+ import { useChatSettingState } from '../../hooks/useChatSettingState';
30
+ import { parseMessageBody } from '../../helpers/parseMessageBody';
31
+ import { useMessageHeapState } from '../../hooks/useMessageHeapState';
32
+ import { DoubleTick } from '../../assets/icons';
33
+ import { useXmppClient } from '../../context/xmppProvider';
34
+ import { MessageReaction } from './MessageReaction';
35
+ import { MessageFooter } from '../styled/StyledComponents';
36
+
37
+ const CustomMessageContainer = styled.View<{ isUser: boolean; reply?: number }>`
38
+ flex-direction: row;
39
+ padding: 10px;
40
+ align-items: flex-end;
41
+ justify-content: ${({ isUser }) => (isUser ? 'flex-end' : 'flex-start')};
42
+ margin-bottom: ${(props) => (props.reply ? '20px' : '0px')};
43
+ `;
44
+
45
+ const CustomMessageBubble = styled.View<{
46
+ isUser: boolean;
47
+ deleted?: boolean;
48
+ backgroundMessageUser?: string;
49
+ backgroundMessage?: string;
50
+ }>`
51
+ position: relative;
52
+ max-width: 85%;
53
+ min-width: 30%;
54
+ padding: 10px;
55
+ margin-right: ${({isUser}) => isUser ? '0' : '10px'};
56
+ margin-left: ${({isUser}) => isUser ? '10px' : '0'};
57
+ border-radius: 10px;
58
+ border-bottom-left-radius: ${({ isUser }) => (isUser ? '10' : '0')}px;
59
+ border-bottom-right-radius: ${({ isUser }) => (isUser ? '0' : '10')}px;
60
+ background-color: ${({
61
+ isUser,
62
+ deleted,
63
+ backgroundMessageUser,
64
+ backgroundMessage,
65
+ }) =>
66
+ deleted
67
+ ? '#f5f5f5'
68
+ : isUser
69
+ ? backgroundMessageUser || '#d1e7ff'
70
+ : backgroundMessage || '#fff'};
71
+ `;
72
+
73
+ const CustomMessageText = styled.Text<{
74
+ isUser: boolean;
75
+ colorUser?: string;
76
+ color?: string;
77
+ }>`
78
+ font-size: 16px;
79
+ color: ${({ color, colorUser, isUser }) =>
80
+ isUser ? colorUser || '#333' : color || '#333'};
81
+ `;
82
+
83
+ const CustomMessagePhoto = styled.Image`
84
+ width: 40px;
85
+ height: 40px;
86
+ border-radius: 20px;
87
+ `;
88
+
89
+ const CustomMessagePhotoContainer = styled.TouchableOpacity`
90
+ margin-right: 10px;
91
+ `;
92
+
93
+ const CustomUserName = styled.Text<{ color?: string }>`
94
+ font-size: 14px;
95
+ font-weight: 500;
96
+ color: ${({ color }) => color || '#333'};
97
+ `;
98
+
99
+ const CustomMessageTimestamp = styled.Text<{
100
+ isUser?: boolean;
101
+ color?: string;
102
+ colorUser?: string;
103
+ }>`
104
+ font-size: 12px;
105
+ color: #999;
106
+ color: ${({ isUser, color, colorUser }) =>
107
+ isUser ? colorUser || '#999' : color || '#999'};
108
+ margin-top: 5px;
109
+ align-self: flex-end;
110
+ `;
111
+
112
+ const Message: React.FC<MessageProps> = ({ message, isUser, isReply }) => {
113
+ const dispatch = useDispatch();
114
+ const { client } = useXmppClient();
115
+ const { config, langSource, user} = useChatSettingState();
116
+ const { idSet } = useMessageHeapState();
117
+
118
+ const [isPressed, setIsPressed] = useState(false);
119
+
120
+ const [contextMenuPosition, setContextMenuPosition] = useState<{
121
+ x: number;
122
+ y: number;
123
+ } | null>(null);
124
+
125
+ const timerRef = useRef<NodeJS.Timeout | null>(null);
126
+ const messageRef = useRef<View>(null);
127
+
128
+ const handleUserAvatarClick = (user: IUser): void => {
129
+ dispatch(setActiveModal(MODAL_TYPES.PROFILE));
130
+ dispatch(setSelectedUser(user));
131
+ };
132
+
133
+ const handleReplyMessage = () => {
134
+ dispatch(setEditAction({ isEdit: false }));
135
+
136
+ if (!isReply && message.mainMessage) {
137
+ const messageCore = JSON.parse(message.mainMessage);
138
+ dispatch(
139
+ setActiveMessage({ id: messageCore.id, chatJID: messageCore.roomJid })
140
+ );
141
+
142
+ return setIsPressed(false);
143
+ }
144
+
145
+ dispatch(setActiveMessage({ id: message.id, chatJID: message.roomJid }));
146
+
147
+ return setIsPressed(false);
148
+ };
149
+
150
+ const handleDeleteMessage = () => {
151
+ dispatch(
152
+ setDeleteModal({
153
+ isDeleteModal: true,
154
+ roomJid: message.roomJid,
155
+ messageId: message.id,
156
+ })
157
+ );
158
+ setIsPressed(false);
159
+ };
160
+
161
+ const handleEditMessage = () => {
162
+ dispatch(
163
+ setEditAction({
164
+ isEdit: true,
165
+ roomJid: message.roomJid,
166
+ messageId: message.id,
167
+ text: message.body,
168
+ })
169
+ );
170
+
171
+ return setIsPressed(false);
172
+ };
173
+
174
+ // const handleLongPress = () => {
175
+ // setIsPressed(true);
176
+ // console.log("setIsPressed", isPressed);
177
+ // };
178
+
179
+ const handleReactionMessage = (emoji: string) => {
180
+ if (!message.reaction) {
181
+ return client.sendMessageReactionStanza(
182
+ message.id,
183
+ message.roomJid,
184
+ [emoji],
185
+ { firstName: user.firstName, lastName: user.lastName }
186
+ );
187
+ }
188
+ if (
189
+ message.reaction &&
190
+ message.reaction[user.xmppUsername || ''] &&
191
+ message.reaction[user.xmppUsername || '']?.emoji.includes(emoji)
192
+ ) {
193
+ const filterEmoji = message.reaction[user.xmppUsername || '']?.emoji.filter(
194
+ (reaction) => reaction !== emoji
195
+ );
196
+
197
+ return client.sendMessageReactionStanza(
198
+ message.id,
199
+ message.roomJid,
200
+ filterEmoji,
201
+ { firstName: user.firstName, lastName: user.lastName }
202
+ );
203
+ }
204
+
205
+ client.sendMessageReactionStanza(
206
+ message.id,
207
+ message.roomJid,
208
+ [...(message.reaction[user.xmppUsername || '']?.emoji || []), emoji],
209
+ { firstName: user.firstName, lastName: user.lastName }
210
+ );
211
+ };
212
+
213
+ const handleLongPress = () => {
214
+ if (messageRef.current) {
215
+ const nodeHandle = findNodeHandle(messageRef.current);
216
+ if (nodeHandle) {
217
+ UIManager.measure(nodeHandle, (x, y, width, height, pageX, pageY) => {
218
+ const screenHeight = Dimensions.get('window').height;
219
+
220
+ const enoughSpaceBelow = screenHeight - pageY - height > 150;
221
+ setContextMenuPosition({
222
+ x: pageX,
223
+ y: enoughSpaceBelow ? pageY + height : pageY - 150,
224
+ });
225
+ });
226
+ }
227
+ }
228
+ setIsPressed(true);
229
+ };
230
+
231
+ const messageText = config?.messageTextFilter?.enabled
232
+ ? parseMessageBody(config?.messageTextFilter.filterFunction(message.body))
233
+ : parseMessageBody(message.body);
234
+
235
+ const isPending = idSet.has(message.id) || message?.pending || false;
236
+
237
+ return (
238
+ <View>
239
+ {isPressed && <View style={styles.overlay} />}
240
+ <View
241
+ ref={messageRef}
242
+ style={[
243
+ styles.customMessageContainer,
244
+ {
245
+ justifyContent: isUser ? 'flex-end' : 'flex-start',
246
+ marginBottom: !!message?.reply?.length || message?.reaction && !!Object.keys(message?.reaction)?.length
247
+ ? 20 : 0,
248
+ },
249
+ isPressed
250
+ ? { transform: [{ scale: 1.05 }], paddingRight: 16 }
251
+ : undefined,
252
+ // justify-content: ${({ isUser }) => (isUser ? "flex-end" : "flex-start")},
253
+ // margin-bottom: ${(props) => !!props.reply && "20px"},
254
+ ]}
255
+ >
256
+ {!isUser && (
257
+ <CustomMessagePhotoContainer
258
+ onPress={() => handleUserAvatarClick(message.user)}
259
+ >
260
+ {message.user?.profileImage ? (
261
+ <CustomMessagePhoto source={{ uri: message.user.profileImage }} />
262
+ ) : (
263
+ <Avatar username={message.user.name} />
264
+ )}
265
+ </CustomMessagePhotoContainer>
266
+ )}
267
+ <TouchableWithoutFeedback
268
+ // disableInteractions hides the long-press → context menu
269
+ // (delete / edit / reply / react). Mirrors web's config gate.
270
+ onLongPress={
271
+ config?.disableInteractions ? undefined : handleLongPress
272
+ }
273
+ delayLongPress={500}
274
+ >
275
+ <CustomMessageBubble
276
+ isUser={isUser}
277
+ deleted={message.isDeleted}
278
+ backgroundMessageUser={config?.messageColor?.backgroundMessageUser}
279
+ backgroundMessage={config?.messageColor?.backgroundMessage}
280
+ >
281
+ {!isUser && (
282
+ <CustomUserName color={config?.colors?.primary}>
283
+ {message.user.name}
284
+ </CustomUserName>
285
+ )}
286
+ {!isReply && message.mainMessage && (
287
+ <MessageReply
288
+ handleReplyMessage={handleReplyMessage}
289
+ isUser={isUser}
290
+ text={JSON.parse(message.mainMessage).text}
291
+ color={config?.colors?.primary}
292
+ />
293
+ )}
294
+
295
+ {message?.isMediafile === 'true' && !message?.isDeleted ? (
296
+ <MediaMessage
297
+ mimeType={message.mimetype}
298
+ messageText={message.locationPreview}
299
+ location={message?.location}
300
+ message={message}
301
+ />
302
+ ) : (
303
+ <>
304
+ {message.isDeleted && message.id !== 'delimiter-new' ? (
305
+ <DeletedMessage />
306
+ ) : (
307
+ <CustomMessageText
308
+ isUser={isUser}
309
+ colorUser={config?.messageColor?.colorUser}
310
+ color={config?.messageColor?.color}
311
+ >
312
+ <Text>{messageText}</Text>
313
+ </CustomMessageText>
314
+ )}
315
+ </>
316
+ )}
317
+ {config?.enableTranslates && (
318
+ <MessageTranslations
319
+ message={message}
320
+ config={config}
321
+ langSource={langSource}
322
+ />
323
+ )}
324
+ <CustomMessageTimestamp>
325
+ {!config?.disableSentLogic && isUser && isPending && <Text>sending...</Text>}
326
+ {new Date(message.date).toLocaleTimeString([], {
327
+ hour: '2-digit',
328
+ minute: '2-digit',
329
+ })}
330
+ {!config?.disableSentLogic && isUser && !isPending && (
331
+ <DoubleTick />
332
+ )}
333
+ </CustomMessageTimestamp>
334
+
335
+ {message?.reply?.length && message?.reply?.length > 0 ? (
336
+ <BottomReplyContainer
337
+ isUser={isUser}
338
+ onClick={handleReplyMessage}
339
+ reply={message?.reply}
340
+ />
341
+ ) : (
342
+ <View />
343
+ )}
344
+
345
+ <MessageFooter isUser={isUser}>
346
+
347
+ {message.reaction && !config?.disableReactions && (
348
+ <MessageReaction
349
+ reaction={message.reaction}
350
+ changeReaction={handleReactionMessage}
351
+ color={config?.colors?.primary || '#0052CD'}
352
+ userName={`${user.firstName} ${user.lastName}`}
353
+ />
354
+ )}
355
+ </MessageFooter>
356
+ </CustomMessageBubble>
357
+ </TouchableWithoutFeedback>
358
+ </View>
359
+ {!config?.disableInteractions && isPressed && (
360
+ <MessageInteractions
361
+ position={contextMenuPosition}
362
+ isReply={isReply}
363
+ isUser={isUser}
364
+ message={message}
365
+ closeMenu={() => setIsPressed(false)}
366
+ handleReplyMessage={handleReplyMessage}
367
+ handleDeleteMessage={handleDeleteMessage}
368
+ handleEditMessage={handleEditMessage}
369
+ handleReactionMessage={handleReactionMessage}
370
+ />
371
+ )}
372
+ </View>
373
+ );
374
+ };
375
+
376
+ export { Message };
377
+
378
+ const styles = StyleSheet.create({
379
+ customMessageContainer: {
380
+ flexDirection: 'row',
381
+ padding: 10,
382
+ alignItems: 'flex-end',
383
+ position: 'relative',
384
+ },
385
+ overlay: {
386
+ ...StyleSheet.absoluteFillObject,
387
+ position: 'absolute',
388
+ top: 0,
389
+ left: 0,
390
+ width: '100%',
391
+ height: '100%',
392
+ // backgroundColor: "rgba(0, 0, 0, 0.3)",
393
+ },
394
+ timestamp: {
395
+ fontSize: 12,
396
+ color: '#999',
397
+ marginTop: 5,
398
+ alignSelf: 'flex-end',
399
+ },
400
+ });
@@ -0,0 +1,247 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import {
3
+ ContextMenu,
4
+ Delimeter,
5
+ MenuItem,
6
+ Overlay,
7
+ } from '../ContextMenu/ContextMenuComponents';
8
+ import { useDispatch, useSelector } from 'react-redux';
9
+ import { RootState } from '../../roomStore';
10
+ import {
11
+ MESSAGE_INTERACTIONS,
12
+ MESSAGE_INTERACTIONS_ICONS,
13
+ } from '../../helpers/constants/MESSAGE_INTERACTIONS';
14
+ import { IMessage } from '../../types/types';
15
+ import { useXmppClient } from '../../context/xmppProvider';
16
+ import { setActiveMessage } from '../../roomStore/roomsSlice';
17
+ import {
18
+ Alert,
19
+ Modal,
20
+ Text,
21
+ TouchableWithoutFeedback,
22
+ StyleSheet,
23
+ View,
24
+ Pressable,
25
+ } from 'react-native';
26
+ import Clipboard from '@react-native-clipboard/clipboard';
27
+ import { useToast } from '../../context/ToastContext';
28
+ import EmojiPicker from 'react-native-emoji-selector';
29
+
30
+ const fixedEmojiIds = ['joy', 'heart', 'fire', '+1', 'smile', 'scream'];
31
+
32
+ function convertIdToEmoji(id: string) {
33
+ const mapping = {
34
+ joy: '😂',
35
+ heart: '❤️',
36
+ fire: '🔥',
37
+ '+1': '👍',
38
+ smile: '😄',
39
+ scream: '😱',
40
+ };
41
+ return mapping[id as keyof typeof mapping] || '❓';
42
+ }
43
+
44
+ interface MessageInteractionsProps {
45
+ isReply?: boolean;
46
+ isUser?: boolean;
47
+ message: IMessage;
48
+ position: { x: number; y: number } | null;
49
+ closeMenu: () => void;
50
+ handleReplyMessage: () => void;
51
+ handleDeleteMessage: () => void;
52
+ handleEditMessage: () => void;
53
+ handleReactionMessage: (id: string) => void;
54
+ }
55
+
56
+ const MessageInteractions: React.FC<MessageInteractionsProps> = ({
57
+ isReply,
58
+ isUser,
59
+ message,
60
+ closeMenu,
61
+ position,
62
+ handleReplyMessage: replyMessage,
63
+ handleDeleteMessage,
64
+ handleEditMessage,
65
+ handleReactionMessage,
66
+ }) => {
67
+ const { client } = useXmppClient();
68
+ const dispatch = useDispatch();
69
+ const { showToast } = useToast();
70
+
71
+ const [pickerVisible, setPickerVisible] = useState(false);
72
+
73
+ const handleReactionClick = (id: string) => {
74
+ handleReactionMessage(id);
75
+ closeMenu();
76
+ };
77
+
78
+ const onClose = () => {
79
+ setPickerVisible(false);
80
+ };
81
+
82
+ // const handleDeleteMessage = (roomJid: string, messageId: string) => {
83
+ // // dispatch(deleteRoomMessage({ roomJID: room, messageId: msgId }));
84
+ // client.deleteMessageStanza(roomJid, messageId);
85
+ // };
86
+
87
+ const config = useSelector(
88
+ (state: RootState) => state.chatSettingStore.config
89
+ );
90
+
91
+ const closeContextMenu = () => {
92
+ // if (!config?.disableInteractions) {
93
+ // setContextMenu({ visible: false, x: 0, y: 0 });
94
+ // }
95
+ };
96
+
97
+ const handleCopyMessage = (text: string) => {
98
+ Clipboard.setString(text);
99
+ showToast({
100
+ id: Date.now().toString(),
101
+ title: 'Success',
102
+ message: 'Copied to clipboard!',
103
+ type: 'success',
104
+ });
105
+ closeMenu();
106
+ };
107
+
108
+ const handleReplyMessage = () => {
109
+ replyMessage();
110
+ };
111
+
112
+ const memoPosition = useMemo(() => {
113
+ if (position) {
114
+ if (isUser) {
115
+ return {
116
+ top: position.y,
117
+ right: 10,
118
+ };
119
+ }
120
+
121
+ return {
122
+ top: position.y,
123
+ left: 10,
124
+ };
125
+ }
126
+ }, [position, isUser]);
127
+
128
+ if (config?.disableInteractions) {return null;}
129
+
130
+ return (
131
+ <Modal
132
+ transparent
133
+ animationType="fade"
134
+ visible={true}
135
+ onRequestClose={closeMenu}
136
+ >
137
+ {!message.isDeleted && (
138
+ <Overlay onPress={closeMenu}>
139
+ <ContextMenu
140
+ style={[styles.contextMenu, memoPosition]}
141
+ // style={{ top: contextMenu.y, left: contextMenu.x }}
142
+ >
143
+ {/* <MenuItem onClick={() => console.log(MESSAGE_INTERACTIONS.SEND_COINS)}>
144
+ {MESSAGE_INTERACTIONS.SEND_COINS}
145
+ <MESSAGE_INTERACTIONS_ICONS.SEND_COINS />{' '}
146
+ </MenuItem>
147
+ <Delimeter />
148
+ <MenuItem onClick={() => console.log(MESSAGE_INTERACTIONS.SEND_ITEM)}>
149
+ {MESSAGE_INTERACTIONS.SEND_ITEM}
150
+ <MESSAGE_INTERACTIONS_ICONS.SEND_ITEM />{' '}
151
+ </MenuItem> */}
152
+ {/* Reaction row — hidden when consumer sets
153
+ `config.disableReactions: true`. Mirrors the gate web
154
+ applies inside its MessageInteractions panel. */}
155
+ {!config?.disableReactions && (
156
+ <View style={{ flexDirection: 'row', paddingBottom: 10 }}>
157
+ {fixedEmojiIds.map((id) => (
158
+ <Pressable
159
+ key={id}
160
+ onPress={() => handleReactionClick(id)}
161
+ style={{ marginRight: 6 }}
162
+ >
163
+ <Text style={{ fontSize: 26 }}>{convertIdToEmoji(id)}</Text>
164
+ </Pressable>
165
+ ))}
166
+
167
+ {/* ArrowButton */}
168
+ <Pressable
169
+ onPress={() => setPickerVisible(!pickerVisible)}
170
+ style={{ marginLeft: 10 }}
171
+ >
172
+ <Text style={{ fontSize: 24 }}>⌄</Text>
173
+ </Pressable>
174
+ </View>
175
+ )}
176
+
177
+ {!config?.disableReactions && pickerVisible && (
178
+ <View style={{ height: 250 }}>
179
+ <EmojiPicker
180
+ onEmojiSelected={(emoji) => {
181
+ handleReactionClick(emoji);
182
+ }}
183
+ showSearchBar={false}
184
+ showTabs={false}
185
+ />
186
+ </View>
187
+ )}
188
+
189
+ {!isReply && (
190
+ <>
191
+ <MenuItem onPress={handleReplyMessage}>
192
+ <Text>{MESSAGE_INTERACTIONS.REPLY}</Text>
193
+ <MESSAGE_INTERACTIONS_ICONS.REPLY />
194
+ </MenuItem>
195
+ <Delimeter />
196
+ </>
197
+ )}
198
+ <MenuItem onPress={() => handleCopyMessage(message.body!)}>
199
+ <Text>{MESSAGE_INTERACTIONS.COPY}</Text>
200
+ <MESSAGE_INTERACTIONS_ICONS.COPY />
201
+ </MenuItem>
202
+ <Delimeter />
203
+ {isUser && (
204
+ <>
205
+ <MenuItem onPress={handleEditMessage}>
206
+ <Text>{MESSAGE_INTERACTIONS.EDIT}</Text>
207
+ <MESSAGE_INTERACTIONS_ICONS.EDIT />
208
+ </MenuItem>
209
+ <Delimeter />
210
+ </>
211
+ )}
212
+ <MenuItem onPress={handleDeleteMessage}>
213
+ <Text>{MESSAGE_INTERACTIONS.DELETE}</Text>
214
+ <MESSAGE_INTERACTIONS_ICONS.DELETE />
215
+ </MenuItem>
216
+ {/* <Delimeter />
217
+ <MenuItem onClick={() => console.log(MESSAGE_INTERACTIONS.REPORT)}>
218
+ {MESSAGE_INTERACTIONS.REPORT}
219
+ <MESSAGE_INTERACTIONS_ICONS.REPORT />{' '}
220
+ </MenuItem> */}
221
+ </ContextMenu>
222
+ </Overlay>
223
+ )}
224
+
225
+ </Modal>
226
+ );
227
+ };
228
+
229
+ export default MessageInteractions;
230
+
231
+ const styles = StyleSheet.create({
232
+ overlay: {
233
+ ...StyleSheet.absoluteFillObject,
234
+ backgroundColor: 'rgba(0, 0, 0, 0.3)',
235
+ },
236
+ contextMenu: {
237
+ position: 'absolute',
238
+ backgroundColor: 'white',
239
+ padding: 10,
240
+ borderRadius: 8,
241
+ shadowColor: '#000',
242
+ shadowOffset: { width: 0, height: 2 },
243
+ shadowOpacity: 0.25,
244
+ shadowRadius: 4,
245
+ elevation: 5,
246
+ },
247
+ });