@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,318 @@
1
+ import React, {FC, useEffect, useMemo, useState} from 'react';
2
+ import {useDispatch, useSelector} from 'react-redux';
3
+ import ChatRoom from './ChatRoom';
4
+ import {
5
+ setActiveModal,
6
+ setConfig,
7
+ setDeleteModal,
8
+ setStoreClient,
9
+ } from '../../roomStore/chatSettingsSlice';
10
+ import {ChatWrapperBox} from '../styled/ChatWrapperBox';
11
+ import {Overlay, StyledModal} from '../styled/MediaModal';
12
+ import {Message} from '../MessageBubble/Message';
13
+ import {IConfig, IRoom, MessageProps, ModalType, User} from '../../types/types';
14
+ import {useXmppClient} from '../../context/xmppProvider';
15
+ import LoginForm from '../AuthForms/Login';
16
+ import {RootState} from '../../roomStore';
17
+ import Loader from '../styled/Loader';
18
+ import {
19
+ setCurrentRoom,
20
+ setEditAction,
21
+ setIsLoading,
22
+ setLastViewedTimestamp,
23
+ } from '../../roomStore/roomsSlice';
24
+ import {refresh} from '../../networking/apiClient';
25
+ import RoomList from './RoomList';
26
+ import {StyledLoaderWrapper} from '../styled/StyledComponents';
27
+ import Modal from '../Modals/Modal/Modal';
28
+ import ThreadWrapper from '../Thread/ThreadWrapper';
29
+ import {ModalWrapper} from '../Modals/ModalWrapper/ModalWrapper';
30
+ import {useChatSettingState} from '../../hooks/useChatSettingState';
31
+ import {Text} from 'react-native';
32
+ import {pushLog as devPushLog} from '../../utils/devLogger';
33
+
34
+ interface ChatWrapperProps {
35
+ token?: string;
36
+ room?: IRoom;
37
+ loginData?: {email: string; password: string};
38
+ MainComponentStyles?: React.CSSProperties; //change to particular types
39
+ CustomMessageComponent?: React.ComponentType<MessageProps>;
40
+ config?: IConfig;
41
+ roomJID?: string;
42
+ }
43
+
44
+ const ChatWrapper: FC<ChatWrapperProps> = ({
45
+ MainComponentStyles,
46
+ CustomMessageComponent,
47
+ room,
48
+ config,
49
+ roomJID,
50
+ }) => {
51
+ const {
52
+ user,
53
+ activeModal,
54
+ deleteModal,
55
+ client: storedClient,
56
+ } = useChatSettingState();
57
+
58
+ const [isInited, setInited] = useState(false);
59
+ const [showModal, setShowModal] = useState(false);
60
+ // const [isModalDeleteOpen, setIsModalDeleteOpen] = useState(false);
61
+
62
+ const [isChatVisible, setIsChatVisible] = useState(false);
63
+ const [isSmallScreen, setIsSmallScreen] = useState(false);
64
+
65
+ const handleItemClick = (value: boolean) => {
66
+ setIsChatVisible(value);
67
+ };
68
+
69
+ const dispatch = useDispatch();
70
+ const {
71
+ client,
72
+ initializeClient,
73
+ setClient,
74
+ providerBootstrapStatus,
75
+ initMode,
76
+ } = useXmppClient();
77
+
78
+ const {rooms, activeRoomJID} = useSelector((state: RootState) => state.rooms);
79
+
80
+ const activeMessage = useMemo(() => {
81
+ if (activeRoomJID) {
82
+ return rooms[activeRoomJID]?.messages?.find(
83
+ message => message?.activeMessage,
84
+ );
85
+ }
86
+ }, [rooms, activeRoomJID]);
87
+
88
+ const handleChangeChat = (chat: IRoom) => {
89
+ dispatch(setCurrentRoom({roomJID: chat.jid}));
90
+ activeRoomJID !== chat.jid &&
91
+ dispatch(setIsLoading({chatJID: chat.jid, loading: true}));
92
+ dispatch(setEditAction({isEdit: false}));
93
+ handleItemClick(true);
94
+ };
95
+
96
+ const handleDeleteClick = () => {
97
+ if (!client || !deleteModal?.roomJid || !deleteModal?.messageId) {
98
+ dispatch(setDeleteModal({isDeleteModal: false}));
99
+ return;
100
+ }
101
+ client.deleteMessageStanza(deleteModal.roomJid, deleteModal.messageId);
102
+ dispatch(setDeleteModal({isDeleteModal: false}));
103
+ };
104
+
105
+ const handleCloseDeleteModal = () => {
106
+ dispatch(setDeleteModal({isDeleteModal: false}));
107
+ };
108
+
109
+ useEffect(() => {
110
+ return () => {
111
+ if (client && user.xmppPassword === '') {
112
+ console.log('closing client');
113
+ client.close();
114
+ setClient(null);
115
+ }
116
+ };
117
+ }, [user.xmppPassword]);
118
+
119
+ // Tell the XMPP client which room is currently active so the QoS
120
+ // scheduler can prioritize its history fetches.
121
+ useEffect(() => {
122
+ if (!client) {return;}
123
+ client.setActiveRoomJid?.(activeRoomJID || null);
124
+ }, [client, activeRoomJID]);
125
+
126
+ useEffect(() => {
127
+ if (roomJID) {
128
+ dispatch(setCurrentRoom({roomJID: roomJID}));
129
+ }
130
+
131
+ const initXmmpClient = async () => {
132
+ // Only sync config to redux if we have one — passing `undefined`
133
+ // wipes whatever XmppProvider already set up.
134
+ if (config) {dispatch(setConfig(config));}
135
+ try {
136
+ const hasUser =
137
+ !!user?.defaultWallet?.walletAddress &&
138
+ user?.defaultWallet.walletAddress !== '' &&
139
+ !!user?.xmppPassword;
140
+
141
+ // initBeforeLoad path — provider owns auth + xmpp connect; we just wait.
142
+ if (config?.initBeforeLoad && initMode === 'provider') {
143
+ if (providerBootstrapStatus === 'failed') {
144
+ devPushLog('error', 'ChatWrapper: bootstrap failed');
145
+ setShowModal(true);
146
+ setInited(false);
147
+ return;
148
+ }
149
+ if (providerBootstrapStatus !== 'ready') {
150
+ // 'idle' or 'running' → just wait; effect will re-run when status flips.
151
+ devPushLog(
152
+ 'rn',
153
+ `ChatWrapper: waiting for provider (${providerBootstrapStatus})`
154
+ );
155
+ return;
156
+ }
157
+ // ready — fall through to client wiring below
158
+ }
159
+
160
+ if (!hasUser) {
161
+ // No user yet. In initBeforeLoad mode this is normal during the
162
+ // bootstrap window; show the loader (no modal). In legacy mode
163
+ // it's an error.
164
+ if (config?.initBeforeLoad) {
165
+ devPushLog('rn', 'ChatWrapper: no user yet, awaiting provider');
166
+ setShowModal(false);
167
+ return;
168
+ }
169
+ devPushLog('error', 'ChatWrapper: no user (legacy login path)');
170
+ setShowModal(true);
171
+ return;
172
+ }
173
+
174
+ // We have a user. Modal should be down.
175
+ setShowModal(false);
176
+
177
+ if (!client && !storedClient) {
178
+ devPushLog('rn', 'ChatWrapper: initing xmpp client (legacy path)');
179
+ await initializeClient(
180
+ user.xmppUsername || user.defaultWallet?.walletAddress,
181
+ user.xmppPassword,
182
+ config?.xmppSettings,
183
+ ).then(c => {
184
+ c.getRoomsStanza().then(() => {
185
+ c.getChatsPrivateStoreRequestStanza();
186
+ dispatch(setStoreClient(c));
187
+ setClient(c);
188
+ });
189
+ });
190
+ setInited(true);
191
+ if (config?.refreshTokens?.enabled) {refresh();}
192
+ } else if (storedClient) {
193
+ devPushLog('rn', 'ChatWrapper: reusing storedClient');
194
+ setClient(storedClient);
195
+ if (!activeRoomJID) {
196
+ storedClient.getRoomsStanza().then(() => {
197
+ storedClient.getChatsPrivateStoreRequestStanza();
198
+ });
199
+ }
200
+ setInited(true);
201
+ if (config?.refreshTokens?.enabled) {refresh();}
202
+ } else if (client) {
203
+ devPushLog('rn', 'ChatWrapper: reusing provider client');
204
+ if (!activeRoomJID) {
205
+ client.getRoomsStanza().then(() => {
206
+ client.getChatsPrivateStoreRequestStanza();
207
+ });
208
+ }
209
+ client.getChatsPrivateStoreRequestStanza();
210
+ setInited(true);
211
+ if (config?.refreshTokens?.enabled) {refresh();}
212
+ }
213
+
214
+ dispatch(setIsLoading({loading: false}));
215
+ } catch (error) {
216
+ devPushLog('error', 'ChatWrapper: init failed', error);
217
+ setShowModal(true);
218
+ setInited(false);
219
+ dispatch(setIsLoading({loading: false}));
220
+ }
221
+ };
222
+
223
+ initXmmpClient();
224
+ }, [
225
+ user.xmppPassword,
226
+ user.defaultWallet,
227
+ providerBootstrapStatus,
228
+ initMode,
229
+ config?.initBeforeLoad,
230
+ ]);
231
+
232
+ // Skip the legacy email/password LoginForm entirely when XmppProvider
233
+ // is driving auth via initBeforeLoad — the bootstrap effect will
234
+ // populate the user shortly. Showing LoginForm here causes a flicker
235
+ // and (worse) a stale form that races against the in-flight bootstrap.
236
+ if (
237
+ user.xmppPassword === '' &&
238
+ user.xmppUsername === '' &&
239
+ !config?.initBeforeLoad
240
+ )
241
+ {return <LoginForm config={config} />;}
242
+
243
+ // Mirror the web layout: when `disableRooms` is false and the
244
+ // consumer didn't preselect a `roomJID`, show the RoomList until the
245
+ // user picks one; then show the chat with a back button to return to
246
+ // the list. With `roomJID` or `disableRooms`, skip the list entirely.
247
+ const showRoomList =
248
+ !config?.disableRooms && !roomJID && !activeRoomJID;
249
+
250
+ return (
251
+ <>
252
+ {showModal && (
253
+ <Overlay>
254
+ <StyledModal>
255
+ <Text>There was an error. Please, refresh the page</Text>
256
+ </StyledModal>
257
+ </Overlay>
258
+ )}
259
+ <>
260
+ {isInited ? (
261
+ <ChatWrapperBox
262
+ style={{
263
+ ...MainComponentStyles,
264
+ }}>
265
+ {showRoomList ? (
266
+ <RoomList
267
+ chats={Object.values(rooms)}
268
+ onRoomClick={handleChangeChat}
269
+ />
270
+ ) : (
271
+ <ChatWrapperBox
272
+ style={{
273
+ ...MainComponentStyles,
274
+ }}>
275
+ <ChatRoom
276
+ CustomMessageComponent={CustomMessageComponent || Message}
277
+ // Only show the back button when there's a room list to
278
+ // return to. In single-room mode (`roomJID` preselected
279
+ // by the consumer) or when the consumer disabled the
280
+ // list (`disableRooms`), there's nowhere to go back to,
281
+ // so we omit the handler and ChatHeader renders without
282
+ // the back arrow.
283
+ handleBackClick={
284
+ roomJID || config?.disableRooms
285
+ ? undefined
286
+ : () => {
287
+ dispatch(setCurrentRoom({ roomJID: '' }));
288
+ }
289
+ }
290
+ />
291
+ </ChatWrapperBox>
292
+ )}
293
+ {/*
294
+ Mount the active-modal renderer so ChatHeader's onPress
295
+ (dispatch setActiveModal(CHAT_PROFILE)) actually surfaces
296
+ a modal. Without this, tapping the header was a no-op:
297
+ redux state flipped but nothing was listening. Web's
298
+ ChatWrapper mounts the same component (web ChatWrapper
299
+ lines 331-336).
300
+ */}
301
+ <Modal
302
+ modal={activeModal}
303
+ setOpenModal={(value?: ModalType) =>
304
+ dispatch(setActiveModal(value))
305
+ }
306
+ />
307
+ </ChatWrapperBox>
308
+ ) : (
309
+ <StyledLoaderWrapper>
310
+ <Loader color={config?.colors?.primary} />
311
+ </StyledLoaderWrapper>
312
+ )}
313
+ </>
314
+ </>
315
+ );
316
+ };
317
+
318
+ export {ChatWrapper};
@@ -0,0 +1,44 @@
1
+ import { styled } from 'styled-components/native';
2
+ import { NoSelectedChatIcon } from '../../assets/icons';
3
+
4
+ export const ChooseChatMessageContainer = styled.View`
5
+ height: 100%;
6
+ width: 100%;
7
+ align-items: center;
8
+ display: flex;
9
+ justify-content: center;
10
+ flex-direction: column;
11
+ gap: 16px;
12
+ `;
13
+
14
+ export const ChooseChatMessageContainerBoxText = styled.View`
15
+ display: flex;
16
+ flex-direction: column;
17
+ gap: 8px;
18
+ align-items: center;
19
+ `;
20
+
21
+ export const ChooseChatTitle = styled.Text`
22
+ font-size: 16px;
23
+ color: #141414;
24
+ font-weight: 600;
25
+ `;
26
+
27
+ export const ChooseChatDescription = styled.Text`
28
+ font-size: 14px;
29
+ color: #141414;
30
+ `;
31
+
32
+ export const ChooseChatMessage = () => {
33
+ return (
34
+ <ChooseChatMessageContainer>
35
+ <NoSelectedChatIcon />
36
+ <ChooseChatMessageContainerBoxText>
37
+ <ChooseChatTitle>Start a Conversation</ChooseChatTitle>
38
+ <ChooseChatDescription>
39
+ Choose a chat to start messaging.
40
+ </ChooseChatDescription>
41
+ </ChooseChatMessageContainerBoxText>
42
+ </ChooseChatMessageContainer>
43
+ );
44
+ };
@@ -0,0 +1,33 @@
1
+ /** @format */
2
+
3
+ import React from 'react';
4
+ import { View, Text, StyleSheet } from 'react-native';
5
+
6
+ const ConnectionBanner: React.FC = () => {
7
+ return (
8
+ <View style={styles.bannerContainer}>
9
+ <Text style={styles.bannerText}>Connection lost. Retrying...</Text>
10
+ </View>
11
+ );
12
+ };
13
+
14
+ const styles = StyleSheet.create({
15
+ bannerContainer: {
16
+ backgroundColor: '#ff9800',
17
+ padding: 8,
18
+ paddingHorizontal: 16,
19
+ width: '100%',
20
+ alignItems: 'center',
21
+ justifyContent: 'center',
22
+ zIndex: 1000,
23
+ },
24
+ bannerText: {
25
+ color: '#ffffff',
26
+ fontSize: 14,
27
+ fontWeight: '500',
28
+ textAlign: 'center',
29
+ },
30
+ });
31
+
32
+ export default ConnectionBanner;
33
+
@@ -0,0 +1,72 @@
1
+ import React, { FC } from 'react';
2
+ import { EditIcon } from '../../assets/icons';
3
+ import { styled } from 'styled-components/native';
4
+ import { Text, TouchableOpacity, View } from 'react-native';
5
+
6
+ export const EditContainer = styled.View`
7
+ background-color: #0052cd0d;
8
+ padding: 12px 24px;
9
+ flex-direction: row;
10
+ align-items: center;
11
+ justify-content: space-between;
12
+ `;
13
+
14
+ export const EditInfoBox = styled.View`
15
+ flex-direction: row;
16
+ align-items: center;
17
+ `;
18
+
19
+ export const EditTitle = styled.Text`
20
+ margin: 0px;
21
+ color: rgb(140, 140, 140);
22
+ text-align: start;
23
+ font-size: 12px;
24
+ padding-bottom: 4px;
25
+ `;
26
+
27
+ export const EditText = styled.Text`
28
+ margin: 0px;
29
+ font-size: 16px;
30
+ text-align: start;
31
+ `;
32
+
33
+ interface EditWrapperProps {
34
+ text: string;
35
+ onClose: () => void;
36
+ }
37
+
38
+ export const EditWrapper: FC<EditWrapperProps> = ({ text, onClose }) => {
39
+ console.log('text', text);
40
+ return (
41
+ <EditContainer>
42
+ <EditInfoBox>
43
+ <View
44
+ style={{
45
+ padding: 9,
46
+ paddingRight: 20,
47
+ paddingLeft: 0,
48
+ borderRightWidth: 1,
49
+ borderRightColor: '#0052CD',
50
+ borderStyle: 'solid',
51
+ }}
52
+ >
53
+ <EditIcon color="#0052CD" />
54
+ </View>
55
+ <View style={{ paddingLeft: 20 }}>
56
+ <EditTitle>Edit Message</EditTitle>
57
+ <EditText>{text}</EditText>
58
+ </View>
59
+ </EditInfoBox>
60
+ <TouchableOpacity
61
+ style={{
62
+ // background: "none",
63
+ // border: "none",
64
+ borderRadius: 8,
65
+ }}
66
+ onPress={onClose}
67
+ >
68
+ <Text style={{ fontSize: 24, color: '#888' }}>&times;</Text>
69
+ </TouchableOpacity>
70
+ </EditContainer>
71
+ );
72
+ };
@@ -0,0 +1,134 @@
1
+ import React, {useCallback, useEffect, useState} from 'react';
2
+ import {IConfig, MessageProps} from '../../types/types';
3
+ import {ChatWrapper} from './ChatWrapper';
4
+ import {RootState} from '../../roomStore';
5
+ import {useDispatch, useSelector} from 'react-redux';
6
+ import {setUser} from '../../roomStore/chatSettingsSlice';
7
+ import {loginEmail} from '../../networking/api-requests/auth.api';
8
+ import {OrDelimiter} from '../styled/StyledComponents';
9
+ import {ButtonText, Container, CustomButton, Message} from './RNStyled';
10
+ import {Text} from 'react-native';
11
+
12
+ interface LoginWrapperProps {
13
+ user?: {email: string; password: string};
14
+ MainComponentStyles?: React.CSSProperties;
15
+ CustomMessageComponent?: React.ComponentType<MessageProps>;
16
+ config?: IConfig;
17
+ roomJID?: string;
18
+ }
19
+
20
+ const LoginWrapper: React.FC<LoginWrapperProps> = ({...props}) => {
21
+ const [showModal, setShowModal] = useState(false);
22
+
23
+ const {user} = useSelector((state: RootState) => state.chatSettingStore);
24
+
25
+ const loginUserFunction = useCallback(async () => {
26
+ try {
27
+ const authData = await loginEmail(
28
+ props?.user?.email || 'yukiraze9@gmail.com',
29
+ props?.user?.password || 'Qwerty123',
30
+ );
31
+
32
+ return {
33
+ ...authData.data.user,
34
+ token: authData.data.token,
35
+ refreshToken: authData.data.refreshToken,
36
+ };
37
+ } catch (error) {
38
+ console.error('Login failed:', error);
39
+ return null;
40
+ }
41
+ }, []);
42
+
43
+ const dispatch = useDispatch();
44
+
45
+ useEffect(() => {
46
+ // When config.initBeforeLoad is enabled, the XmppProvider owns user
47
+ // resolution end-to-end. Skip the legacy login paths here so we don't
48
+ // race against the provider's resolveInitBeforeLoadUser pipeline.
49
+ if (props?.config?.initBeforeLoad) {
50
+ return;
51
+ }
52
+
53
+ if (props?.config?.userLogin?.enabled && props?.config?.userLogin?.user) {
54
+ dispatch(setUser(props.config.userLogin.user));
55
+ return;
56
+ }
57
+
58
+ //if no login config - default user login
59
+
60
+ if (
61
+ !props.config?.googleLogin &&
62
+ !props.config?.defaultLogin &&
63
+ !props.config?.jwtLogin &&
64
+ !props.config?.userLogin &&
65
+ !props.config?.customLogin &&
66
+ user.xmppUsername === ''
67
+ ) {
68
+ const defaultLogin = async () => {
69
+ try {
70
+ const loginData = await loginUserFunction();
71
+ if (loginData) {
72
+ dispatch(setUser(loginData));
73
+ }
74
+ } catch (error) {
75
+ console.log('error with default login', error);
76
+ setShowModal(true);
77
+ }
78
+ };
79
+ defaultLogin();
80
+ }
81
+ //if google - show login.tsx and process user there (there will be dispatch, set user)
82
+ //if only ethora - show login with only ethora
83
+ return () => {
84
+ //clear
85
+ };
86
+ }, []);
87
+
88
+ return (
89
+ // <>
90
+ // {showModal ? (
91
+ // <View
92
+ // style={{
93
+ // ...props.MainComponentStyles,
94
+ // display: 'flex',
95
+ // justifyContent: 'center',
96
+ // alignItems: 'center',
97
+ // flexDirection: 'column',
98
+ // padding: '20px',
99
+ // gap: '8px',
100
+ // }}
101
+ // >
102
+ // <p>Error on loading chat. Please, try again later</p>
103
+ // <OrDelimiter>Or</OrDelimiter>
104
+ // <Button onClick={() => setShowModal(false)} style={{ width: '100%' }}>
105
+ // Enter with default account
106
+ // </Button>
107
+ // </View>
108
+ // ) : user && user.xmppPassword !== '' ? (
109
+ // <ChatWrapper {...props} />
110
+ // ) : (
111
+ // <LoginForm {...props} />
112
+ // )}
113
+ // </>
114
+ <>
115
+ {showModal ? (
116
+ <Container>
117
+ <Message>Error on loading chat. Please, try again later</Message>
118
+ <OrDelimiter>Or</OrDelimiter>
119
+ <CustomButton onPress={() => setShowModal(false)}>
120
+ <ButtonText>Enter with default account</ButtonText>
121
+ </CustomButton>
122
+ </Container>
123
+ ) : (
124
+ // CRITICAL: forward props so `ChatWrapper` sees `config` (and
125
+ // therefore `initBeforeLoad`, `xmppSettings`, `refreshTokens`,
126
+ // etc.). Without this, ChatWrapper's effect can't tell that
127
+ // XmppProvider owns bootstrap and races against it.
128
+ <ChatWrapper {...props} />
129
+ )}
130
+ </>
131
+ );
132
+ };
133
+
134
+ export default LoginWrapper;
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { IMessage } from '../../types/types';
3
+ import FileDownload from '../styled/UnsupportedType';
4
+ import CustomMessageImage from '../styled/MessageImage';
5
+ import CustomMessageVideo from '../styled/VideoMessage';
6
+ import AudioMessage from '../styled/AudioMessage';
7
+ import { Text } from 'react-native';
8
+
9
+ interface MediaMessageProps {
10
+ mimeType?: string;
11
+ message?: IMessage;
12
+ location?: string;
13
+ messageText?: string;
14
+ }
15
+
16
+ const MediaMessage: React.FC<MediaMessageProps> = ({
17
+ mimeType,
18
+ location,
19
+ messageText,
20
+ message,
21
+ }) => {
22
+ if (mimeType)
23
+ {switch (true) {
24
+ case mimeType.startsWith('image/'):
25
+ return (
26
+ <CustomMessageImage
27
+ fileName={message?.fileName || '000132001'}
28
+ fileURL={messageText || ''}
29
+ mimetype={mimeType}
30
+ />
31
+ );
32
+ case mimeType.startsWith('video/'):
33
+ return (
34
+ <CustomMessageVideo
35
+ fileName={message?.fileName || '000132001'}
36
+ fileURL={location || ''}
37
+ mimetype={mimeType}
38
+ />
39
+ );
40
+ case mimeType.startsWith('audio/') ||
41
+ mimeType.includes('application/octet-stream'):
42
+ return <AudioMessage src={location || ''} />;
43
+ default:
44
+ return (
45
+ <FileDownload
46
+ fileURL={location ? location : ''}
47
+ fileName={location?.split('/')?.pop() || 'MediaFile'}
48
+ mimetype={mimeType}
49
+ />
50
+ );
51
+ }}
52
+ return <Text>Unsupported media type</Text>;
53
+ };
54
+
55
+ export default MediaMessage;