@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,74 @@
|
|
|
1
|
+
import { Element } from 'ltx';
|
|
2
|
+
import { Client, xml } from '@xmpp/client';
|
|
3
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
4
|
+
|
|
5
|
+
export function createRoomPresence(roomId: string, client: Client) {
|
|
6
|
+
let stanzaHdlrPointer: {
|
|
7
|
+
(el: Element): void;
|
|
8
|
+
(stanza: Element): void;
|
|
9
|
+
(el: Element): void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const unsubscribe = () => {
|
|
13
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
17
|
+
stanzaHdlrPointer = (stanza: Element) => {
|
|
18
|
+
if (
|
|
19
|
+
stanza.is('presence') &&
|
|
20
|
+
stanza.attrs.from.split('/')[0] === roomId
|
|
21
|
+
) {
|
|
22
|
+
const xEls = stanza.getChildren('x');
|
|
23
|
+
|
|
24
|
+
if (xEls.length === 2) {
|
|
25
|
+
const x = xEls.find(
|
|
26
|
+
(el) => el.attrs.xmlns === 'http://jabber.org/protocol/muc#user'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (x) {
|
|
30
|
+
const statuses = x.getChildren('status');
|
|
31
|
+
|
|
32
|
+
if (!statuses) {
|
|
33
|
+
unsubscribe();
|
|
34
|
+
reject('!statuses');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const codes = statuses.map((el) => el.attrs.code);
|
|
38
|
+
|
|
39
|
+
if (codes.includes('201') && codes.includes('110')) {
|
|
40
|
+
console.log('createRoomPresence:resolve true');
|
|
41
|
+
unsubscribe();
|
|
42
|
+
resolve(true);
|
|
43
|
+
} else {
|
|
44
|
+
console.log(
|
|
45
|
+
'createRoomPresence:reject, such room already exists'
|
|
46
|
+
);
|
|
47
|
+
unsubscribe();
|
|
48
|
+
resolve(true);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
unsubscribe();
|
|
52
|
+
reject();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
client.on('stanza', stanzaHdlrPointer);
|
|
59
|
+
|
|
60
|
+
const message = xml(
|
|
61
|
+
'presence',
|
|
62
|
+
{
|
|
63
|
+
to: `${roomId}/${client.jid.getLocal()}`,
|
|
64
|
+
},
|
|
65
|
+
xml('x', 'http://jabber.org/protocol/muc')
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
client.send(message);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const timeoutPromise = createTimeoutPromise(2000, unsubscribe);
|
|
72
|
+
|
|
73
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
74
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function createTimeoutPromise(
|
|
2
|
+
ms: number | undefined,
|
|
3
|
+
unsubscribe?: () => void
|
|
4
|
+
) {
|
|
5
|
+
return new Promise((_, reject) => {
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
try {
|
|
8
|
+
if (unsubscribe) {
|
|
9
|
+
unsubscribe();
|
|
10
|
+
}
|
|
11
|
+
} catch (e) {}
|
|
12
|
+
reject();
|
|
13
|
+
}, ms);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export function deleteMessage(client: Client, room: string, msgId: string) {
|
|
4
|
+
const stanza = xml(
|
|
5
|
+
'message',
|
|
6
|
+
{
|
|
7
|
+
from: client.jid?.toString(),
|
|
8
|
+
to: room,
|
|
9
|
+
id: 'deleteMessageStanza',
|
|
10
|
+
type: 'groupchat',
|
|
11
|
+
},
|
|
12
|
+
xml('body', 'wow'),
|
|
13
|
+
xml('delete', {
|
|
14
|
+
id: msgId,
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
client.send(stanza);
|
|
19
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
3
|
+
|
|
4
|
+
export async function editMessage(client: Client, chatId: string, messageId: string, text: string) {
|
|
5
|
+
const id = `edit-message-${Date.now().toString()}`;
|
|
6
|
+
const xmlMessage = xml(
|
|
7
|
+
'message',
|
|
8
|
+
{
|
|
9
|
+
to: chatId,
|
|
10
|
+
type: 'groupchat',
|
|
11
|
+
id: id,
|
|
12
|
+
},
|
|
13
|
+
xml(
|
|
14
|
+
'replace',
|
|
15
|
+
{
|
|
16
|
+
id: messageId,
|
|
17
|
+
text: text,
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
// let stanzaHdlrPointer;
|
|
22
|
+
// const unsubscribe = () => {
|
|
23
|
+
// client.off('stanza', stanzaHdlrPointer)
|
|
24
|
+
// }
|
|
25
|
+
// const responsePromise = new Promise((resolve, _) => {
|
|
26
|
+
// stanzaHdlrPointer = (stanza) => {
|
|
27
|
+
// if (stanza.is("message") && stanza.attrs["id"] === id) {
|
|
28
|
+
// console.log("edit message response ", stanza.toString())
|
|
29
|
+
// resolve(true)
|
|
30
|
+
// // const msg = stanza
|
|
31
|
+
// // const text = msg.getChild('body')?.getText()
|
|
32
|
+
// // if (text) {
|
|
33
|
+
// // let parsedEl: any = {}
|
|
34
|
+
// // const result = ws.realtimeMessageParser(msg)
|
|
35
|
+
// // unsubscribe()
|
|
36
|
+
// // resolve(true)
|
|
37
|
+
// // }
|
|
38
|
+
// }
|
|
39
|
+
// }
|
|
40
|
+
// client.on("stanza", stanzaHdlrPointer)
|
|
41
|
+
// console.log("editMessage:send:stanza ", xmlMessage.toString())
|
|
42
|
+
client.send(xmlMessage);
|
|
43
|
+
// })
|
|
44
|
+
// const timeoutPromise = createTimeoutPromise(10000, unsubscribe)
|
|
45
|
+
// return Promise.race([responsePromise, timeoutPromise]);
|
|
46
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { Element } from 'ltx';
|
|
3
|
+
|
|
4
|
+
export async function getChatsPrivateStoreRequest(client: Client) {
|
|
5
|
+
const id = `get-chats-private-req:${Date.now().toString()}`;
|
|
6
|
+
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
let stanzaHdlrPointer: (stanza: Element) => void;
|
|
9
|
+
|
|
10
|
+
const timeout = setTimeout(() => {
|
|
11
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
12
|
+
reject(new Error('get-chats-private timed out'));
|
|
13
|
+
}, 10000);
|
|
14
|
+
|
|
15
|
+
stanzaHdlrPointer = (stanza: Element) => {
|
|
16
|
+
if (stanza.is('iq') && stanza.attrs.id === id) {
|
|
17
|
+
clearTimeout(timeout);
|
|
18
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
19
|
+
|
|
20
|
+
if (stanza.attrs.type === 'error') {
|
|
21
|
+
reject(new Error('Error response from server'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const chatjson = stanza.getChild('query')?.getChild('chatjson');
|
|
26
|
+
if (chatjson && chatjson.attrs.value) {
|
|
27
|
+
try {
|
|
28
|
+
const roomTimestampObject = JSON.parse(chatjson.attrs.value);
|
|
29
|
+
resolve(roomTimestampObject);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
resolve(null);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
client.on('stanza', stanzaHdlrPointer);
|
|
40
|
+
|
|
41
|
+
const message = xml(
|
|
42
|
+
'iq',
|
|
43
|
+
{ id, type: 'get' },
|
|
44
|
+
xml(
|
|
45
|
+
'query',
|
|
46
|
+
{ xmlns: 'jabber:iq:private' },
|
|
47
|
+
xml('chatjson', { xmlns: 'chatjson:store' })
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
client.send(message).catch((err) => {
|
|
52
|
+
clearTimeout(timeout);
|
|
53
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
54
|
+
reject(err);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
3
|
+
import { Element } from 'ltx';
|
|
4
|
+
import { IMessage } from '../../types/types';
|
|
5
|
+
import { getDataFromXml } from '../../helpers/getDataFromXml';
|
|
6
|
+
import { createMessageFromXml } from '../../helpers/createMessageFromXml';
|
|
7
|
+
|
|
8
|
+
export const getHistory = async (
|
|
9
|
+
client: Client,
|
|
10
|
+
chatJID: string,
|
|
11
|
+
max: number,
|
|
12
|
+
before?: number,
|
|
13
|
+
otherId?: string
|
|
14
|
+
): Promise<IMessage[] | undefined> => {
|
|
15
|
+
if (typeof chatJID !== 'string') {return;}
|
|
16
|
+
// If a caller passes a bare local-part (no `@host`), pick a default
|
|
17
|
+
// conference based on the client's actual service URL — never leak a
|
|
18
|
+
// hard-coded dev domain.
|
|
19
|
+
const fixedChatJid = chatJID.includes('@')
|
|
20
|
+
? chatJID
|
|
21
|
+
: (() => {
|
|
22
|
+
const service: string = (client as any)?.options?.service || '';
|
|
23
|
+
const host =
|
|
24
|
+
service.match(/wss?:\/\/([^:/]+)/)?.[1] || 'xmpp.chat.ethora.com';
|
|
25
|
+
return `${chatJID}@conference.${host}`;
|
|
26
|
+
})();
|
|
27
|
+
|
|
28
|
+
const id = otherId ?? `get-history:${Date.now().toString()}`;
|
|
29
|
+
|
|
30
|
+
let stanzaHdlrPointer: {
|
|
31
|
+
(el: Element): void;
|
|
32
|
+
(stanza: any): void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const unsubscribe = () => {
|
|
36
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
40
|
+
let messages: Element[] = [];
|
|
41
|
+
|
|
42
|
+
stanzaHdlrPointer = async (stanza) => {
|
|
43
|
+
const result = stanza.getChild('result');
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
stanza.is('message') &&
|
|
47
|
+
stanza.attrs.from &&
|
|
48
|
+
stanza.attrs.from.startsWith(fixedChatJid) &&
|
|
49
|
+
result
|
|
50
|
+
) {
|
|
51
|
+
const messageEl = result.getChild('forwarded')?.getChild('message');
|
|
52
|
+
|
|
53
|
+
messages.push(messageEl);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
stanza.is('iq') &&
|
|
58
|
+
stanza.attrs.id === id &&
|
|
59
|
+
stanza.attrs.type === 'result'
|
|
60
|
+
) {
|
|
61
|
+
let mainMessages: IMessage[] = [];
|
|
62
|
+
|
|
63
|
+
for (const msg of messages) {
|
|
64
|
+
const reactions = msg?.getChild('reactions');
|
|
65
|
+
const text = msg.getChild('body')?.getText();
|
|
66
|
+
|
|
67
|
+
if (text || reactions) {
|
|
68
|
+
const result = await getDataFromXml(msg);
|
|
69
|
+
if (!result) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { data, id, body, ...rest } = result;
|
|
73
|
+
|
|
74
|
+
if (!data) {
|
|
75
|
+
console.log('No data in stanza');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const message = await createMessageFromXml({
|
|
80
|
+
data,
|
|
81
|
+
id,
|
|
82
|
+
body,
|
|
83
|
+
...rest,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
mainMessages.push(message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
resolve(mainMessages);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (
|
|
93
|
+
stanza.is('iq') &&
|
|
94
|
+
stanza.attrs.id === id &&
|
|
95
|
+
stanza.attrs.type === 'error'
|
|
96
|
+
) {
|
|
97
|
+
reject();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
client?.on('stanza', stanzaHdlrPointer);
|
|
102
|
+
|
|
103
|
+
const message = xml(
|
|
104
|
+
'iq',
|
|
105
|
+
{
|
|
106
|
+
type: 'set',
|
|
107
|
+
to: fixedChatJid,
|
|
108
|
+
id: id,
|
|
109
|
+
},
|
|
110
|
+
xml(
|
|
111
|
+
'query',
|
|
112
|
+
{ xmlns: 'urn:xmpp:mam:2' },
|
|
113
|
+
xml(
|
|
114
|
+
'set',
|
|
115
|
+
{ xmlns: 'http://jabber.org/protocol/rsm' },
|
|
116
|
+
xml('max', {}, max.toString()),
|
|
117
|
+
before ? xml('before', {}, before.toString()) : xml('before')
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
client?.send(message).catch((err) => console.log('err on load', err));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const timeoutPromise = createTimeoutPromise(10000);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
const res: IMessage[] | null = await Promise.race<[IMessage[] | null]>([
|
|
130
|
+
responsePromise as Promise<IMessage[] | null>,
|
|
131
|
+
timeoutPromise as Promise<null>,
|
|
132
|
+
]);
|
|
133
|
+
return res === null ? [] : res;
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.log('=-> error in', fixedChatJid, e);
|
|
136
|
+
return [];
|
|
137
|
+
} finally {
|
|
138
|
+
unsubscribe();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export function getLastMessage(client: Client, roomJID: string) {
|
|
4
|
+
const message = xml(
|
|
5
|
+
'iq',
|
|
6
|
+
{
|
|
7
|
+
type: 'set',
|
|
8
|
+
to: roomJID,
|
|
9
|
+
id: 'GetArchive',
|
|
10
|
+
},
|
|
11
|
+
xml(
|
|
12
|
+
'query',
|
|
13
|
+
{ xmlns: 'urn:xmpp:mam:2' },
|
|
14
|
+
xml(
|
|
15
|
+
'set',
|
|
16
|
+
{ xmlns: 'http://jabber.org/protocol/rsm' },
|
|
17
|
+
xml('max', {}, '1'),
|
|
18
|
+
xml('before')
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
client.send(message);
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export const getRoomInfo = (roomJID: string, client: Client) => {
|
|
4
|
+
//main info, descrription etc
|
|
5
|
+
const message = xml(
|
|
6
|
+
'iq',
|
|
7
|
+
{
|
|
8
|
+
id: 'roomInfo',
|
|
9
|
+
to: roomJID,
|
|
10
|
+
type: 'get',
|
|
11
|
+
},
|
|
12
|
+
xml('query', { xmlns: 'http://jabber.org/protocol/disco#info' })
|
|
13
|
+
);
|
|
14
|
+
client.send(message);
|
|
15
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export const getRoomMembers = (roomJID: string, client: any) => {
|
|
4
|
+
const message = xml(
|
|
5
|
+
'iq',
|
|
6
|
+
{
|
|
7
|
+
id: 'roomMemberInfo',
|
|
8
|
+
type: 'get',
|
|
9
|
+
},
|
|
10
|
+
xml('query', { xmlns: 'ns:room:last', room: roomJID })
|
|
11
|
+
);
|
|
12
|
+
client.send(message);
|
|
13
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
3
|
+
import { Element } from 'ltx';
|
|
4
|
+
|
|
5
|
+
export const getRooms = async (client: Client): Promise<any> => {
|
|
6
|
+
let stanzaHdlrPointer: (stanza: Element) => void;
|
|
7
|
+
|
|
8
|
+
const unsubscribe = () => {
|
|
9
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const responsePromise = new Promise<void>((resolve, reject) => {
|
|
13
|
+
stanzaHdlrPointer = (stanza) => {};
|
|
14
|
+
|
|
15
|
+
client.on('stanza', stanzaHdlrPointer);
|
|
16
|
+
|
|
17
|
+
const message = xml(
|
|
18
|
+
'iq',
|
|
19
|
+
{
|
|
20
|
+
type: 'get',
|
|
21
|
+
from: client.jid?.toString(),
|
|
22
|
+
id: 'getUserRooms',
|
|
23
|
+
},
|
|
24
|
+
xml('query', { xmlns: 'ns:getrooms' })
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
client.send(message).catch((err) => {
|
|
28
|
+
console.error('Error sending getRooms request:', err);
|
|
29
|
+
unsubscribe();
|
|
30
|
+
reject(err);
|
|
31
|
+
});
|
|
32
|
+
resolve();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const timeoutPromise = createTimeoutPromise(2000, unsubscribe);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
return await Promise.race([responsePromise, timeoutPromise]);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error('Error in getRooms:', e);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
3
|
+
import { Element } from '@xmpp/xml';
|
|
4
|
+
|
|
5
|
+
export const getRoomsPaged = async (
|
|
6
|
+
client: Client,
|
|
7
|
+
maxResults = 3,
|
|
8
|
+
before = null
|
|
9
|
+
) => {
|
|
10
|
+
let stanzaHdlrPointer: {
|
|
11
|
+
(el: Element): void;
|
|
12
|
+
(stanza: any): void;
|
|
13
|
+
(el: Element): void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const unsubscribe = () => {
|
|
17
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return new Promise(async (resolve, reject) => {
|
|
21
|
+
stanzaHdlrPointer = (stanza) => {
|
|
22
|
+
if (stanza.is('iq') && stanza.attrs.id === 'getUserRooms') {
|
|
23
|
+
unsubscribe();
|
|
24
|
+
resolve(stanza);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
client.on('stanza', stanzaHdlrPointer);
|
|
29
|
+
|
|
30
|
+
const query = xml('query', { xmlns: 'ns:getrooms' });
|
|
31
|
+
const set = xml(
|
|
32
|
+
'set',
|
|
33
|
+
{ xmlns: 'http://jabber.org/protocol/rsm' },
|
|
34
|
+
xml('max', {}, maxResults.toString())
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (before) {
|
|
38
|
+
set.append(xml('before', {}, before));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
query.append(set);
|
|
42
|
+
|
|
43
|
+
const message = xml(
|
|
44
|
+
'iq',
|
|
45
|
+
{ type: 'get', from: client.jid?.toString(), id: 'getUserRoomsPaged' },
|
|
46
|
+
query
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
client.send(message);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.error('Error sending getRooms request:', err);
|
|
53
|
+
unsubscribe();
|
|
54
|
+
reject(err);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await createTimeoutPromise(2000, unsubscribe).catch(reject);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Element } from 'ltx';
|
|
2
|
+
import {
|
|
3
|
+
onDeleteMessage,
|
|
4
|
+
onEditMessage,
|
|
5
|
+
onRealtimeMessage,
|
|
6
|
+
onMessageHistory,
|
|
7
|
+
onGetLastMessageArchive,
|
|
8
|
+
handleComposing,
|
|
9
|
+
onChatInvite,
|
|
10
|
+
onPresenceInRoom,
|
|
11
|
+
onGetChatRooms,
|
|
12
|
+
onGetMembers,
|
|
13
|
+
onGetRoomInfo,
|
|
14
|
+
onNewRoomCreated,
|
|
15
|
+
onReactionMessage,
|
|
16
|
+
onReactionHistory,
|
|
17
|
+
onRoomKicked,
|
|
18
|
+
onMessageError,
|
|
19
|
+
} from '../stanzaHandlers';
|
|
20
|
+
import XmppClient from '../xmppClient';
|
|
21
|
+
|
|
22
|
+
export function handleStanza(stanza: Element, xmppWs: XmppClient) {
|
|
23
|
+
if (stanza?.attrs?.type === 'headline') {return;}
|
|
24
|
+
switch (stanza.name) {
|
|
25
|
+
case 'message':
|
|
26
|
+
onMessageError(stanza, xmppWs);
|
|
27
|
+
onReactionMessage(stanza);
|
|
28
|
+
onReactionHistory(stanza);
|
|
29
|
+
onDeleteMessage(stanza);
|
|
30
|
+
onEditMessage(stanza);
|
|
31
|
+
onChatInvite(stanza, xmppWs);
|
|
32
|
+
onRealtimeMessage(stanza);
|
|
33
|
+
onMessageHistory(stanza);
|
|
34
|
+
handleComposing(stanza, xmppWs.username);
|
|
35
|
+
onPresenceInRoom(stanza);
|
|
36
|
+
break;
|
|
37
|
+
case 'presence':
|
|
38
|
+
onRoomKicked(stanza);
|
|
39
|
+
onPresenceInRoom(stanza);
|
|
40
|
+
break;
|
|
41
|
+
case 'iq':
|
|
42
|
+
onGetChatRooms(stanza, xmppWs);
|
|
43
|
+
onRealtimeMessage(stanza);
|
|
44
|
+
onPresenceInRoom(stanza);
|
|
45
|
+
onGetMembers(stanza);
|
|
46
|
+
onGetRoomInfo(stanza);
|
|
47
|
+
onGetLastMessageArchive(stanza);
|
|
48
|
+
break;
|
|
49
|
+
case 'room-config':
|
|
50
|
+
onNewRoomCreated(stanza, xmppWs);
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
console.log('Unhandled stanza type:', stanza.name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { CHAT_DOMAIN } from '../../helpers/constants/PLATFORM_CONSTANTS';
|
|
3
|
+
|
|
4
|
+
export async function inviteRoomRequest(
|
|
5
|
+
client: Client,
|
|
6
|
+
to: string,
|
|
7
|
+
roomJid: string
|
|
8
|
+
) {
|
|
9
|
+
const id = `invite-rooms:${Date.now().toString()}`;
|
|
10
|
+
|
|
11
|
+
const xmlMessage = xml(
|
|
12
|
+
'message',
|
|
13
|
+
{
|
|
14
|
+
to: roomJid,
|
|
15
|
+
id: id,
|
|
16
|
+
},
|
|
17
|
+
xml(
|
|
18
|
+
'x',
|
|
19
|
+
'http://jabber.org/protocol/muc#user',
|
|
20
|
+
xml('invite', { to: to + CHAT_DOMAIN })
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
client.send(xmlMessage);
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export const leaveTheRoom = (roomJID: string, client: Client) => {
|
|
4
|
+
if (!client.jid) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
'Client JID is not set. Ensure the client is authenticated before calling this function.'
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
const message = xml('presence', {
|
|
10
|
+
to: `${roomJID}/${client.jid.getLocal()}`,
|
|
11
|
+
type: 'unavailable',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
client.send(message);
|
|
15
|
+
};
|