@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,103 @@
1
+ import { FC, useRef, useState } from 'react';
2
+ import {
3
+ CloseButton,
4
+ GroupContainer,
5
+ ModalBackground,
6
+ ModalContainer,
7
+ ModalDescription,
8
+ ModalTitle,
9
+ } from '../styledModalComponents';
10
+ import { TextareaInput } from '../../styled/StyledInputComponents/StyledInputComponents';
11
+ import Button from '../../styled/Button';
12
+ import { Modal, Text, TextInput } from 'react-native';
13
+
14
+ interface ModalWrapperProps {
15
+ iconTitle?: any;
16
+ title: string;
17
+ description?: string;
18
+ buttonText?: string;
19
+ backgroundColorButton?: string;
20
+ isTextarea?: boolean;
21
+ textarea?: string;
22
+ setTextarea?: (value: string) => void;
23
+ handleCloseModal: () => void;
24
+ handleClick: () => void;
25
+ }
26
+
27
+ export const ModalWrapper: FC<ModalWrapperProps> = ({
28
+ iconTitle: IconTitle,
29
+ title,
30
+ description,
31
+ buttonText,
32
+ backgroundColorButton,
33
+ isTextarea,
34
+ textarea,
35
+ setTextarea,
36
+ handleCloseModal,
37
+ handleClick,
38
+ }) => {
39
+ const textareaRef = useRef<TextInput>(null);
40
+
41
+ // const handleInput = () => {
42
+ // const textarea = textareaRef.current;
43
+ // if (textarea) {
44
+ // textarea.style.height = "auto";
45
+ // textarea.style.height = `${textarea.scrollHeight}px`;
46
+ // }
47
+ // };
48
+
49
+ return (
50
+ <Modal
51
+ transparent
52
+ animationType="fade"
53
+ visible={true}
54
+ onRequestClose={handleCloseModal}
55
+ >
56
+ <ModalBackground>
57
+ <ModalContainer style={{ maxWidth: 640 }}>
58
+ <CloseButton onPress={handleCloseModal}>
59
+ <Text style={{ fontSize: 24 }}>&times;</Text>
60
+ </CloseButton>
61
+ {IconTitle ? <IconTitle /> : <ModalTitle>{title}</ModalTitle>}
62
+ {description && <ModalDescription>{description}</ModalDescription>}
63
+ {isTextarea && (
64
+ <GroupContainer
65
+ style={{ flexDirection: 'column', position: 'relative' }}
66
+ >
67
+ {/* <TextareaInput
68
+ ref={textareaRef}
69
+ onInput={handleInput}
70
+ id="additionalDetails"
71
+ value={textarea}
72
+ onChangeText={(text) => setTextarea(text)}
73
+ placeholder="Additional Details"
74
+ /> */}
75
+ </GroupContainer>
76
+ )}
77
+ {!buttonText && <GroupContainer />}
78
+ <GroupContainer>
79
+ <Button
80
+ onPress={handleCloseModal}
81
+ text={'Cancel'}
82
+ style={{ width: '100%' }}
83
+ unstyled
84
+ variant="outlined"
85
+ />
86
+ {buttonText && (
87
+ <Button
88
+ onPress={handleClick}
89
+ text={buttonText}
90
+ style={{
91
+ width: '100%',
92
+ backgroundColor: backgroundColorButton,
93
+ }}
94
+ unstyled
95
+ variant="filled"
96
+ />
97
+ )}
98
+ </GroupContainer>
99
+ </ModalContainer>
100
+ </ModalBackground>
101
+ </Modal>
102
+ );
103
+ };
@@ -0,0 +1,151 @@
1
+ import React from 'react';
2
+ import {
3
+ ModalContainer,
4
+ CloseButton,
5
+ ModalTitle,
6
+ GroupContainer,
7
+ } from '../styledModalComponents';
8
+ import InputWithLabel from '../../styled/StyledInput';
9
+ import Select from '../../MainComponents/Select';
10
+ import Button from '../../styled/Button';
11
+ import UsersList from '../../UsersList/UsersList';
12
+ import { ProfileImagePlaceholder } from '../../MainComponents/ProfileImagePlaceholder';
13
+ import { ChatAccessOption } from '../../../types/types';
14
+ import { AddPhotoIcon } from '../../../assets/icons';
15
+ import { Text } from 'react-native';
16
+
17
+ type ModalContentProps = {
18
+ activeTab: '0' | '1' | null;
19
+ roomName: string;
20
+ roomDescription: string;
21
+ chatType: ChatAccessOption;
22
+ profileImage: string | File | null;
23
+ setActiveTab: (tab: '0' | '1' | null) => void;
24
+ handleRoomNameChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
25
+ setRoomDescription: (description: string) => void;
26
+ setChatType: (type: ChatAccessOption) => void;
27
+ setProfileImage: (image: string | File | null) => void;
28
+ selectedUsers: any[];
29
+ setSelectedUsers: (users: any[]) => void;
30
+ handleCreateRoom: () => void;
31
+ handleCloseModal: () => void;
32
+ errors: { name: string; description: string };
33
+ setErrors: (errors: { name: string; description: string }) => void;
34
+ options: ChatAccessOption[];
35
+ };
36
+
37
+ const ModalContent: React.FC<ModalContentProps> = ({
38
+ activeTab,
39
+ roomName,
40
+ roomDescription,
41
+ chatType,
42
+ profileImage,
43
+ setActiveTab,
44
+ handleRoomNameChange,
45
+ setChatType,
46
+ setProfileImage,
47
+ selectedUsers,
48
+ setSelectedUsers,
49
+ handleCreateRoom,
50
+ handleCloseModal,
51
+ errors,
52
+ setErrors,
53
+ options,
54
+ }) => {
55
+ return (
56
+ <ModalContainer>
57
+ <CloseButton onPress={handleCloseModal}>
58
+ <Text style={{ fontSize: 24 }}>&times;</Text>
59
+ </CloseButton>
60
+ {activeTab === '0' && (
61
+ <>
62
+ <ModalTitle>Create New Chat</ModalTitle>
63
+ <ProfileImagePlaceholder
64
+ size={120}
65
+ upload={{ active: true, onUpload: setProfileImage }}
66
+ remove={{
67
+ enabled: true,
68
+ onRemoveClick: () => setProfileImage(null),
69
+ }}
70
+ placeholderIcon={<AddPhotoIcon />}
71
+ icon={profileImage}
72
+ disableOverlay={!profileImage}
73
+ role="user"
74
+ />
75
+ <GroupContainer
76
+ style={{
77
+ flexDirection: 'column',
78
+ position: 'relative',
79
+ width: '100%',
80
+ }}
81
+ >
82
+ <InputWithLabel
83
+ style={{ flex: 1 }}
84
+ id="roomName"
85
+ value={roomName}
86
+ onChange={handleRoomNameChange}
87
+ placeholder="Enter Room Name"
88
+ helperText={errors.name}
89
+ error={!!errors.name}
90
+ />
91
+ <Select
92
+ options={options}
93
+ onSelect={setChatType}
94
+ selectedValue={chatType}
95
+ placeholder={'Select room type'}
96
+ />
97
+ </GroupContainer>
98
+ {chatType.id === 'group' && (
99
+ <Button
100
+ onPress={() => setActiveTab('1')}
101
+ style={{ width: '100%' }}
102
+ variant="outlined"
103
+ unstyled
104
+ >
105
+ Add users
106
+ </Button>
107
+ )}
108
+ <GroupContainer>
109
+ <Button
110
+ onPress={handleCloseModal}
111
+ text={'Cancel'}
112
+ style={{ width: '100%' }}
113
+ unstyled
114
+ variant="outlined"
115
+ />
116
+ <Button
117
+ onPress={handleCreateRoom}
118
+ text={'Create'}
119
+ style={{ width: '100%' }}
120
+ variant="filled"
121
+ />
122
+ </GroupContainer>
123
+ </>
124
+ )}
125
+ {activeTab === '1' && (
126
+ <>
127
+ <ModalTitle>Select users to add to Chat</ModalTitle>
128
+ <UsersList
129
+ selectedUsers={selectedUsers}
130
+ setSelectedUsers={setSelectedUsers}
131
+ style={{
132
+ minHeight: '400px',
133
+ minWidth: '100%',
134
+ width: '100%',
135
+ }}
136
+ />
137
+ <Button
138
+ onPress={() => setActiveTab('0')}
139
+ style={{ width: '100%' }}
140
+ variant="outlined"
141
+ unstyled
142
+ >
143
+ Back to creation
144
+ </Button>
145
+ </>
146
+ )}
147
+ </ModalContainer>
148
+ );
149
+ };
150
+
151
+ export default ModalContent;
@@ -0,0 +1,391 @@
1
+ import React, { useState, useEffect, useMemo } from 'react';
2
+ import Button from '../../styled/Button';
3
+ import { AddNewIcon, AddPhotoIcon } from '../../../assets/icons';
4
+ import { RootState } from '../../../roomStore';
5
+ import { useXmppClient } from '../../../context/xmppProvider';
6
+ import {
7
+ CloseButton,
8
+ GroupContainer,
9
+ ModalBackground,
10
+ ModalContainer,
11
+ ModalTitle,
12
+ } from '../styledModalComponents';
13
+ import { addRoomViaApi, setCurrentRoom, updateRoom } from '../../../roomStore/roomsSlice';
14
+ import InputWithLabel from '../../styled/StyledInput';
15
+ import { uploadFile } from '../../../networking/api-requests/auth.api';
16
+ import { ProfileImagePlaceholder } from '../../MainComponents/ProfileImagePlaceholder';
17
+ import { Text, Alert, Linking, Platform } from 'react-native';
18
+ import ImagePicker from 'react-native-image-crop-picker';
19
+ import {
20
+ check,
21
+ request,
22
+ PERMISSIONS,
23
+ RESULTS,
24
+ Permission,
25
+ } from 'react-native-permissions';
26
+ import { ApiRoom, ChatAccessOption, RoomMember } from '../../../types/models/room.model';
27
+ import { createRoomFromApi } from '../../../helpers/createRoomFromApi';
28
+ import { postRoom } from '../../../networking/api-requests/rooms.api';
29
+ import { useAppDispatch, useAppSelector } from '../../../hooks/hooks';
30
+ import { useChatSettingState } from '../../../hooks/useChatSettingState';
31
+ import { useToast } from '../../../context/ToastContext';
32
+
33
+ interface NewChatModalProps {
34
+ handleCloseModal?: any;
35
+ }
36
+
37
+ const NewChatModal: React.FC<NewChatModalProps> = ({
38
+ // Some call sites mount `<NewChatModal />` with no props (e.g. the
39
+ // empty-state in ChatRoom when roomsList is empty). Default to a noop
40
+ // so the Close/Cancel buttons don't throw "handleClose is not a
41
+ // function".
42
+ handleCloseModal: handleClose = () => {},
43
+ }) => {
44
+ const config = useAppSelector(
45
+ (state: RootState) => state.chatSettingStore.config
46
+ );
47
+
48
+ const dispatch = useAppDispatch();
49
+ const { client } = useXmppClient();
50
+ const { user } = useChatSettingState();
51
+ const { showToast } = useToast();
52
+
53
+ const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
54
+ const [loading, setLoading] = useState<boolean>(false);
55
+ const [activeTab, setActiveTab] = useState<'0' | '1' | null>('0');
56
+
57
+ const [roomName, setRoomName] = useState<string>('');
58
+ const [roomDescription, setRoomDescription] = useState<string>('');
59
+ const [chatType, setChatType] = useState<ChatAccessOption>({
60
+ name: 'Public',
61
+ id: 'public',
62
+ });
63
+ const [profileImage, setProfileImage] = useState<string | { uri: string; type: string; name: string } | null>(null);
64
+ const [errors, setErrors] = useState({ name: '', description: '' });
65
+ const [selectedUsers, setSelectedUsers] = useState<RoomMember[]>([]);
66
+
67
+ const isValid = useMemo(
68
+ // () => roomName.length >= 3 && roomDescription.length >= 5,
69
+ () => roomName.length >= 3,
70
+ [roomName, roomDescription]
71
+ );
72
+
73
+ const validateRoomName = (name: string) => {
74
+ if (name.trim().length < 3) {
75
+ return 'Room name must be at least 3 characters.';
76
+ }
77
+ return '';
78
+ };
79
+
80
+ // const validateRoomDescription = (description: string) => {
81
+ // if (description.trim().length < 5) {
82
+ // return 'Room description must be at least 5 characters.';
83
+ // }
84
+ // return '';
85
+ // };
86
+
87
+ const handleRoomNameChange = (e: string) => {
88
+ const name = e;
89
+ setRoomName(name);
90
+ setErrors((prevErrors) => ({
91
+ ...prevErrors,
92
+ name: validateRoomName(name),
93
+ }));
94
+ };
95
+
96
+ const handleRoomDescriptionChange = (
97
+ e: string
98
+ ) => {
99
+ const description = e;
100
+ setRoomDescription(description);
101
+ setErrors((prevErrors) => ({
102
+ ...prevErrors,
103
+ // description: validateRoomDescription(description),
104
+ }));
105
+ };
106
+
107
+ const handleOpenModal = () => setIsModalOpen(true);
108
+ const handleCloseModal = () => {
109
+ handleClose();
110
+ setActiveTab('0');
111
+ setIsModalOpen(false);
112
+ setRoomName('');
113
+ setSelectedUsers([]);
114
+ };
115
+
116
+ const checkPermission = async (permission: Permission) => {
117
+ const status = await check(permission);
118
+ if (status === RESULTS.GRANTED) {
119
+ return status;
120
+ } else if (status === RESULTS.DENIED) {
121
+ const requestStatus = await request(permission);
122
+ return requestStatus;
123
+ }
124
+ return status;
125
+ };
126
+
127
+ const onUpload = async () => {
128
+ try {
129
+ const permission =
130
+ Platform.OS === 'ios'
131
+ ? PERMISSIONS.IOS.PHOTO_LIBRARY
132
+ : PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE;
133
+ const permissionStatus = await checkPermission(permission);
134
+
135
+ if (permissionStatus !== RESULTS.GRANTED) {
136
+ Alert.alert(
137
+ 'Permission required',
138
+ 'Photo library permission is needed to select images.',
139
+ [
140
+ {
141
+ text: 'Cancel',
142
+ onPress: () => console.log('Photo permission cancelled'),
143
+ style: 'cancel',
144
+ },
145
+ {
146
+ text: 'Open Settings',
147
+ onPress: () => Linking.openSettings(),
148
+ },
149
+ ]
150
+ );
151
+ return;
152
+ }
153
+
154
+ const image = await ImagePicker.openPicker({
155
+ width: 300,
156
+ height: 300,
157
+ cropping: true,
158
+ cropperCircleOverlay: true,
159
+ compressImageQuality: 0.8,
160
+ });
161
+
162
+ const originalName = image.path.split('/').pop();
163
+ const fileObject = {
164
+ uri: image.path,
165
+ type: image.mime || 'image/jpeg',
166
+ name: originalName || `profile_${Date.now()}.jpg`,
167
+ };
168
+
169
+ setProfileImage(fileObject);
170
+ } catch (error: any) {
171
+ if (error?.code === 'E_PICKER_CANCELLED' || error?.code === 'E_NO_CAMERA_PERMISSION') {
172
+ console.log('User cancelled image selection');
173
+ return;
174
+ }
175
+ console.error('Image selection failed:', error);
176
+ Alert.alert('Error', 'Failed to select image');
177
+ }
178
+ };
179
+
180
+ const onRemoveClick = async () => {
181
+ setProfileImage(null);
182
+ };
183
+
184
+ const handleRoomCreation = async (
185
+ newChat: ApiRoom,
186
+ usersArrayLength: number
187
+ ) => {
188
+ try {
189
+ const normalizedChat = createRoomFromApi(
190
+ newChat,
191
+ config?.xmppSettings?.conference,
192
+ usersArrayLength
193
+ );
194
+
195
+ dispatch(
196
+ addRoomViaApi({
197
+ room: normalizedChat,
198
+ xmpp: client,
199
+ })
200
+ );
201
+
202
+ dispatch(setCurrentRoom({ roomJID: normalizedChat.jid }));
203
+
204
+ showToast({
205
+ id: Date.now().toString(),
206
+ title: 'Success',
207
+ message: 'Room created successfully',
208
+ type: 'success',
209
+ });
210
+ } catch (error) {
211
+ console.error('Error handling room creation:', error);
212
+ showToast({
213
+ id: Date.now().toString(),
214
+ title: 'Error',
215
+ message: 'Failed to create room',
216
+ type: 'error',
217
+ });
218
+ }
219
+ };
220
+
221
+ const handleCreateRoom = async () => {
222
+ setLoading(true);
223
+ if (isValid) {
224
+ let location: string | undefined;
225
+
226
+ if (profileImage && typeof profileImage === 'object' && 'uri' in profileImage) {
227
+ try {
228
+ const mediaData = new FormData();
229
+ mediaData.append('files', profileImage as any);
230
+ const uploadResult = await uploadFile(mediaData);
231
+ location = uploadResult?.data?.results?.[0]?.location;
232
+ } catch (error) {
233
+ console.error('Failed to upload image:', error);
234
+ setLoading(false);
235
+ return;
236
+ }
237
+ }
238
+
239
+ if (config?.newArch) {
240
+ const namesArray = selectedUsers.map((user) => user.xmppUsername);
241
+ const newChat: ApiRoom = await postRoom({
242
+ title: roomName,
243
+ description:
244
+ roomDescription && roomDescription !== ''
245
+ ? roomDescription
246
+ : 'No description',
247
+ picture: location || '',
248
+ type: chatType.id || 'public',
249
+ members: namesArray,
250
+ });
251
+
252
+ handleRoomCreation(newChat, namesArray.length);
253
+ handleCloseModal();
254
+ } else {
255
+ try {
256
+ const newChatJid = await client.createRoomStanza(
257
+ roomName,
258
+ roomDescription && roomDescription !== ''
259
+ ? roomDescription
260
+ : 'No description'
261
+ );
262
+
263
+ client.getRoomsStanza();
264
+
265
+ dispatch(setCurrentRoom({ roomJID: newChatJid }));
266
+
267
+ if (location) {
268
+ client.setRoomImageStanza(newChatJid, location, 'icon', 'none');
269
+ dispatch(
270
+ updateRoom({ jid: newChatJid, updates: { icon: location } })
271
+ );
272
+ }
273
+
274
+ showToast({
275
+ id: Date.now().toString(),
276
+ title: 'Success',
277
+ message: 'Room created successfully',
278
+ type: 'success',
279
+ });
280
+ handleCloseModal();
281
+ } catch (error) {
282
+ console.error('Failed to create room:', error);
283
+ showToast({
284
+ id: Date.now().toString(),
285
+ title: 'Error',
286
+ message: 'Failed to create room',
287
+ type: 'error',
288
+ });
289
+ }
290
+ }
291
+
292
+ setIsModalOpen(false);
293
+ setErrors({ name: '', description: '' });
294
+ setProfileImage(null);
295
+ setRoomName('');
296
+ setRoomDescription('');
297
+ setLoading(false);
298
+ }
299
+ };
300
+
301
+ return (
302
+ <>
303
+ {/* <Button
304
+ style={{
305
+ padding: 8,
306
+ borderRadius: 16,
307
+ backgroundColor: "transparent",
308
+ }}
309
+ color="black"
310
+ unstyled
311
+ EndIcon={<AddNewIcon color={config?.colors?.primary} />}
312
+ onPress={handleOpenModal}
313
+ /> */}
314
+
315
+ <ModalBackground
316
+ // visible={isModalOpen}
317
+ // transparent={true}
318
+ // animationType="fade"
319
+ // onRequestClose={handleCloseModal}
320
+ >
321
+ <ModalContainer>
322
+ <CloseButton onPress={handleCloseModal}>
323
+ <Text style={{ fontSize: 24, padding: 5 }}>&times;</Text>
324
+ </CloseButton>
325
+ <ModalTitle>Create New Chat</ModalTitle>
326
+ <ProfileImagePlaceholder
327
+ size={120}
328
+ upload={{ active: true, onUpload }}
329
+ remove={{ enabled: true, onRemoveClick }}
330
+ placeholderIcon={<AddPhotoIcon color="#0052CD" />}
331
+ icon={
332
+ profileImage && typeof profileImage === 'object' && 'uri' in profileImage
333
+ ? { uri: profileImage.uri }
334
+ : profileImage
335
+ }
336
+ disableOverlay={!profileImage}
337
+ role="user"
338
+ />
339
+ <GroupContainer
340
+ style={{
341
+ flexDirection: 'column',
342
+ position: 'relative',
343
+ width: '100%',
344
+ }}
345
+ >
346
+ <InputWithLabel
347
+ color="#F5F7F9"
348
+ id="roomName"
349
+ value={roomName}
350
+ onChangeText={handleRoomNameChange}
351
+ placeholder="Enter Room Name"
352
+ helperText={errors.name}
353
+ error={!!errors.name}
354
+ />
355
+ <InputWithLabel
356
+ color="#F5F7F9"
357
+ id="roomDescription"
358
+ value={roomDescription}
359
+ onChangeText={handleRoomDescriptionChange}
360
+ placeholder="Enter Description"
361
+ helperText={errors.description}
362
+ error={!!errors.description}
363
+ />
364
+ </GroupContainer>
365
+
366
+ <GroupContainer>
367
+ <Button
368
+ onPress={handleCreateRoom}
369
+ text={'Create'}
370
+ style={{ width: '100%' }}
371
+ unstyled
372
+ variant="filled"
373
+ disabled={!isValid}
374
+ color="#fff"
375
+ />
376
+ <Button
377
+ onPress={handleCloseModal}
378
+ text={'Cancel'}
379
+ style={{ width: '100%' }}
380
+ unstyled
381
+ variant="outlined"
382
+ color="#0052CD"
383
+ />
384
+ </GroupContainer>
385
+ </ModalContainer>
386
+ </ModalBackground>
387
+ </>
388
+ );
389
+ };
390
+
391
+ export default NewChatModal;