@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.
- package/LICENSE +661 -0
- package/README.md +148 -0
- package/empty-shim.js +15 -0
- package/index.js +13 -0
- package/metro.js +72 -0
- package/package.json +99 -0
- package/src/api.config.ts +34 -0
- package/src/assets/BG.png +0 -0
- package/src/assets/BG.tsx +56 -0
- package/src/assets/File.svg +4 -0
- package/src/assets/ForzaCare.png +0 -0
- package/src/assets/ForzaCare.tsx +27 -0
- package/src/assets/icons.tsx +685 -0
- package/src/assets/images.tsx +41 -0
- package/src/assets/test.xml +243 -0
- package/src/components/AuthForms/Login.tsx +295 -0
- package/src/components/AuthForms/LoginAnonym.tsx +68 -0
- package/src/components/AuthForms/Register.tsx +8 -0
- package/src/components/ContextMenu/ContextMenuComponents.tsx +87 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +244 -0
- package/src/components/ExampleComponents/CustomMessage.tsx +92 -0
- package/src/components/ExampleComponents/CustomTypingIndicatorExamples.tsx +239 -0
- package/src/components/Header/HeaderRoomList.tsx +104 -0
- package/src/components/InputComponents/AudioInput.tsx +24 -0
- package/src/components/InputComponents/AudioRecorder.tsx +100 -0
- package/src/components/InputComponents/MediaInput.tsx +114 -0
- package/src/components/InputComponents/RecordingIndicator.tsx +77 -0
- package/src/components/InputComponents/Search.tsx +135 -0
- package/src/components/InputComponents/TextInput.tsx +66 -0
- package/src/components/MainComponents/ChatHeader.tsx +163 -0
- package/src/components/MainComponents/ChatRoom.tsx +392 -0
- package/src/components/MainComponents/ChatWrapper.tsx +318 -0
- package/src/components/MainComponents/ChooseChatMessage.tsx +44 -0
- package/src/components/MainComponents/ConnectionBanner.tsx +33 -0
- package/src/components/MainComponents/EditWrapper.tsx +72 -0
- package/src/components/MainComponents/LoginWrapper.tsx +134 -0
- package/src/components/MainComponents/MediaMessage.tsx +55 -0
- package/src/components/MainComponents/MessageContainer.tsx +122 -0
- package/src/components/MainComponents/MessageList.tsx +429 -0
- package/src/components/MainComponents/NoMessagesPlaceholder.tsx +49 -0
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +143 -0
- package/src/components/MainComponents/RNStyled.tsx +34 -0
- package/src/components/MainComponents/ReduxWrapper.tsx +40 -0
- package/src/components/MainComponents/RoomList.tsx +246 -0
- package/src/components/MainComponents/Select.tsx +165 -0
- package/src/components/MainComponents/Switch.tsx +73 -0
- package/src/components/MainComponents/SystemMessage.tsx +42 -0
- package/src/components/Menu/HeaderRoomListMenu.tsx +169 -0
- package/src/components/MenuRoom/MenuRoom.tsx +46 -0
- package/src/components/MessageBubble/Avatar.tsx +84 -0
- package/src/components/MessageBubble/BottomReplyContainer.tsx +117 -0
- package/src/components/MessageBubble/CustomDivider.tsx +10 -0
- package/src/components/MessageBubble/DeletedMessage.tsx +36 -0
- package/src/components/MessageBubble/Message.tsx +400 -0
- package/src/components/MessageBubble/MessageInteractions.tsx +247 -0
- package/src/components/MessageBubble/MessageReaction.tsx +149 -0
- package/src/components/MessageBubble/MessageReply.tsx +50 -0
- package/src/components/MessageBubble/MessageTranslations.tsx +30 -0
- package/src/components/Modals/AddMembersModal/AddMembersModal.tsx +142 -0
- package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +471 -0
- package/src/components/Modals/ChatProfileModal/DeleteChatModal.tsx +91 -0
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +298 -0
- package/src/components/Modals/Modal/Modal.tsx +52 -0
- package/src/components/Modals/ModalHeaderComponent.tsx +41 -0
- package/src/components/Modals/ModalSelectMedia/ModalSelectMedia.tsx +285 -0
- package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +103 -0
- package/src/components/Modals/NewChatModal/ModalContent.tsx +151 -0
- package/src/components/Modals/NewChatModal/NewChatModal.tsx +391 -0
- package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +136 -0
- package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +134 -0
- package/src/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.tsx +63 -0
- package/src/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.tsx +115 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +121 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/StyledComponents.ts +0 -0
- package/src/components/Modals/SettingsModals/ProfileShares/ProfileShares.tsx +65 -0
- package/src/components/Modals/SettingsModals/Referrals/Referrals.tsx +90 -0
- package/src/components/Modals/SettingsModals/SharedStyledComponents.ts +74 -0
- package/src/components/Modals/SettingsModals/Visibility/RadioInput.tsx +59 -0
- package/src/components/Modals/SettingsModals/Visibility/StyledComponents.ts +32 -0
- package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +146 -0
- package/src/components/Modals/UserProfileModal/EditUserModal.tsx +163 -0
- package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +410 -0
- package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +85 -0
- package/src/components/Modals/styledModalComponents.tsx +181 -0
- package/src/components/OperationalModal/OperationalModal.tsx +78 -0
- package/src/components/RoomComponents/ChatRoomItem.tsx +219 -0
- package/src/components/RoomComponents/LastMessageItem.tsx +47 -0
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +62 -0
- package/src/components/RoomComponents/styled/LastMessageEmoji.tsx +26 -0
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +70 -0
- package/src/components/RoomComponents/styled/LastTextMessage.tsx +65 -0
- package/src/components/RoomComponents/styled/StyledRoomComponents.ts +53 -0
- package/src/components/SortDropDown/index.tsx +76 -0
- package/src/components/Thread/ThreadHeader.tsx +41 -0
- package/src/components/Thread/ThreadWrapper.tsx +270 -0
- package/src/components/Toast/Toast.tsx +128 -0
- package/src/components/Toast/index.ts +13 -0
- package/src/components/UsersList/StyledComponents.ts +30 -0
- package/src/components/UsersList/UsersList.tsx +112 -0
- package/src/components/styled/ActionButton.tsx +40 -0
- package/src/components/styled/AudioMessage.tsx +82 -0
- package/src/components/styled/Button.tsx +107 -0
- package/src/components/styled/ChatWrapperBox.tsx +9 -0
- package/src/components/styled/DateLabel.tsx +77 -0
- package/src/components/styled/Loader.tsx +65 -0
- package/src/components/styled/MediaFilePreview.tsx +42 -0
- package/src/components/styled/MediaModal.tsx +54 -0
- package/src/components/styled/MessageImage.tsx +54 -0
- package/src/components/styled/NewMessageLabel.tsx +50 -0
- package/src/components/styled/RoomListComponents/index.tsx +164 -0
- package/src/components/styled/SendInput.tsx +297 -0
- package/src/components/styled/StyledComponents.ts +320 -0
- package/src/components/styled/StyledInput.tsx +101 -0
- package/src/components/styled/StyledInputComponents/AudioComponents.tsx +1 -0
- package/src/components/styled/StyledInputComponents/Composing.tsx +97 -0
- package/src/components/styled/StyledInputComponents/CustomTypingIndicator.tsx +261 -0
- package/src/components/styled/StyledInputComponents/MediaComponents.tsx +90 -0
- package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +131 -0
- package/src/components/styled/StyledInputComponents/VideoComponents.tsx +49 -0
- package/src/components/styled/TreadLabel.tsx +50 -0
- package/src/components/styled/UnsupportedType.tsx +95 -0
- package/src/components/styled/VideoMessage.tsx +68 -0
- package/src/context/MessageNotificationContext.tsx +335 -0
- package/src/context/PushNotificationProvider.tsx +78 -0
- package/src/context/ToastContext.tsx +63 -0
- package/src/context/toastProvider.tsx +0 -0
- package/src/context/xmppProvider.tsx +364 -0
- package/src/helpers/block_scroll.ts +95 -0
- package/src/helpers/chatAutoEnterer.ts +46 -0
- package/src/helpers/checkUniqueUsers.tsx +31 -0
- package/src/helpers/constants/CHAT_TYPES.ts +6 -0
- package/src/helpers/constants/LANGUAGE_OPTIONS.ts +14 -0
- package/src/helpers/constants/LOCAL_STORAGE.ts +3 -0
- package/src/helpers/constants/MESSAGE_INTERACTIONS.ts +29 -0
- package/src/helpers/constants/MODAL_TYPES.ts +57 -0
- package/src/helpers/constants/PLATFORM_CONSTANTS.ts +3 -0
- package/src/helpers/createMainMessageForThread.ts +23 -0
- package/src/helpers/createMessageFromXml.ts +118 -0
- package/src/helpers/createRoomFromApi.tsx +27 -0
- package/src/helpers/createUserNameFromSetUser.ts +15 -0
- package/src/helpers/dateComparison.ts +12 -0
- package/src/helpers/debounce.ts +10 -0
- package/src/helpers/ensureScopedChatCache.ts +61 -0
- package/src/helpers/extractUniqueMembersFromRooms.ts +45 -0
- package/src/helpers/formatNumberWithCommas.ts +3 -0
- package/src/helpers/getBooleanFromString.ts +7 -0
- package/src/helpers/getDataFromXml.ts +80 -0
- package/src/helpers/getNumberFromString.ts +5 -0
- package/src/helpers/getRoomsWithRetry.ts +45 -0
- package/src/helpers/getTintedColor.ts +28 -0
- package/src/helpers/getUnnamedUsers.ts +39 -0
- package/src/helpers/handleCopyClick.ts +3 -0
- package/src/helpers/handleXmppError.ts +14 -0
- package/src/helpers/hashcolor.ts +34 -0
- package/src/helpers/historyPreloadScheduler.ts +264 -0
- package/src/helpers/initRoomsPresence.ts +32 -0
- package/src/helpers/initXmppRooms.tsx +71 -0
- package/src/helpers/insertMessageWithDelimiter.ts +96 -0
- package/src/helpers/isChatIdPresentInArray.ts +54 -0
- package/src/helpers/localStorageUser.ts +9 -0
- package/src/helpers/markdownParser.tsx +295 -0
- package/src/helpers/nanoToMs.ts +3 -0
- package/src/helpers/parseMessageBody.tsx +516 -0
- package/src/helpers/parseUrls.tsx +42 -0
- package/src/helpers/resolveInitBeforeLoadUser.ts +240 -0
- package/src/helpers/storeConsole.ts +26 -0
- package/src/helpers/transformTranslatations.ts +16 -0
- package/src/helpers/updateMessagesTillLast.tsx +104 -0
- package/src/helpers/updatedChatLastTimestamps.ts +29 -0
- package/src/helpers/validator.ts +20 -0
- package/src/helpers/walletUsername.ts +12 -0
- package/src/hooks/hooks.ts +6 -0
- package/src/hooks/useChatSettingState.tsx +38 -0
- package/src/hooks/useChatWrapperInit.ts +266 -0
- package/src/hooks/useComposing.tsx +59 -0
- package/src/hooks/useCustomTypingIndicator.tsx +193 -0
- package/src/hooks/useEventHandlers.tsx +81 -0
- package/src/hooks/useGetNewArchRoom.tsx +57 -0
- package/src/hooks/useHeapSender.tsx +88 -0
- package/src/hooks/useLocalStorage.tsx +53 -0
- package/src/hooks/useLogout.tsx +31 -0
- package/src/hooks/useMessageHeapState.tsx +11 -0
- package/src/hooks/useMessageLoaderQueue.tsx +90 -0
- package/src/hooks/useMessageQueue.ts +146 -0
- package/src/hooks/usePendingNotification.ts +49 -0
- package/src/hooks/usePrevious.tsx +15 -0
- package/src/hooks/usePushNotifications.ts +106 -0
- package/src/hooks/useQRCodeChatHandler.ts +58 -0
- package/src/hooks/useRoomInitialization.tsx +160 -0
- package/src/hooks/useRoomState.tsx +47 -0
- package/src/hooks/useRoomUrl.tsx +41 -0
- package/src/hooks/useSendMessage.tsx +306 -0
- package/src/hooks/useUnreadMessagesCounter.ts +55 -0
- package/src/hooks/useXmppInitialization.ts +148 -0
- package/src/main.ts +45 -0
- package/src/networking/api-requests/auth.api.ts +140 -0
- package/src/networking/api-requests/push.api.ts +55 -0
- package/src/networking/api-requests/roomMembers.api.ts +20 -0
- package/src/networking/api-requests/rooms.api.ts +142 -0
- package/src/networking/api-requests/user.api.ts +65 -0
- package/src/networking/apiClient.ts +149 -0
- package/src/networking/helpers/refreshChecker.ts +13 -0
- package/src/networking/stanzaHandlers.ts +418 -0
- package/src/networking/xmpp/actionSetTimestampToPrivateStore.xmpp.ts +37 -0
- package/src/networking/xmpp/allRoomPresences.xmpp.ts +10 -0
- package/src/networking/xmpp/createPrivateRoom.xmpp.ts +26 -0
- package/src/networking/xmpp/createRoom.xmpp.ts +35 -0
- package/src/networking/xmpp/createRoomPresence.xmpp.ts +74 -0
- package/src/networking/xmpp/createTimeoutPromise.xmpp.ts +15 -0
- package/src/networking/xmpp/deleteMessage.xmpp.ts +19 -0
- package/src/networking/xmpp/editMessage.xmpp.ts +46 -0
- package/src/networking/xmpp/getChatsPrivateStoreRequest.xmpp.ts +57 -0
- package/src/networking/xmpp/getHistory.xmpp.ts +140 -0
- package/src/networking/xmpp/getLastMessageArchive.xmpp.ts +24 -0
- package/src/networking/xmpp/getRoomInfo.xmpp.ts +15 -0
- package/src/networking/xmpp/getRoomMembers.xmpp.ts +13 -0
- package/src/networking/xmpp/getRooms.xmpp.ts +43 -0
- package/src/networking/xmpp/getRoomsPaged.xmpp.ts +59 -0
- package/src/networking/xmpp/handlePong.xmpp.ts +7 -0
- package/src/networking/xmpp/handleStanzas.xmpp.ts +55 -0
- package/src/networking/xmpp/inviteRoomRequest.xmpp.ts +25 -0
- package/src/networking/xmpp/leaveTheRoom.xmpp.ts +15 -0
- package/src/networking/xmpp/listenerManager.ts +116 -0
- package/src/networking/xmpp/presenceInRoom.xmpp.ts +57 -0
- package/src/networking/xmpp/roomConfig.xmpp.ts +71 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +97 -0
- package/src/networking/xmpp/sendMessageReaction.xmpp.ts +41 -0
- package/src/networking/xmpp/sendPing.xmpp.ts +21 -0
- package/src/networking/xmpp/sendTextMessage.xmpp.ts +99 -0
- package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +44 -0
- package/src/networking/xmpp/sendTypingRequest.xmpp.ts +26 -0
- package/src/networking/xmpp/setChatsPrivateStoreRequest.xmpp.ts +48 -0
- package/src/networking/xmpp/setMeAsOwner.xmpp.ts +52 -0
- package/src/networking/xmpp/setRoomImage.xmpp.ts +26 -0
- package/src/networking/xmpp/setVCard.xmpp.ts +19 -0
- package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +75 -0
- package/src/networking/xmppClient.ts +603 -0
- package/src/roomStore/Middleware/logoutMiddleware.tsx +24 -0
- package/src/roomStore/Middleware/newMessageMidlleware.tsx +87 -0
- package/src/roomStore/Middleware/reactionsMiddleware.tsx +77 -0
- package/src/roomStore/Middleware/testMiddleware.tsx +20 -0
- package/src/roomStore/Middleware/unreadMidlleware.tsx +58 -0
- package/src/roomStore/chatSettingsSlice.ts +178 -0
- package/src/roomStore/index.ts +68 -0
- package/src/roomStore/persistence.ts +152 -0
- package/src/roomStore/roomHeapSlice.ts +37 -0
- package/src/roomStore/roomsSlice.ts +353 -0
- package/src/services/pushNotifications.ts +170 -0
- package/src/services/pushSubscriptionService.ts +145 -0
- package/src/types/messages.ts +61 -0
- package/src/types/models/action.model.ts +30 -0
- package/src/types/models/config.model.ts +16 -0
- package/src/types/models/customComponents.model.ts +53 -0
- package/src/types/models/language.model.ts +11 -0
- package/src/types/models/media.model.ts +5 -0
- package/src/types/models/message.model.ts +69 -0
- package/src/types/models/modal.model.ts +9 -0
- package/src/types/models/room.model.ts +120 -0
- package/src/types/models/user.model.ts +90 -0
- package/src/types/models/xmpp.model.ts +155 -0
- package/src/types/types.ts +505 -0
- package/src/utils/PriorityQueue.ts +47 -0
- package/src/utils/actionHelpers.ts +40 -0
- package/src/utils/actionLogger.ts +64 -0
- package/src/utils/clientRegistry.ts +80 -0
- package/src/utils/devLogger.ts +197 -0
- package/src/utils/messageNotificationManager.ts +108 -0
- package/src/utils/resendMessage.ts +87 -0
- package/src/utils/toastEmitter.ts +27 -0
- package/src/utils/xmppMemoryMonitor.ts +63 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { AppState } from 'react-native';
|
|
2
|
+
import XmppClient from '../networking/xmppClient';
|
|
3
|
+
import { store } from '../roomStore';
|
|
4
|
+
import { applyRoomsPreloadBatch } from '../roomStore/roomsSlice';
|
|
5
|
+
import { IMessage, IRoom } from '../types/types';
|
|
6
|
+
|
|
7
|
+
interface HistoryPreloadSchedulerOptions {
|
|
8
|
+
client: XmppClient;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
concurrency?: number;
|
|
11
|
+
pageSize?: number;
|
|
12
|
+
retryLimit?: number;
|
|
13
|
+
roomLimit?: number;
|
|
14
|
+
selectedRoomJid?: string | null;
|
|
15
|
+
defaultRoomJids?: string[];
|
|
16
|
+
forceReload?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface QueueItem {
|
|
20
|
+
jid: string;
|
|
21
|
+
priority: number;
|
|
22
|
+
activityScore: number;
|
|
23
|
+
attempts: number;
|
|
24
|
+
readyAt: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const DEFAULT_CONCURRENCY = 3;
|
|
28
|
+
const DEFAULT_PAGE_SIZE = 10;
|
|
29
|
+
const DEFAULT_RETRY_LIMIT = 2;
|
|
30
|
+
|
|
31
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
32
|
+
|
|
33
|
+
const messageTimestamp = (m: IMessage): number => {
|
|
34
|
+
if (!m) {return 0;}
|
|
35
|
+
const t = (m as any).timestamp;
|
|
36
|
+
if (Number.isFinite(t) && t > 0) {return Number(t);}
|
|
37
|
+
const id = Number(m.id);
|
|
38
|
+
if (Number.isFinite(id) && id > 0) {return id;}
|
|
39
|
+
return 0;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const getRoomLastActivityScore = (room: IRoom): number => {
|
|
43
|
+
if (!room?.messages?.length) {return 0;}
|
|
44
|
+
return room.messages.reduce((max, m) => Math.max(max, messageTimestamp(m)), 0);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const computeUnreadCapped = (
|
|
48
|
+
room: IRoom,
|
|
49
|
+
messages: IMessage[],
|
|
50
|
+
pageSize: number
|
|
51
|
+
): boolean => {
|
|
52
|
+
if (!room) {return false;}
|
|
53
|
+
if (!messages || messages.length < pageSize) {return false;}
|
|
54
|
+
if (room.historyComplete === true) {return false;}
|
|
55
|
+
|
|
56
|
+
const countable = messages.filter(
|
|
57
|
+
(msg) => !!msg && msg.id !== 'delimiter-new' && !msg.pending
|
|
58
|
+
);
|
|
59
|
+
if (countable.length < pageSize) {return false;}
|
|
60
|
+
|
|
61
|
+
const lastViewed = Number(room.lastViewedTimestamp) || 0;
|
|
62
|
+
if (lastViewed <= 0) {return true;}
|
|
63
|
+
|
|
64
|
+
const oldestTs = countable.reduce<number>((minTs, m) => {
|
|
65
|
+
const ts = messageTimestamp(m);
|
|
66
|
+
if (!Number.isFinite(ts) || ts <= 0) {return minTs;}
|
|
67
|
+
return Math.min(minTs, ts);
|
|
68
|
+
}, Number.MAX_SAFE_INTEGER);
|
|
69
|
+
if (!Number.isFinite(oldestTs) || oldestTs === Number.MAX_SAFE_INTEGER)
|
|
70
|
+
{return false;}
|
|
71
|
+
return oldestTs > lastViewed;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const getRoomPriority = (
|
|
75
|
+
jid: string,
|
|
76
|
+
_room: IRoom,
|
|
77
|
+
selectedRoomJid: string | null,
|
|
78
|
+
defaultRoomJids: Set<string>
|
|
79
|
+
): number => {
|
|
80
|
+
if (selectedRoomJid && selectedRoomJid === jid) {return 0;}
|
|
81
|
+
if (defaultRoomJids.has(jid)) {return 1;}
|
|
82
|
+
return 2;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const shouldPauseForVisibility = (): boolean => {
|
|
86
|
+
return AppState.currentState !== 'active';
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Background-loads message history for every room into the redux store,
|
|
91
|
+
* prioritized by selected/default rooms then by last activity. Coalesces
|
|
92
|
+
* with the XMPP client's MAM queue (so the active-room scroll fetch wins).
|
|
93
|
+
* Mirrors the web `runHistoryPreloadScheduler`.
|
|
94
|
+
*/
|
|
95
|
+
export const runHistoryPreloadScheduler = async (
|
|
96
|
+
options: HistoryPreloadSchedulerOptions
|
|
97
|
+
): Promise<void> => {
|
|
98
|
+
const {
|
|
99
|
+
client,
|
|
100
|
+
signal,
|
|
101
|
+
concurrency = DEFAULT_CONCURRENCY,
|
|
102
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
|
103
|
+
retryLimit = DEFAULT_RETRY_LIMIT,
|
|
104
|
+
roomLimit,
|
|
105
|
+
selectedRoomJid = null,
|
|
106
|
+
defaultRoomJids = [],
|
|
107
|
+
forceReload = false,
|
|
108
|
+
} = options;
|
|
109
|
+
|
|
110
|
+
if (signal?.aborted) {return;}
|
|
111
|
+
|
|
112
|
+
const state = store.getState();
|
|
113
|
+
const rooms = (state.rooms.rooms || {}) as Record<string, IRoom>;
|
|
114
|
+
const defaultSet = new Set(defaultRoomJids);
|
|
115
|
+
|
|
116
|
+
const sortedQueue: QueueItem[] = Object.entries(rooms)
|
|
117
|
+
.map(([jid, room]: [string, IRoom]) => ({
|
|
118
|
+
jid,
|
|
119
|
+
priority: getRoomPriority(jid, room, selectedRoomJid, defaultSet),
|
|
120
|
+
activityScore: getRoomLastActivityScore(room),
|
|
121
|
+
attempts: 0,
|
|
122
|
+
readyAt: Date.now(),
|
|
123
|
+
}))
|
|
124
|
+
.sort((a, b) => {
|
|
125
|
+
if (a.priority !== b.priority) {return a.priority - b.priority;}
|
|
126
|
+
if (a.activityScore !== b.activityScore) {
|
|
127
|
+
return b.activityScore - a.activityScore;
|
|
128
|
+
}
|
|
129
|
+
return a.jid.localeCompare(b.jid);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const queue: QueueItem[] =
|
|
133
|
+
roomLimit && roomLimit > 0
|
|
134
|
+
? sortedQueue.slice(0, roomLimit)
|
|
135
|
+
: sortedQueue;
|
|
136
|
+
|
|
137
|
+
const inFlightByRoom = new Map<string, Promise<void>>();
|
|
138
|
+
let consecutiveErrorCount = 0;
|
|
139
|
+
|
|
140
|
+
while (queue.length > 0) {
|
|
141
|
+
if (signal?.aborted) {return;}
|
|
142
|
+
|
|
143
|
+
if (!client.isActiveRoomGateOpen()) {
|
|
144
|
+
await sleep(80);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (shouldPauseForVisibility()) {
|
|
148
|
+
await sleep(250);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const now = Date.now();
|
|
153
|
+
const readyItems = queue.filter(
|
|
154
|
+
(item) => item.readyAt <= now && !inFlightByRoom.has(item.jid)
|
|
155
|
+
);
|
|
156
|
+
if (readyItems.length === 0) {
|
|
157
|
+
await sleep(60);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const batch = readyItems.slice(0, Math.max(1, concurrency));
|
|
162
|
+
|
|
163
|
+
store.dispatch(
|
|
164
|
+
applyRoomsPreloadBatch({
|
|
165
|
+
rooms: batch.map((item) => ({
|
|
166
|
+
jid: item.jid,
|
|
167
|
+
historyPreloadState: 'loading',
|
|
168
|
+
})),
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
await Promise.all(
|
|
173
|
+
batch.map(async (item) => {
|
|
174
|
+
const queueIndex = queue.findIndex((queued) => queued.jid === item.jid);
|
|
175
|
+
if (queueIndex !== -1) {queue.splice(queueIndex, 1);}
|
|
176
|
+
|
|
177
|
+
const task = (async () => {
|
|
178
|
+
const currentRoom = store.getState().rooms.rooms[item.jid];
|
|
179
|
+
if (
|
|
180
|
+
!currentRoom ||
|
|
181
|
+
(!forceReload && currentRoom.historyPreloadState === 'done')
|
|
182
|
+
) {
|
|
183
|
+
store.dispatch(
|
|
184
|
+
applyRoomsPreloadBatch({
|
|
185
|
+
rooms: [{ jid: item.jid, historyPreloadState: 'done' }],
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
const fetchedMessages = await client.getHistoryStanza(
|
|
193
|
+
item.jid,
|
|
194
|
+
pageSize,
|
|
195
|
+
undefined,
|
|
196
|
+
undefined,
|
|
197
|
+
{
|
|
198
|
+
coalesceRoom: true,
|
|
199
|
+
skipIfPreloaded: !forceReload,
|
|
200
|
+
source: 'background',
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
if (signal?.aborted) {return;}
|
|
204
|
+
if (typeof fetchedMessages === 'undefined') {
|
|
205
|
+
throw new Error('history_timeout');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const nextRoom = store.getState().rooms.rooms[item.jid];
|
|
209
|
+
const unreadCapped = computeUnreadCapped(
|
|
210
|
+
nextRoom,
|
|
211
|
+
fetchedMessages || [],
|
|
212
|
+
pageSize
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
store.dispatch(
|
|
216
|
+
applyRoomsPreloadBatch({
|
|
217
|
+
rooms: [
|
|
218
|
+
{
|
|
219
|
+
jid: item.jid,
|
|
220
|
+
messages: fetchedMessages || [],
|
|
221
|
+
unreadCapped,
|
|
222
|
+
historyPreloadState: 'done',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
})
|
|
226
|
+
);
|
|
227
|
+
consecutiveErrorCount = 0;
|
|
228
|
+
} catch {
|
|
229
|
+
const retries = item.attempts + 1;
|
|
230
|
+
const canRetry = retries <= retryLimit;
|
|
231
|
+
if (canRetry) {
|
|
232
|
+
const jitter = Math.floor(Math.random() * 120);
|
|
233
|
+
const backoff = Math.min(1600, 240 * 2 ** item.attempts) + jitter;
|
|
234
|
+
queue.push({
|
|
235
|
+
...item,
|
|
236
|
+
attempts: retries,
|
|
237
|
+
readyAt: Date.now() + backoff,
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
store.dispatch(
|
|
241
|
+
applyRoomsPreloadBatch({
|
|
242
|
+
rooms: [{ jid: item.jid, historyPreloadState: 'error' }],
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
consecutiveErrorCount += 1;
|
|
247
|
+
if (consecutiveErrorCount >= 3) {
|
|
248
|
+
await sleep(300);
|
|
249
|
+
consecutiveErrorCount = 0;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
})();
|
|
253
|
+
|
|
254
|
+
inFlightByRoom.set(item.jid, task);
|
|
255
|
+
await task.finally(() => inFlightByRoom.delete(item.jid));
|
|
256
|
+
})
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
// Yield to JS event loop (no requestIdleCallback in RN).
|
|
260
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export default runHistoryPreloadScheduler;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import XmppClient from '../networking/xmppClient';
|
|
2
|
+
import { IRoom } from '../types/types';
|
|
3
|
+
import { presenceInRoom } from '../networking/xmpp/presenceInRoom.xmpp';
|
|
4
|
+
import { pushSubscriptionService } from '../services/pushSubscriptionService';
|
|
5
|
+
|
|
6
|
+
export const initRoomsPresence = async (
|
|
7
|
+
client: XmppClient,
|
|
8
|
+
rooms: { [jid: string]: IRoom }
|
|
9
|
+
) => {
|
|
10
|
+
console.log('Persisted presence');
|
|
11
|
+
if (!client) {return null;}
|
|
12
|
+
const jids = Object.keys(rooms || {});
|
|
13
|
+
if (!jids.length) {return null;}
|
|
14
|
+
await Promise.allSettled(
|
|
15
|
+
jids.map(async (jid) => {
|
|
16
|
+
try {
|
|
17
|
+
await presenceInRoom(client.client, jid);
|
|
18
|
+
} catch (e) {}
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (jids.length > 0 && client.client) {
|
|
23
|
+
const userNick = client.client.jid?.getLocal();
|
|
24
|
+
await pushSubscriptionService.subscribeToRooms(
|
|
25
|
+
client.client,
|
|
26
|
+
jids,
|
|
27
|
+
userNick
|
|
28
|
+
).catch((error) => {
|
|
29
|
+
console.error('Failed to subscribe to rooms for push:', error);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { setCurrentRoom, setIsLoading } from '../roomStore/roomsSlice';
|
|
2
|
+
import { updatedChatLastTimestamps } from './updatedChatLastTimestamps';
|
|
3
|
+
import { initRoomsPresence } from './initRoomsPresence';
|
|
4
|
+
import XmppClient from '../networking/xmppClient';
|
|
5
|
+
import { IConfig, IRoom, User } from '../types/types';
|
|
6
|
+
import { store } from '../roomStore';
|
|
7
|
+
|
|
8
|
+
const initXmppRooms = async (
|
|
9
|
+
user: User,
|
|
10
|
+
config: IConfig,
|
|
11
|
+
xmmpClient: XmppClient,
|
|
12
|
+
rooms?: { [key: string]: IRoom },
|
|
13
|
+
roomJID?: string
|
|
14
|
+
) => {
|
|
15
|
+
if (roomJID) {
|
|
16
|
+
store.dispatch(setCurrentRoom({ roomJID: roomJID }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
if (!user.defaultWallet || !user.defaultWallet.walletAddress) {
|
|
21
|
+
console.log('Error, no user');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!xmmpClient) {
|
|
26
|
+
console.log('No xmmpClient, initializing one');
|
|
27
|
+
|
|
28
|
+
if (rooms && Object.keys(rooms).length > 0) {
|
|
29
|
+
await initRoomsPresence(xmmpClient, rooms);
|
|
30
|
+
} else {
|
|
31
|
+
if (config?.newArch) {
|
|
32
|
+
// const rooms = await getRooms();
|
|
33
|
+
// rooms.items.map((room) => {
|
|
34
|
+
// dispatch(
|
|
35
|
+
// addRoomViaApi({
|
|
36
|
+
// room: createRoomFromApi(
|
|
37
|
+
// room,
|
|
38
|
+
// config?.xmppSettings?.conference
|
|
39
|
+
// ),
|
|
40
|
+
// xmpp: newClient,
|
|
41
|
+
// })
|
|
42
|
+
// );
|
|
43
|
+
// });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const res = await xmmpClient.getRoomsStanza();
|
|
47
|
+
console.log(res);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//@ts-ignore
|
|
51
|
+
const roomTimestampObject: [jid: string, timestamp: string] =
|
|
52
|
+
await xmmpClient.getChatsPrivateStoreRequestStanza();
|
|
53
|
+
updatedChatLastTimestamps(roomTimestampObject, store.dispatch);
|
|
54
|
+
} else {
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
const roomTimestampObject: [jid: string, timestamp: string] =
|
|
57
|
+
await xmmpClient.getChatsPrivateStoreRequestStanza();
|
|
58
|
+
updatedChatLastTimestamps(roomTimestampObject, store.dispatch);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (config?.refreshTokens?.enabled) {
|
|
62
|
+
config?.refreshTokens?.refreshFunction();
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(error);
|
|
66
|
+
} finally {
|
|
67
|
+
store.dispatch(setIsLoading({ loading: false }));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default initXmppRooms;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { IMessage } from '../types/types';
|
|
2
|
+
import { isDateAfter, isDateBefore } from './dateComparison';
|
|
3
|
+
|
|
4
|
+
function deepMerge(target: any, source: any): any {
|
|
5
|
+
for (const key in source) {
|
|
6
|
+
if (
|
|
7
|
+
source[key] &&
|
|
8
|
+
typeof source[key] === 'object' &&
|
|
9
|
+
!Array.isArray(source[key])
|
|
10
|
+
) {
|
|
11
|
+
target[key] = deepMerge(target[key] || {}, source[key]);
|
|
12
|
+
} else {
|
|
13
|
+
target[key] = source[key];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function insertMessageWithDelimiter(
|
|
20
|
+
roomMessages: Partial<IMessage>[],
|
|
21
|
+
message: IMessage,
|
|
22
|
+
lastViewedTimestamp: { toString: () => string } | null,
|
|
23
|
+
) {
|
|
24
|
+
const existingIndex = roomMessages.findIndex(
|
|
25
|
+
(msg) =>
|
|
26
|
+
msg.id === message.id ||
|
|
27
|
+
(message.xmppId && msg.id === message.xmppId) ||
|
|
28
|
+
(msg.xmppId && msg.xmppId === message.id)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (existingIndex !== -1) {
|
|
32
|
+
roomMessages[existingIndex] = deepMerge(
|
|
33
|
+
{ ...roomMessages[existingIndex] },
|
|
34
|
+
{ ...message, pending: false }
|
|
35
|
+
);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const newMessageDate = message.date;
|
|
40
|
+
const lastMessage = roomMessages[roomMessages.length - 1];
|
|
41
|
+
const firstMessage = roomMessages[0];
|
|
42
|
+
|
|
43
|
+
if (isDateAfter(newMessageDate.toString(), lastMessage.date.toString())) {
|
|
44
|
+
const index = roomMessages.findIndex(
|
|
45
|
+
(msg) => msg.id === message.xmppId || msg.id === message.id
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (index !== -1) {
|
|
49
|
+
roomMessages[index] = { ...message, id: message.id, pending: false };
|
|
50
|
+
} else {
|
|
51
|
+
roomMessages.push(message);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
lastViewedTimestamp &&
|
|
56
|
+
!roomMessages.some((msg) => msg.id === 'delimiter-new') &&
|
|
57
|
+
isDateAfter(newMessageDate.toString(), lastViewedTimestamp.toString())
|
|
58
|
+
) {
|
|
59
|
+
const delimiterIndex = roomMessages.findIndex((msg) =>
|
|
60
|
+
isDateAfter(msg.date.toString(), lastViewedTimestamp.toString())
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (delimiterIndex !== -1) {
|
|
64
|
+
roomMessages.splice(delimiterIndex, 0, {
|
|
65
|
+
id: 'delimiter-new',
|
|
66
|
+
user: {
|
|
67
|
+
id: 'system',
|
|
68
|
+
name: null,
|
|
69
|
+
token: '',
|
|
70
|
+
refreshToken: '',
|
|
71
|
+
},
|
|
72
|
+
date: new Date().toString(),
|
|
73
|
+
body: 'New Messages',
|
|
74
|
+
roomJid: '',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (lastViewedTimestamp.toString() === '0') {
|
|
78
|
+
roomMessages.splice(delimiterIndex, 1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} else if (
|
|
83
|
+
isDateBefore(newMessageDate.toString(), firstMessage.date.toString())
|
|
84
|
+
) {
|
|
85
|
+
roomMessages.unshift(message);
|
|
86
|
+
} else {
|
|
87
|
+
for (let i = 0; i < roomMessages.length; i++) {
|
|
88
|
+
if (
|
|
89
|
+
isDateBefore(newMessageDate.toString(), roomMessages[i].date.toString())
|
|
90
|
+
) {
|
|
91
|
+
roomMessages.splice(i, 0, message);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ApiRoom, IRoom } from '../types/types';
|
|
2
|
+
|
|
3
|
+
export function isChatIdPresentInArray(
|
|
4
|
+
chatIdToFind: string | null | undefined,
|
|
5
|
+
chatList: ApiRoom[] | { [jid: string]: IRoom }
|
|
6
|
+
): boolean {
|
|
7
|
+
if (!chatList) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (Array.isArray(chatList)) {
|
|
12
|
+
if (chatList.length === 0) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
if (Object.keys(chatList).length === 0) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if(!chatIdToFind || typeof chatIdToFind !== 'string') {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const trimmedId = chatIdToFind.split('@')[0].trim();
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(chatList)) {
|
|
28
|
+
for (const chatObject of chatList) {
|
|
29
|
+
console.log('check', trimmedId === chatObject.name);
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
chatObject &&
|
|
33
|
+
typeof chatObject.name === 'string' &&
|
|
34
|
+
chatObject.name === trimmedId
|
|
35
|
+
) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
for (const jid in chatList) {
|
|
41
|
+
const chatObject = chatList[jid];
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
chatObject &&
|
|
45
|
+
typeof chatObject.name === 'string' &&
|
|
46
|
+
chatObject.name === trimmedId
|
|
47
|
+
) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { User } from '../types/types';
|
|
2
|
+
import { localStorageConstants } from './constants/LOCAL_STORAGE';
|
|
3
|
+
|
|
4
|
+
export const getLocalStorageUser = () => {
|
|
5
|
+
const user: User = JSON.parse(
|
|
6
|
+
localStorage.getItem(localStorageConstants.ETHORA_USER)
|
|
7
|
+
);
|
|
8
|
+
return user;
|
|
9
|
+
};
|