@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,68 @@
1
+ import React, { useRef } from 'react';
2
+ import { View, TouchableOpacity, StyleSheet } from 'react-native';
3
+ import Video, { VideoRef } from 'react-native-video';
4
+ import { useDispatch } from 'react-redux';
5
+ import {
6
+ setActiveFile,
7
+ setActiveModal,
8
+ } from '../../roomStore/chatSettingsSlice';
9
+ import { MODAL_TYPES } from '../../helpers/constants/MODAL_TYPES';
10
+
11
+ interface CustomMessageVideoProps {
12
+ fileName: string;
13
+ fileURL: string;
14
+ mimetype: string;
15
+ }
16
+
17
+ const CustomMessageVideo: React.FC<CustomMessageVideoProps> = ({
18
+ fileName,
19
+ fileURL,
20
+ mimetype,
21
+ }) => {
22
+ const dispatch = useDispatch();
23
+ const videoRef = useRef<VideoRef>(null);
24
+
25
+ const handleOpen = () => {
26
+ dispatch(setActiveFile({ fileName, fileURL, mimetype }));
27
+ dispatch(setActiveModal(MODAL_TYPES.FILE_PREVIEW));
28
+ };
29
+
30
+ const handlePlayPause = () => {
31
+ if (videoRef.current) {
32
+ videoRef.current.seek(0);
33
+ // videoRef.current.presentFullscreenPlayer();
34
+ }
35
+ };
36
+
37
+ return (
38
+ <TouchableOpacity style={styles.container} onPress={handlePlayPause}>
39
+ <Video
40
+ ref={videoRef}
41
+ source={{ uri: fileURL }}
42
+ style={styles.video}
43
+ controls
44
+ resizeMode="contain"
45
+ paused={true}
46
+ onBuffer={handleOpen}
47
+ onError={(error) => console.error('Video error:', error)}
48
+ />
49
+ </TouchableOpacity>
50
+ );
51
+ };
52
+
53
+ export default CustomMessageVideo;
54
+
55
+ const styles = StyleSheet.create({
56
+ container: {
57
+ margin: 0,
58
+ alignItems: 'center',
59
+ justifyContent: 'center',
60
+ width: '100%',
61
+ },
62
+ video: {
63
+ width: 300,
64
+ height: 200,
65
+ borderRadius: 10,
66
+ backgroundColor: '#000', // Задаем черный фон для видео
67
+ },
68
+ });
@@ -0,0 +1,335 @@
1
+ // RN port of the web MessageNotificationProvider. Renders Telegram-style
2
+ // in-app toasts when a new message arrives in a room that is NOT the
3
+ // currently active room. Backed by the global messageNotificationManager,
4
+ // which means non-React code (stanza handlers) can push notifications.
5
+ import React, {
6
+ createContext,
7
+ ReactNode,
8
+ useCallback,
9
+ useContext,
10
+ useEffect,
11
+ useRef,
12
+ useState,
13
+ } from 'react';
14
+ import {
15
+ Animated,
16
+ AppState,
17
+ AppStateStatus,
18
+ Pressable,
19
+ StyleSheet,
20
+ Text,
21
+ View,
22
+ } from 'react-native';
23
+ import { useDispatch, useSelector } from 'react-redux';
24
+ import { messageNotificationManager } from '../utils/messageNotificationManager';
25
+ import { setCurrentRoom } from '../roomStore/roomsSlice';
26
+ import { IConfig, IMessage } from '../types/types';
27
+ import { RootState } from '../roomStore';
28
+
29
+ interface ToastItem {
30
+ id: string;
31
+ message: IMessage;
32
+ roomName: string;
33
+ senderName: string;
34
+ roomJID: string;
35
+ timestamp: number;
36
+ }
37
+
38
+ interface MessageNotificationContextValue {
39
+ showMessageNotification: (
40
+ message: IMessage,
41
+ roomName: string,
42
+ senderName: string,
43
+ roomJID: string
44
+ ) => void;
45
+ }
46
+
47
+ const MessageNotificationContext =
48
+ createContext<MessageNotificationContextValue | null>(null);
49
+
50
+ const DEFAULT_MAX = 3;
51
+ const DEFAULT_DURATION_MS = 30000;
52
+
53
+ interface ProviderProps {
54
+ children: ReactNode;
55
+ config?: IConfig;
56
+ }
57
+
58
+ export const MessageNotificationProvider: React.FC<ProviderProps> = ({
59
+ children,
60
+ config: propConfig,
61
+ }) => {
62
+ const dispatch = useDispatch();
63
+ const contextConfig = useSelector(
64
+ (state: RootState) => state.chatSettingStore?.config
65
+ );
66
+ const activeRoomJID = useSelector(
67
+ (state: RootState) => state.rooms.activeRoomJID
68
+ );
69
+
70
+ const config = propConfig || contextConfig;
71
+ const notificationConfig = config?.inAppNotifications;
72
+ const isEnabled = notificationConfig?.enabled === true;
73
+ const maxNotifications = notificationConfig?.maxNotifications ?? DEFAULT_MAX;
74
+ const duration = notificationConfig?.duration ?? DEFAULT_DURATION_MS;
75
+
76
+ const [toasts, setToasts] = useState<ToastItem[]>([]);
77
+ const appActiveRef = useRef(AppState.currentState === 'active');
78
+
79
+ // Track AppState — when backgrounded, hold toasts longer; when
80
+ // foregrounded, prune expired.
81
+ useEffect(() => {
82
+ const sub = AppState.addEventListener(
83
+ 'change',
84
+ (next: AppStateStatus) => {
85
+ appActiveRef.current = next === 'active';
86
+ if (next === 'active') {
87
+ const now = Date.now();
88
+ setToasts((prev) => prev.filter((t) => now - t.timestamp < duration));
89
+ }
90
+ }
91
+ );
92
+ return () => sub.remove();
93
+ }, [duration]);
94
+
95
+ // Periodic prune when active.
96
+ useEffect(() => {
97
+ const interval = setInterval(() => {
98
+ if (!appActiveRef.current) {return;}
99
+ const now = Date.now();
100
+ setToasts((prev) => prev.filter((t) => now - t.timestamp < duration));
101
+ }, 1000);
102
+ return () => clearInterval(interval);
103
+ }, [duration]);
104
+
105
+ // Clear toasts when their room becomes active.
106
+ useEffect(() => {
107
+ if (!activeRoomJID) {return;}
108
+ setToasts((prev) => prev.filter((t) => t.roomJID !== activeRoomJID));
109
+ }, [activeRoomJID]);
110
+
111
+ const dismiss = useCallback((id: string) => {
112
+ setToasts((prev) => prev.filter((t) => t.id !== id));
113
+ }, []);
114
+
115
+ const navigateToMessage = useCallback(
116
+ (
117
+ roomJID: string,
118
+ messageId: string,
119
+ message: IMessage,
120
+ roomName: string,
121
+ senderName: string
122
+ ) => {
123
+ setToasts((prev) => prev.filter((t) => t.roomJID !== roomJID));
124
+ const customOnClick = notificationConfig?.onClick;
125
+ if (customOnClick) {
126
+ Promise.resolve(
127
+ customOnClick({ roomJID, messageId, message, roomName, senderName })
128
+ ).catch((e) => console.error('onClick handler error', e));
129
+ return;
130
+ }
131
+ if (roomJID) {dispatch(setCurrentRoom({ roomJID }));}
132
+ },
133
+ [dispatch, notificationConfig]
134
+ );
135
+
136
+ const showMessageNotification = useCallback(
137
+ (
138
+ message: IMessage,
139
+ roomName: string,
140
+ senderName: string,
141
+ roomJID: string
142
+ ) => {
143
+ if (!isEnabled) {return;}
144
+ // Don't toast for the currently active room.
145
+ if (activeRoomJID && activeRoomJID === roomJID) {return;}
146
+ const id = `msg-notification-${message.id}-${Date.now()}`;
147
+ const item: ToastItem = {
148
+ id,
149
+ message,
150
+ roomName,
151
+ senderName,
152
+ roomJID,
153
+ timestamp: Date.now(),
154
+ };
155
+ setToasts((prev) => {
156
+ const next = [...prev, item];
157
+ return next.length > maxNotifications
158
+ ? next.slice(-maxNotifications)
159
+ : next;
160
+ });
161
+ },
162
+ [isEnabled, activeRoomJID, maxNotifications]
163
+ );
164
+
165
+ // Register with the global manager.
166
+ useEffect(() => {
167
+ if (!isEnabled) {return;}
168
+ const unsubscribe = messageNotificationManager.addCallback(
169
+ showMessageNotification
170
+ );
171
+ return unsubscribe;
172
+ }, [isEnabled, showMessageNotification]);
173
+
174
+ return (
175
+ <MessageNotificationContext.Provider value={{ showMessageNotification }}>
176
+ {children}
177
+ {isEnabled && toasts.length > 0 && (
178
+ <View
179
+ pointerEvents="box-none"
180
+ style={[
181
+ styles.container,
182
+ positionToStyle(notificationConfig?.position),
183
+ ]}
184
+ >
185
+ {toasts.map((t) => {
186
+ const Custom = notificationConfig?.customComponent;
187
+ if (Custom) {
188
+ return (
189
+ <Custom
190
+ key={t.id}
191
+ id={t.id}
192
+ message={t.message}
193
+ roomName={t.roomName}
194
+ senderName={t.senderName}
195
+ roomJID={t.roomJID}
196
+ timestamp={t.timestamp}
197
+ onClose={() => dismiss(t.id)}
198
+ onNavigateToMessage={navigateToMessage}
199
+ duration={duration}
200
+ />
201
+ );
202
+ }
203
+ return (
204
+ <ToastRow
205
+ key={t.id}
206
+ item={t}
207
+ onPress={() =>
208
+ navigateToMessage(
209
+ t.roomJID,
210
+ t.message.id,
211
+ t.message,
212
+ t.roomName,
213
+ t.senderName
214
+ )
215
+ }
216
+ onDismiss={() => dismiss(t.id)}
217
+ />
218
+ );
219
+ })}
220
+ </View>
221
+ )}
222
+ </MessageNotificationContext.Provider>
223
+ );
224
+ };
225
+
226
+ const ToastRow: React.FC<{
227
+ item: ToastItem;
228
+ onPress: () => void;
229
+ onDismiss: () => void;
230
+ }> = ({ item, onPress, onDismiss }) => {
231
+ const fade = useRef(new Animated.Value(0)).current;
232
+ useEffect(() => {
233
+ Animated.timing(fade, {
234
+ toValue: 1,
235
+ duration: 180,
236
+ useNativeDriver: true,
237
+ }).start();
238
+ }, [fade]);
239
+
240
+ return (
241
+ <Animated.View style={[styles.toast, { opacity: fade }]}>
242
+ <Pressable style={styles.toastBody} onPress={onPress}>
243
+ <Text style={styles.toastTitle} numberOfLines={1}>
244
+ {item.roomName}
245
+ </Text>
246
+ <Text style={styles.toastSubtitle} numberOfLines={2}>
247
+ {item.senderName}: {item.message?.body || ''}
248
+ </Text>
249
+ </Pressable>
250
+ <Pressable onPress={onDismiss} style={styles.dismiss}>
251
+ <Text style={styles.dismissText}>×</Text>
252
+ </Pressable>
253
+ </Animated.View>
254
+ );
255
+ };
256
+
257
+ const positionToStyle = (
258
+ position?: NonNullable<IConfig['inAppNotifications']>['position']
259
+ ) => {
260
+ const horizontal = position?.horizontal || 'left';
261
+ const vertical = position?.vertical || 'bottom';
262
+ const offset = position?.offset || {};
263
+ const out: any = {};
264
+ if (vertical === 'top') {
265
+ out.top = offset.top ?? 20;
266
+ } else {
267
+ out.bottom = offset.bottom ?? 20;
268
+ }
269
+ if (horizontal === 'right') {
270
+ out.right = offset.right ?? 20;
271
+ out.alignItems = 'flex-end';
272
+ } else if (horizontal === 'center') {
273
+ out.left = 0;
274
+ out.right = 0;
275
+ out.alignItems = 'center';
276
+ } else {
277
+ out.left = offset.left ?? 20;
278
+ out.alignItems = 'flex-start';
279
+ }
280
+ return out;
281
+ };
282
+
283
+ const styles = StyleSheet.create({
284
+ container: {
285
+ position: 'absolute',
286
+ zIndex: 10000,
287
+ elevation: 10000,
288
+ },
289
+ toast: {
290
+ flexDirection: 'row',
291
+ alignItems: 'center',
292
+ backgroundColor: '#fff',
293
+ paddingVertical: 10,
294
+ paddingHorizontal: 14,
295
+ marginVertical: 4,
296
+ borderRadius: 12,
297
+ minWidth: 240,
298
+ maxWidth: 340,
299
+ shadowColor: '#000',
300
+ shadowOpacity: 0.15,
301
+ shadowOffset: { width: 0, height: 2 },
302
+ shadowRadius: 6,
303
+ },
304
+ toastBody: {
305
+ flex: 1,
306
+ },
307
+ toastTitle: {
308
+ fontWeight: '600',
309
+ fontSize: 14,
310
+ color: '#222',
311
+ marginBottom: 2,
312
+ },
313
+ toastSubtitle: {
314
+ fontSize: 12,
315
+ color: '#555',
316
+ },
317
+ dismiss: {
318
+ paddingHorizontal: 8,
319
+ paddingVertical: 4,
320
+ },
321
+ dismissText: {
322
+ fontSize: 18,
323
+ color: '#777',
324
+ },
325
+ });
326
+
327
+ export const useMessageNotification = () => {
328
+ const ctx = useContext(MessageNotificationContext);
329
+ if (!ctx) {
330
+ throw new Error(
331
+ 'useMessageNotification must be used within a MessageNotificationProvider'
332
+ );
333
+ }
334
+ return ctx;
335
+ };
@@ -0,0 +1,78 @@
1
+ // /**
2
+ // * Push Notification Provider
3
+ // * Initializes and manages push notifications for the chat
4
+ // */
5
+
6
+ // import React, { createContext, useContext, useEffect, ReactNode } from 'react';
7
+ // import { useSelector, useDispatch } from 'react-redux';
8
+ // import { usePushNotifications } from '../hooks/usePushNotifications';
9
+ // import { RootState } from '../roomStore';
10
+ // import { setCurrentRoom } from '../roomStore/roomsSlice';
11
+ // import { IConfig } from '../types/types';
12
+
13
+ // interface PushNotificationContextType {
14
+ // fcmToken: string | null;
15
+ // isInitialized: boolean;
16
+ // error: string | null;
17
+ // }
18
+
19
+ // const PushNotificationContext = createContext<PushNotificationContextType>({
20
+ // fcmToken: null,
21
+ // isInitialized: false,
22
+ // error: null,
23
+ // });
24
+
25
+ // interface PushNotificationProviderProps {
26
+ // children: ReactNode;
27
+ // config?: IConfig;
28
+ // }
29
+
30
+ // export const PushNotificationProvider: React.FC<PushNotificationProviderProps> = ({
31
+ // children,
32
+ // config,
33
+ // }) => {
34
+ // const dispatch = useDispatch();
35
+ // const rooms = useSelector((state: RootState) => state.rooms.rooms);
36
+
37
+ // // Handle notification press - navigate to chat
38
+ // const handleNotificationPress = (data: any) => {
39
+ // console.log('[PushProvider] Notification pressed:', data);
40
+
41
+ // if (data?.chatJid) {
42
+ // // Find the room and set it as current
43
+ // const room = rooms.find((r) => r.jid === data.chatJid);
44
+ // if (room) {
45
+ // dispatch(setCurrentRoom({ roomJID: room.jid }));
46
+ // }
47
+ // }
48
+
49
+ // // Call custom handler if provided
50
+ // config?.pushNotifications?.onNotificationPress?.(data);
51
+ // };
52
+
53
+ // const { fcmToken, isInitialized, error } = usePushNotifications({
54
+ // enabled: config?.pushNotifications?.enabled ?? false,
55
+ // pushApiUrl: config?.pushNotifications?.pushApiUrl,
56
+ // onNotificationPress: handleNotificationPress,
57
+ // });
58
+
59
+ // useEffect(() => {
60
+ // if (isInitialized) {
61
+ // console.log('[PushProvider] Push notifications initialized');
62
+ // }
63
+ // if (error) {
64
+ // console.error('[PushProvider] Push error:', error);
65
+ // }
66
+ // }, [isInitialized, error]);
67
+
68
+ // return (
69
+ // <PushNotificationContext.Provider value={{ fcmToken, isInitialized, error }}>
70
+ // {children}
71
+ // </PushNotificationContext.Provider>
72
+ // );
73
+ // };
74
+
75
+ // export const usePushNotificationContext = () => useContext(PushNotificationContext);
76
+
77
+ // export default PushNotificationProvider;
78
+
@@ -0,0 +1,63 @@
1
+ // src/context/ToastContext.tsx
2
+ import React, { createContext, useContext, useEffect, useState, ReactNode } from 'react';
3
+ import { ToastType, Toast } from '../components/Toast';
4
+ import { View } from 'react-native';
5
+ import { toastEmitter } from '../utils/toastEmitter';
6
+
7
+ interface ToastContextType {
8
+ showToast: (toast: ToastType) => void;
9
+ }
10
+
11
+ const ToastContext = createContext<ToastContextType | undefined>(undefined);
12
+
13
+ export const ToastProvider: React.FC<{ children: ReactNode }> = ({
14
+ children,
15
+ }) => {
16
+ const [toasts, setToasts] = useState<ToastType[]>([]);
17
+
18
+ // Subscribe to global toast emitter so non-React code can trigger toasts
19
+ useEffect(() => {
20
+ const unsubscribe = toastEmitter.subscribe((toast) => showToast(toast));
21
+ return unsubscribe;
22
+ }, []);
23
+
24
+ const showToast = (toast: ToastType) => {
25
+ setToasts((prev) => {
26
+ const next = [...prev, toast];
27
+ return next.length > 5 ? next.slice(1) : next;
28
+ });
29
+
30
+ setTimeout(() => {
31
+ setToasts((prev) => prev.filter((t) => t.id !== toast.id));
32
+ }, toast.duration || 3000);
33
+ };
34
+
35
+ return (
36
+ <ToastContext.Provider value={{ showToast }}>
37
+ {children}
38
+ <View
39
+ style={{
40
+ position: 'absolute',
41
+ top: 70,
42
+ left: 0,
43
+ right: 0,
44
+ flexDirection: 'column',
45
+ alignItems: 'center',
46
+ zIndex: 9999,
47
+ }}
48
+ >
49
+ {toasts.map((toast) => (
50
+ <Toast key={toast.id} {...toast} />
51
+ ))}
52
+ </View>
53
+ </ToastContext.Provider>
54
+ );
55
+ };
56
+
57
+ export const useToast = () => {
58
+ const context = useContext(ToastContext);
59
+ if (!context) {
60
+ throw new Error('useToast must be used within a ToastProvider');
61
+ }
62
+ return context;
63
+ };
File without changes