@ethora/chat-component-rn 26.10.4 → 26.10.6
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/CHANGELOG.md +8 -0
- package/README.md +15 -0
- package/app.plugin.js +2 -0
- package/lib/commonjs/assets/icons.js +2 -2
- package/lib/commonjs/assets/icons.js.map +1 -1
- package/lib/commonjs/components/MainComponents/AlbumGrid.js +152 -0
- package/lib/commonjs/components/MainComponents/AlbumGrid.js.map +1 -0
- package/lib/commonjs/components/MainComponents/ChatRoom.js +2 -2
- package/lib/commonjs/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/commonjs/components/MainComponents/MediaMessage.js +199 -123
- package/lib/commonjs/components/MainComponents/MediaMessage.js.map +1 -1
- package/lib/commonjs/components/MainComponents/MediaUploadOverlay.js +109 -0
- package/lib/commonjs/components/MainComponents/MediaUploadOverlay.js.map +1 -0
- package/lib/commonjs/components/MessageBubble/MediaCaption.js +51 -0
- package/lib/commonjs/components/MessageBubble/MediaCaption.js.map +1 -0
- package/lib/commonjs/components/MessageBubble/Message.js +40 -1
- package/lib/commonjs/components/MessageBubble/Message.js.map +1 -1
- package/lib/commonjs/components/MessageBubble/MessageInteractions.js +2 -1
- package/lib/commonjs/components/MessageBubble/MessageInteractions.js.map +1 -1
- package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js +75 -0
- package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/LastMessageItem.js +20 -4
- package/lib/commonjs/components/RoomComponents/LastMessageItem.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastAudioMessage.js +3 -2
- package/lib/commonjs/components/RoomComponents/styled/LastAudioMessage.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js +3 -2
- package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js +3 -2
- package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js +3 -2
- package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
- package/lib/commonjs/components/Thread/ThreadWrapper.js +3 -2
- package/lib/commonjs/components/Thread/ThreadWrapper.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/ActiveCallBar.js +61 -16
- package/lib/commonjs/components/VideoCalls/ActiveCallBar.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/CallIcons.js +41 -16
- package/lib/commonjs/components/VideoCalls/CallIcons.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/VideoCallOverlay.js +183 -9
- package/lib/commonjs/components/VideoCalls/VideoCallOverlay.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/VideoCallSession.js +40 -15
- package/lib/commonjs/components/VideoCalls/VideoCallSession.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/callSessionController.js +49 -26
- package/lib/commonjs/components/VideoCalls/callSessionController.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/callUiStore.js +33 -4
- package/lib/commonjs/components/VideoCalls/callUiStore.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/livekitRuntime.js +9 -1
- package/lib/commonjs/components/VideoCalls/livekitRuntime.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/useCallKeep.js +197 -28
- package/lib/commonjs/components/VideoCalls/useCallKeep.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/useOngoingCallNotification.js +88 -0
- package/lib/commonjs/components/VideoCalls/useOngoingCallNotification.js.map +1 -0
- package/lib/commonjs/components/VideoCalls/usePipTile.js +232 -0
- package/lib/commonjs/components/VideoCalls/usePipTile.js.map +1 -0
- package/lib/commonjs/components/styled/MediaFilePreview.js +60 -47
- package/lib/commonjs/components/styled/MediaFilePreview.js.map +1 -1
- package/lib/commonjs/components/styled/MessageImage.js +16 -6
- package/lib/commonjs/components/styled/MessageImage.js.map +1 -1
- package/lib/commonjs/components/styled/SendInput.js +99 -68
- package/lib/commonjs/components/styled/SendInput.js.map +1 -1
- package/lib/commonjs/components/styled/VideoMessage.js +24 -10
- package/lib/commonjs/components/styled/VideoMessage.js.map +1 -1
- package/lib/commonjs/context/xmppProvider.js +46 -0
- package/lib/commonjs/context/xmppProvider.js.map +1 -1
- package/lib/commonjs/e2ee/fileEnvelope.js +6 -0
- package/lib/commonjs/e2ee/fileEnvelope.js.map +1 -1
- package/lib/commonjs/e2ee/sealedBody.js +32 -2
- package/lib/commonjs/e2ee/sealedBody.js.map +1 -1
- package/lib/commonjs/helpers/albumLayout.js +150 -0
- package/lib/commonjs/helpers/albumLayout.js.map +1 -0
- package/lib/commonjs/helpers/attachments.js +255 -0
- package/lib/commonjs/helpers/attachments.js.map +1 -0
- package/lib/commonjs/helpers/caption.js +214 -0
- package/lib/commonjs/helpers/caption.js.map +1 -0
- package/lib/commonjs/helpers/createMainMessageForThread.js +5 -1
- package/lib/commonjs/helpers/createMainMessageForThread.js.map +1 -1
- package/lib/commonjs/helpers/createMessageFromXml.js +19 -5
- package/lib/commonjs/helpers/createMessageFromXml.js.map +1 -1
- package/lib/commonjs/helpers/fileKind.js +40 -0
- package/lib/commonjs/helpers/fileKind.js.map +1 -0
- package/lib/commonjs/helpers/getDataFromXml.js +6 -1
- package/lib/commonjs/helpers/getDataFromXml.js.map +1 -1
- package/lib/commonjs/helpers/mapWithConcurrency.js +41 -0
- package/lib/commonjs/helpers/mapWithConcurrency.js.map +1 -0
- package/lib/commonjs/helpers/mediaLimits.js +33 -0
- package/lib/commonjs/helpers/mediaLimits.js.map +1 -0
- package/lib/commonjs/helpers/mediaSendRetry.js +64 -0
- package/lib/commonjs/helpers/mediaSendRetry.js.map +1 -0
- package/lib/commonjs/helpers/mediaWireData.js +62 -0
- package/lib/commonjs/helpers/mediaWireData.js.map +1 -0
- package/lib/commonjs/helpers/mentionSpans.js +19 -0
- package/lib/commonjs/helpers/mentionSpans.js.map +1 -0
- package/lib/commonjs/helpers/mimeToExtension.js +45 -0
- package/lib/commonjs/helpers/mimeToExtension.js.map +1 -1
- package/lib/commonjs/helpers/readReceipts.js +173 -0
- package/lib/commonjs/helpers/readReceipts.js.map +1 -0
- package/lib/commonjs/helpers/repairFilenameEncoding.js +79 -0
- package/lib/commonjs/helpers/repairFilenameEncoding.js.map +1 -0
- package/lib/commonjs/helpers/safeJson.js +18 -0
- package/lib/commonjs/helpers/safeJson.js.map +1 -0
- package/lib/commonjs/helpers/updateMessagesTillLast.js +3 -1
- package/lib/commonjs/helpers/updateMessagesTillLast.js.map +1 -1
- package/lib/commonjs/hooks/useSendMessage.js +384 -193
- package/lib/commonjs/hooks/useSendMessage.js.map +1 -1
- package/lib/commonjs/i18n/strings.js +144 -0
- package/lib/commonjs/i18n/strings.js.map +1 -1
- package/lib/commonjs/main.js.map +1 -1
- package/lib/commonjs/networking/api-requests/auth.api.js +62 -3
- package/lib/commonjs/networking/api-requests/auth.api.js.map +1 -1
- package/lib/commonjs/networking/stanzaHandlers.js +100 -3
- package/lib/commonjs/networking/stanzaHandlers.js.map +1 -1
- package/lib/commonjs/networking/xmpp/handleStanzas.xmpp.js +4 -2
- package/lib/commonjs/networking/xmpp/handleStanzas.xmpp.js.map +1 -1
- package/lib/commonjs/networking/xmpp/sendDisplayedMarker.xmpp.js +28 -0
- package/lib/commonjs/networking/xmpp/sendDisplayedMarker.xmpp.js.map +1 -0
- package/lib/commonjs/networking/xmpp/sendMediaMessage.xmpp.js +53 -2
- package/lib/commonjs/networking/xmpp/sendMediaMessage.xmpp.js.map +1 -1
- package/lib/commonjs/networking/xmpp/sendReceivedReceipt.xmpp.js +28 -0
- package/lib/commonjs/networking/xmpp/sendReceivedReceipt.xmpp.js.map +1 -0
- package/lib/commonjs/networking/xmppClient.js +64 -0
- package/lib/commonjs/networking/xmppClient.js.map +1 -1
- package/lib/commonjs/roomStore/persistence.js +78 -5
- package/lib/commonjs/roomStore/persistence.js.map +1 -1
- package/lib/commonjs/roomStore/roomHeapSlice.js +4 -0
- package/lib/commonjs/roomStore/roomHeapSlice.js.map +1 -1
- package/lib/commonjs/roomStore/roomsSlice.js +114 -1
- package/lib/commonjs/roomStore/roomsSlice.js.map +1 -1
- package/lib/commonjs/types/models/attachment.model.js +2 -0
- package/lib/commonjs/types/models/attachment.model.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/assets/icons.js +1 -1
- package/lib/module/assets/icons.js.map +1 -1
- package/lib/module/components/MainComponents/AlbumGrid.js +146 -0
- package/lib/module/components/MainComponents/AlbumGrid.js.map +1 -0
- package/lib/module/components/MainComponents/ChatRoom.js +2 -2
- package/lib/module/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/module/components/MainComponents/MediaMessage.js +200 -124
- package/lib/module/components/MainComponents/MediaMessage.js.map +1 -1
- package/lib/module/components/MainComponents/MediaUploadOverlay.js +104 -0
- package/lib/module/components/MainComponents/MediaUploadOverlay.js.map +1 -0
- package/lib/module/components/MessageBubble/MediaCaption.js +46 -0
- package/lib/module/components/MessageBubble/MediaCaption.js.map +1 -0
- package/lib/module/components/MessageBubble/Message.js +44 -5
- package/lib/module/components/MessageBubble/Message.js.map +1 -1
- package/lib/module/components/MessageBubble/MessageInteractions.js +2 -1
- package/lib/module/components/MessageBubble/MessageInteractions.js.map +1 -1
- package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js +75 -0
- package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
- package/lib/module/components/RoomComponents/LastMessageItem.js +20 -4
- package/lib/module/components/RoomComponents/LastMessageItem.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastAudioMessage.js +3 -2
- package/lib/module/components/RoomComponents/styled/LastAudioMessage.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastMessageFile.js +3 -2
- package/lib/module/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js +3 -2
- package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastMessageVideo.js +3 -2
- package/lib/module/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
- package/lib/module/components/Thread/ThreadWrapper.js +3 -2
- package/lib/module/components/Thread/ThreadWrapper.js.map +1 -1
- package/lib/module/components/VideoCalls/ActiveCallBar.js +63 -18
- package/lib/module/components/VideoCalls/ActiveCallBar.js.map +1 -1
- package/lib/module/components/VideoCalls/CallIcons.js +38 -15
- package/lib/module/components/VideoCalls/CallIcons.js.map +1 -1
- package/lib/module/components/VideoCalls/VideoCallOverlay.js +185 -11
- package/lib/module/components/VideoCalls/VideoCallOverlay.js.map +1 -1
- package/lib/module/components/VideoCalls/VideoCallSession.js +41 -16
- package/lib/module/components/VideoCalls/VideoCallSession.js.map +1 -1
- package/lib/module/components/VideoCalls/callSessionController.js +46 -24
- package/lib/module/components/VideoCalls/callSessionController.js.map +1 -1
- package/lib/module/components/VideoCalls/callUiStore.js +30 -3
- package/lib/module/components/VideoCalls/callUiStore.js.map +1 -1
- package/lib/module/components/VideoCalls/livekitRuntime.js +9 -1
- package/lib/module/components/VideoCalls/livekitRuntime.js.map +1 -1
- package/lib/module/components/VideoCalls/useCallKeep.js +198 -29
- package/lib/module/components/VideoCalls/useCallKeep.js.map +1 -1
- package/lib/module/components/VideoCalls/useOngoingCallNotification.js +84 -0
- package/lib/module/components/VideoCalls/useOngoingCallNotification.js.map +1 -0
- package/lib/module/components/VideoCalls/usePipTile.js +228 -0
- package/lib/module/components/VideoCalls/usePipTile.js.map +1 -0
- package/lib/module/components/styled/MediaFilePreview.js +61 -48
- package/lib/module/components/styled/MediaFilePreview.js.map +1 -1
- package/lib/module/components/styled/MessageImage.js +16 -6
- package/lib/module/components/styled/MessageImage.js.map +1 -1
- package/lib/module/components/styled/SendInput.js +99 -68
- package/lib/module/components/styled/SendInput.js.map +1 -1
- package/lib/module/components/styled/VideoMessage.js +24 -10
- package/lib/module/components/styled/VideoMessage.js.map +1 -1
- package/lib/module/context/xmppProvider.js +46 -0
- package/lib/module/context/xmppProvider.js.map +1 -1
- package/lib/module/e2ee/fileEnvelope.js +1 -1
- package/lib/module/e2ee/fileEnvelope.js.map +1 -1
- package/lib/module/e2ee/sealedBody.js +32 -2
- package/lib/module/e2ee/sealedBody.js.map +1 -1
- package/lib/module/helpers/albumLayout.js +143 -0
- package/lib/module/helpers/albumLayout.js.map +1 -0
- package/lib/module/helpers/attachments.js +245 -0
- package/lib/module/helpers/attachments.js.map +1 -0
- package/lib/module/helpers/caption.js +207 -0
- package/lib/module/helpers/caption.js.map +1 -0
- package/lib/module/helpers/createMainMessageForThread.js +5 -1
- package/lib/module/helpers/createMainMessageForThread.js.map +1 -1
- package/lib/module/helpers/createMessageFromXml.js +20 -6
- package/lib/module/helpers/createMessageFromXml.js.map +1 -1
- package/lib/module/helpers/fileKind.js +34 -0
- package/lib/module/helpers/fileKind.js.map +1 -0
- package/lib/module/helpers/getDataFromXml.js +6 -1
- package/lib/module/helpers/getDataFromXml.js.map +1 -1
- package/lib/module/helpers/mapWithConcurrency.js +37 -0
- package/lib/module/helpers/mapWithConcurrency.js.map +1 -0
- package/lib/module/helpers/mediaLimits.js +27 -0
- package/lib/module/helpers/mediaLimits.js.map +1 -0
- package/lib/module/helpers/mediaSendRetry.js +55 -0
- package/lib/module/helpers/mediaSendRetry.js.map +1 -0
- package/lib/module/helpers/mediaWireData.js +58 -0
- package/lib/module/helpers/mediaWireData.js.map +1 -0
- package/lib/module/helpers/mentionSpans.js +14 -0
- package/lib/module/helpers/mentionSpans.js.map +1 -0
- package/lib/module/helpers/mimeToExtension.js +43 -0
- package/lib/module/helpers/mimeToExtension.js.map +1 -1
- package/lib/module/helpers/readReceipts.js +160 -0
- package/lib/module/helpers/readReceipts.js.map +1 -0
- package/lib/module/helpers/repairFilenameEncoding.js +74 -0
- package/lib/module/helpers/repairFilenameEncoding.js.map +1 -0
- package/lib/module/helpers/safeJson.js +13 -0
- package/lib/module/helpers/safeJson.js.map +1 -0
- package/lib/module/helpers/updateMessagesTillLast.js +3 -1
- package/lib/module/helpers/updateMessagesTillLast.js.map +1 -1
- package/lib/module/hooks/useSendMessage.js +387 -195
- package/lib/module/hooks/useSendMessage.js.map +1 -1
- package/lib/module/i18n/strings.js +144 -0
- package/lib/module/i18n/strings.js.map +1 -1
- package/lib/module/main.js.map +1 -1
- package/lib/module/networking/api-requests/auth.api.js +62 -3
- package/lib/module/networking/api-requests/auth.api.js.map +1 -1
- package/lib/module/networking/stanzaHandlers.js +97 -4
- package/lib/module/networking/stanzaHandlers.js.map +1 -1
- package/lib/module/networking/xmpp/handleStanzas.xmpp.js +5 -3
- package/lib/module/networking/xmpp/handleStanzas.xmpp.js.map +1 -1
- package/lib/module/networking/xmpp/sendDisplayedMarker.xmpp.js +25 -0
- package/lib/module/networking/xmpp/sendDisplayedMarker.xmpp.js.map +1 -0
- package/lib/module/networking/xmpp/sendMediaMessage.xmpp.js +53 -2
- package/lib/module/networking/xmpp/sendMediaMessage.xmpp.js.map +1 -1
- package/lib/module/networking/xmpp/sendReceivedReceipt.xmpp.js +25 -0
- package/lib/module/networking/xmpp/sendReceivedReceipt.xmpp.js.map +1 -0
- package/lib/module/networking/xmppClient.js +64 -0
- package/lib/module/networking/xmppClient.js.map +1 -1
- package/lib/module/roomStore/persistence.js +78 -5
- package/lib/module/roomStore/persistence.js.map +1 -1
- package/lib/module/roomStore/roomHeapSlice.js +4 -0
- package/lib/module/roomStore/roomHeapSlice.js.map +1 -1
- package/lib/module/roomStore/roomsSlice.js +109 -0
- package/lib/module/roomStore/roomsSlice.js.map +1 -1
- package/lib/module/types/models/attachment.model.js +2 -0
- package/lib/module/types/models/attachment.model.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/assets/icons.d.ts +6 -1
- package/lib/typescript/assets/icons.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/AlbumGrid.d.ts +21 -0
- package/lib/typescript/components/MainComponents/AlbumGrid.d.ts.map +1 -0
- package/lib/typescript/components/MainComponents/ChatRoom.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/MediaMessage.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/MediaUploadOverlay.d.ts +17 -0
- package/lib/typescript/components/MainComponents/MediaUploadOverlay.d.ts.map +1 -0
- package/lib/typescript/components/MessageBubble/MediaCaption.d.ts +12 -0
- package/lib/typescript/components/MessageBubble/MediaCaption.d.ts.map +1 -0
- package/lib/typescript/components/MessageBubble/Message.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble/MessageInteractions.d.ts.map +1 -1
- package/lib/typescript/components/Modals/FilePreviewModal/FilePreviewModal.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/LastMessageItem.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/styled/LastAudioMessage.d.ts +2 -0
- package/lib/typescript/components/RoomComponents/styled/LastAudioMessage.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/styled/LastMessageFile.d.ts +2 -0
- package/lib/typescript/components/RoomComponents/styled/LastMessageFile.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/styled/LastMessagePhoto.d.ts +2 -0
- package/lib/typescript/components/RoomComponents/styled/LastMessagePhoto.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/styled/LastMessageVideo.d.ts +2 -0
- package/lib/typescript/components/RoomComponents/styled/LastMessageVideo.d.ts.map +1 -1
- package/lib/typescript/components/Thread/ThreadWrapper.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/ActiveCallBar.d.ts +9 -3
- package/lib/typescript/components/VideoCalls/ActiveCallBar.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/CallIcons.d.ts +9 -0
- package/lib/typescript/components/VideoCalls/CallIcons.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/VideoCallOverlay.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/VideoCallSession.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/callSessionController.d.ts +7 -0
- package/lib/typescript/components/VideoCalls/callSessionController.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/callUiStore.d.ts +13 -0
- package/lib/typescript/components/VideoCalls/callUiStore.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/livekitRuntime.d.ts +5 -0
- package/lib/typescript/components/VideoCalls/livekitRuntime.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/useCallKeep.d.ts +12 -0
- package/lib/typescript/components/VideoCalls/useCallKeep.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/useOngoingCallNotification.d.ts +10 -0
- package/lib/typescript/components/VideoCalls/useOngoingCallNotification.d.ts.map +1 -0
- package/lib/typescript/components/VideoCalls/usePipTile.d.ts +46 -0
- package/lib/typescript/components/VideoCalls/usePipTile.d.ts.map +1 -0
- package/lib/typescript/components/styled/MediaFilePreview.d.ts.map +1 -1
- package/lib/typescript/components/styled/MessageImage.d.ts +10 -0
- package/lib/typescript/components/styled/MessageImage.d.ts.map +1 -1
- package/lib/typescript/components/styled/SendInput.d.ts +7 -1
- package/lib/typescript/components/styled/SendInput.d.ts.map +1 -1
- package/lib/typescript/components/styled/VideoMessage.d.ts +7 -0
- package/lib/typescript/components/styled/VideoMessage.d.ts.map +1 -1
- package/lib/typescript/context/xmppProvider.d.ts.map +1 -1
- package/lib/typescript/e2ee/fileEnvelope.d.ts +1 -1
- package/lib/typescript/e2ee/fileEnvelope.d.ts.map +1 -1
- package/lib/typescript/e2ee/sealedBody.d.ts +16 -0
- package/lib/typescript/e2ee/sealedBody.d.ts.map +1 -1
- package/lib/typescript/helpers/albumLayout.d.ts +66 -0
- package/lib/typescript/helpers/albumLayout.d.ts.map +1 -0
- package/lib/typescript/helpers/attachments.d.ts +55 -0
- package/lib/typescript/helpers/attachments.d.ts.map +1 -0
- package/lib/typescript/helpers/caption.d.ts +64 -0
- package/lib/typescript/helpers/caption.d.ts.map +1 -0
- package/lib/typescript/helpers/createMainMessageForThread.d.ts.map +1 -1
- package/lib/typescript/helpers/createMessageFromXml.d.ts.map +1 -1
- package/lib/typescript/helpers/fileKind.d.ts +20 -0
- package/lib/typescript/helpers/fileKind.d.ts.map +1 -0
- package/lib/typescript/helpers/getDataFromXml.d.ts.map +1 -1
- package/lib/typescript/helpers/mapWithConcurrency.d.ts +9 -0
- package/lib/typescript/helpers/mapWithConcurrency.d.ts.map +1 -0
- package/lib/typescript/helpers/mediaLimits.d.ts +13 -0
- package/lib/typescript/helpers/mediaLimits.d.ts.map +1 -0
- package/lib/typescript/helpers/mediaSendRetry.d.ts +26 -0
- package/lib/typescript/helpers/mediaSendRetry.d.ts.map +1 -0
- package/lib/typescript/helpers/mediaWireData.d.ts +16 -0
- package/lib/typescript/helpers/mediaWireData.d.ts.map +1 -0
- package/lib/typescript/helpers/mentionSpans.d.ts +8 -0
- package/lib/typescript/helpers/mentionSpans.d.ts.map +1 -0
- package/lib/typescript/helpers/mimeToExtension.d.ts +7 -0
- package/lib/typescript/helpers/mimeToExtension.d.ts.map +1 -1
- package/lib/typescript/helpers/readReceipts.d.ts +82 -0
- package/lib/typescript/helpers/readReceipts.d.ts.map +1 -0
- package/lib/typescript/helpers/repairFilenameEncoding.d.ts +12 -0
- package/lib/typescript/helpers/repairFilenameEncoding.d.ts.map +1 -0
- package/lib/typescript/helpers/safeJson.d.ts +2 -0
- package/lib/typescript/helpers/safeJson.d.ts.map +1 -0
- package/lib/typescript/helpers/updateMessagesTillLast.d.ts.map +1 -1
- package/lib/typescript/hooks/useSendMessage.d.ts +2 -1
- package/lib/typescript/hooks/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/i18n/strings.d.ts.map +1 -1
- package/lib/typescript/main.d.ts +1 -1
- package/lib/typescript/main.d.ts.map +1 -1
- package/lib/typescript/networking/api-requests/auth.api.d.ts +2 -0
- package/lib/typescript/networking/api-requests/auth.api.d.ts.map +1 -1
- package/lib/typescript/networking/stanzaHandlers.d.ts +7 -3
- package/lib/typescript/networking/stanzaHandlers.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/handleStanzas.xmpp.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/sendDisplayedMarker.xmpp.d.ts +3 -0
- package/lib/typescript/networking/xmpp/sendDisplayedMarker.xmpp.d.ts.map +1 -0
- package/lib/typescript/networking/xmpp/sendMediaMessage.xmpp.d.ts +12 -0
- package/lib/typescript/networking/xmpp/sendMediaMessage.xmpp.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/sendReceivedReceipt.xmpp.d.ts +3 -0
- package/lib/typescript/networking/xmpp/sendReceivedReceipt.xmpp.d.ts.map +1 -0
- package/lib/typescript/networking/xmppClient.d.ts +15 -0
- package/lib/typescript/networking/xmppClient.d.ts.map +1 -1
- package/lib/typescript/roomStore/persistence.d.ts.map +1 -1
- package/lib/typescript/roomStore/roomHeapSlice.d.ts +22 -1
- package/lib/typescript/roomStore/roomHeapSlice.d.ts.map +1 -1
- package/lib/typescript/roomStore/roomsSlice.d.ts +67 -3
- package/lib/typescript/roomStore/roomsSlice.d.ts.map +1 -1
- package/lib/typescript/types/models/attachment.model.d.ts +52 -0
- package/lib/typescript/types/models/attachment.model.d.ts.map +1 -0
- package/lib/typescript/types/models/message.model.d.ts +26 -0
- package/lib/typescript/types/models/message.model.d.ts.map +1 -1
- package/lib/typescript/types/models/modal.model.d.ts +7 -0
- package/lib/typescript/types/models/modal.model.d.ts.map +1 -1
- package/lib/typescript/types/models/room.model.d.ts +2 -0
- package/lib/typescript/types/models/room.model.d.ts.map +1 -1
- package/lib/typescript/types/types.d.ts +69 -1
- package/lib/typescript/types/types.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +4 -1
- package/plugins/notification-service/Info.plist +31 -0
- package/plugins/notification-service/NotificationService.swift +82 -0
- package/plugins/withNotificationServiceExtension.js +137 -0
- package/src/assets/icons.tsx +20 -2
- package/src/components/MainComponents/AlbumGrid.tsx +183 -0
- package/src/components/MainComponents/ChatRoom.tsx +4 -2
- package/src/components/MainComponents/MediaMessage.tsx +246 -130
- package/src/components/MainComponents/MediaUploadOverlay.tsx +102 -0
- package/src/components/MessageBubble/MediaCaption.tsx +45 -0
- package/src/components/MessageBubble/Message.tsx +71 -3
- package/src/components/MessageBubble/MessageInteractions.tsx +2 -1
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +64 -0
- package/src/components/RoomComponents/LastMessageItem.tsx +15 -4
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +6 -3
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +6 -2
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +6 -2
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +6 -2
- package/src/components/Thread/ThreadWrapper.tsx +5 -9
- package/src/components/VideoCalls/ActiveCallBar.tsx +56 -10
- package/src/components/VideoCalls/CallIcons.tsx +36 -12
- package/src/components/VideoCalls/VideoCallOverlay.tsx +205 -8
- package/src/components/VideoCalls/VideoCallSession.tsx +45 -13
- package/src/components/VideoCalls/callSessionController.ts +51 -20
- package/src/components/VideoCalls/callUiStore.ts +33 -3
- package/src/components/VideoCalls/livekitRuntime.ts +13 -0
- package/src/components/VideoCalls/useCallKeep.ts +204 -33
- package/src/components/VideoCalls/useOngoingCallNotification.ts +113 -0
- package/src/components/VideoCalls/usePipTile.ts +214 -0
- package/src/components/styled/MediaFilePreview.tsx +49 -34
- package/src/components/styled/MessageImage.tsx +21 -5
- package/src/components/styled/SendInput.tsx +101 -87
- package/src/components/styled/VideoMessage.tsx +34 -9
- package/src/context/xmppProvider.tsx +32 -0
- package/src/e2ee/fileEnvelope.ts +1 -1
- package/src/e2ee/sealedBody.ts +44 -5
- package/src/helpers/albumLayout.ts +207 -0
- package/src/helpers/attachments.ts +316 -0
- package/src/helpers/caption.ts +283 -0
- package/src/helpers/createMainMessageForThread.ts +6 -1
- package/src/helpers/createMessageFromXml.ts +21 -5
- package/src/helpers/fileKind.ts +38 -0
- package/src/helpers/getDataFromXml.ts +5 -1
- package/src/helpers/mapWithConcurrency.ts +32 -0
- package/src/helpers/mediaLimits.ts +27 -0
- package/src/helpers/mediaSendRetry.ts +59 -0
- package/src/helpers/mediaWireData.ts +57 -0
- package/src/helpers/mentionSpans.ts +17 -0
- package/src/helpers/mimeToExtension.ts +51 -0
- package/src/helpers/readReceipts.ts +219 -0
- package/src/helpers/repairFilenameEncoding.ts +82 -0
- package/src/helpers/safeJson.ts +11 -0
- package/src/helpers/updateMessagesTillLast.tsx +2 -1
- package/src/hooks/useSendMessage.tsx +448 -249
- package/src/i18n/strings.ts +144 -0
- package/src/main.ts +3 -0
- package/src/networking/api-requests/auth.api.ts +60 -3
- package/src/networking/stanzaHandlers.ts +91 -2
- package/src/networking/xmpp/handleStanzas.xmpp.ts +6 -2
- package/src/networking/xmpp/sendDisplayedMarker.xmpp.ts +31 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +60 -3
- package/src/networking/xmpp/sendReceivedReceipt.xmpp.ts +31 -0
- package/src/networking/xmppClient.ts +48 -0
- package/src/roomStore/persistence.ts +94 -3
- package/src/roomStore/roomHeapSlice.ts +23 -1
- package/src/roomStore/roomsSlice.ts +112 -1
- package/src/types/models/attachment.model.ts +51 -0
- package/src/types/models/message.model.ts +29 -0
- package/src/types/models/modal.model.ts +7 -0
- package/src/types/models/room.model.ts +2 -0
- package/src/types/types.ts +83 -1
- package/src/version.ts +1 -1
- package/lib/commonjs/components/VideoCalls/useDraggable.js +0 -59
- package/lib/commonjs/components/VideoCalls/useDraggable.js.map +0 -1
- package/lib/module/components/VideoCalls/useDraggable.js +0 -55
- package/lib/module/components/VideoCalls/useDraggable.js.map +0 -1
- package/lib/typescript/components/VideoCalls/useDraggable.d.ts +0 -19
- package/lib/typescript/components/VideoCalls/useDraggable.d.ts.map +0 -1
- package/src/components/VideoCalls/useDraggable.ts +0 -46
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { IAttachment, IMessage } from '../types/types';
|
|
2
|
+
import { safeJsonParse } from './safeJson';
|
|
3
|
+
import { repairFilenameEncoding } from './repairFilenameEncoding';
|
|
4
|
+
import { inferMimeFromName, isGenericMime } from './mimeToExtension';
|
|
5
|
+
|
|
6
|
+
/** Parses a dimension that may arrive as a number or a numeric string. */
|
|
7
|
+
const parseDimension = (value: unknown): number | undefined => {
|
|
8
|
+
const n = typeof value === 'string' ? Number.parseFloat(value) : value;
|
|
9
|
+
return typeof n === 'number' && Number.isFinite(n) && n > 0 ? n : undefined;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Hard ceiling on how many attachments we will serialise into a stanza.
|
|
14
|
+
* The composer caps the picker far below this; this is the parser-side
|
|
15
|
+
* guard so a malformed or hostile stanza cannot make us render an
|
|
16
|
+
* unbounded grid.
|
|
17
|
+
*/
|
|
18
|
+
export const MAX_ATTACHMENTS_PER_MESSAGE = 10;
|
|
19
|
+
|
|
20
|
+
const asOptionalString = (value: unknown): string | undefined => {
|
|
21
|
+
if (value === null || value === undefined) return undefined;
|
|
22
|
+
if (typeof value === 'string') return value || undefined;
|
|
23
|
+
if (typeof value === 'number') return String(value);
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** A file name from the wire/API, with UTF-8-read-as-Latin-1 mojibake undone. */
|
|
28
|
+
const asOptionalFileName = (value: unknown): string | undefined => {
|
|
29
|
+
const name = asOptionalString(value);
|
|
30
|
+
return name === undefined ? undefined : repairFilenameEncoding(name);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const asOptionalBoolean = (value: unknown): boolean | undefined => {
|
|
34
|
+
if (typeof value === 'boolean') return value;
|
|
35
|
+
if (value === 'true') return true;
|
|
36
|
+
if (value === 'false') return false;
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Turns one raw wire/API object into an `IAttachment`, or null when there is
|
|
42
|
+
* nothing renderable in it. `location` is allowed to be empty: that is what
|
|
43
|
+
* an optimistic (still-uploading) attachment looks like.
|
|
44
|
+
*/
|
|
45
|
+
export const normalizeAttachment = (raw: unknown): IAttachment | null => {
|
|
46
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
47
|
+
|
|
48
|
+
const source = raw as Record<string, unknown>;
|
|
49
|
+
const location = asOptionalString(source.location) ?? '';
|
|
50
|
+
const originalName =
|
|
51
|
+
asOptionalFileName(source.originalName) ?? asOptionalFileName(source.originalname);
|
|
52
|
+
const rawMimetype = asOptionalString(source.mimetype);
|
|
53
|
+
const fileName = asOptionalFileName(source.fileName) ?? asOptionalFileName(source.filename);
|
|
54
|
+
const duration =
|
|
55
|
+
asOptionalString(source.duration) ?? asOptionalString(source.mediaDuration);
|
|
56
|
+
const mimetype = resolveLegacyMimetype(rawMimetype, {
|
|
57
|
+
names: [originalName, fileName, urlPath(location)],
|
|
58
|
+
duration,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (!location && !originalName && !mimetype && !fileName) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
attachmentId: asOptionalString(source.attachmentId) ?? asOptionalString(source._id),
|
|
67
|
+
location,
|
|
68
|
+
locationPreview: asOptionalString(source.locationPreview),
|
|
69
|
+
mimetype,
|
|
70
|
+
originalName,
|
|
71
|
+
fileName,
|
|
72
|
+
size: asOptionalString(source.size),
|
|
73
|
+
duration,
|
|
74
|
+
...optionalDimensions(source),
|
|
75
|
+
ownerKey: asOptionalString(source.ownerKey),
|
|
76
|
+
userId: asOptionalString(source.userId),
|
|
77
|
+
createdAt: asOptionalString(source.createdAt),
|
|
78
|
+
updatedAt: asOptionalString(source.updatedAt),
|
|
79
|
+
expiresAt: asOptionalString(source.expiresAt),
|
|
80
|
+
isVisible: asOptionalBoolean(source.isVisible),
|
|
81
|
+
isPrivate: asOptionalBoolean(source.isPrivate),
|
|
82
|
+
...normalizeUploadState(source),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** The path part of a URL (no query or fragment), for reading an extension off it. */
|
|
87
|
+
const urlPath = (url: string): string | undefined =>
|
|
88
|
+
url ? url.split(/[?#]/)[0] : undefined;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Older clients and the storage send media with no `mimetype`, or with the
|
|
92
|
+
* "could not sniff" `application/octet-stream`. The extension of any name the
|
|
93
|
+
* file carries tells which picture, video, audio or PDF it is. A nameless or
|
|
94
|
+
* extensionless file with a duration is a recorded voice note (browsers upload
|
|
95
|
+
* those as a `blob`), which is exactly what octet-stream renders as.
|
|
96
|
+
*/
|
|
97
|
+
const resolveLegacyMimetype = (
|
|
98
|
+
mimetype: string | undefined,
|
|
99
|
+
hints: { names: Array<string | undefined>; duration?: string }
|
|
100
|
+
): string | undefined => {
|
|
101
|
+
if (!isGenericMime(mimetype)) return mimetype;
|
|
102
|
+
const hasDuration = Number.parseFloat(hints.duration ?? '') > 0;
|
|
103
|
+
// A recorded note keeps its generic type: browsers upload it as a nameless
|
|
104
|
+
// `blob` (and storage may add a `.webm` to the stored name, which is audio
|
|
105
|
+
// here, not video). Only a name that says what it is overrides that.
|
|
106
|
+
if (hasDuration && !inferMimeFromName(hints.names[0])) return mimetype ?? 'application/octet-stream';
|
|
107
|
+
for (const name of hints.names) {
|
|
108
|
+
const inferred = inferMimeFromName(name);
|
|
109
|
+
if (inferred) return inferred;
|
|
110
|
+
}
|
|
111
|
+
return mimetype;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Pixel size, only when the source carries a usable one. */
|
|
115
|
+
const optionalDimensions = (
|
|
116
|
+
source: Record<string, unknown>
|
|
117
|
+
): Pick<IAttachment, 'width' | 'height'> => {
|
|
118
|
+
const width = parseDimension(source.width);
|
|
119
|
+
const height = parseDimension(source.height);
|
|
120
|
+
return {
|
|
121
|
+
...(width !== undefined ? { width } : {}),
|
|
122
|
+
...(height !== undefined ? { height } : {}),
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Local upload state rides along on optimistic attachments only; it is
|
|
128
|
+
* never serialised, so a received attachment never carries it.
|
|
129
|
+
*/
|
|
130
|
+
const normalizeUploadState = (
|
|
131
|
+
source: Record<string, unknown>
|
|
132
|
+
): Pick<IAttachment, 'uploadStatus' | 'uploadProgress' | 'localUrl'> => {
|
|
133
|
+
const status = source.uploadStatus === 'uploading' || source.uploadStatus === 'failed'
|
|
134
|
+
? source.uploadStatus
|
|
135
|
+
: undefined;
|
|
136
|
+
if (!status) return {};
|
|
137
|
+
const progress =
|
|
138
|
+
typeof source.uploadProgress === 'number' && Number.isFinite(source.uploadProgress)
|
|
139
|
+
? Math.min(100, Math.max(0, source.uploadProgress))
|
|
140
|
+
: 0;
|
|
141
|
+
// Only a file on this device can be the local preview of an outgoing file.
|
|
142
|
+
const localUrl =
|
|
143
|
+
typeof source.localUrl === 'string' && /^(file|content):\/\//.test(source.localUrl)
|
|
144
|
+
? source.localUrl
|
|
145
|
+
: undefined;
|
|
146
|
+
return {
|
|
147
|
+
uploadStatus: status,
|
|
148
|
+
uploadProgress: progress,
|
|
149
|
+
...(localUrl ? { localUrl } : {}),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/** Accepts the parsed array, the raw JSON string, or junk. Never throws. */
|
|
154
|
+
export const parseAttachments = (raw: unknown): IAttachment[] => {
|
|
155
|
+
const candidate = typeof raw === 'string' ? safeJsonParse<unknown>(raw, []) : raw;
|
|
156
|
+
if (!Array.isArray(candidate)) return [];
|
|
157
|
+
|
|
158
|
+
return candidate
|
|
159
|
+
.slice(0, MAX_ATTACHMENTS_PER_MESSAGE)
|
|
160
|
+
.map(normalizeAttachment)
|
|
161
|
+
.filter((item): item is IAttachment => item !== null);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The wire form: a JSON string on the `<data attachments="...">` attribute.
|
|
166
|
+
* Only the fields a receiver renders are sent - the stanza is already wide
|
|
167
|
+
* and every byte here is duplicated per attachment.
|
|
168
|
+
*/
|
|
169
|
+
export const serializeAttachments = (attachments: IAttachment[]): string =>
|
|
170
|
+
JSON.stringify(
|
|
171
|
+
attachments.slice(0, MAX_ATTACHMENTS_PER_MESSAGE).map((attachment) => ({
|
|
172
|
+
attachmentId: attachment.attachmentId,
|
|
173
|
+
location: attachment.location,
|
|
174
|
+
locationPreview: attachment.locationPreview,
|
|
175
|
+
mimetype: attachment.mimetype,
|
|
176
|
+
originalName: attachment.originalName,
|
|
177
|
+
fileName: attachment.fileName,
|
|
178
|
+
size: attachment.size,
|
|
179
|
+
duration: attachment.duration,
|
|
180
|
+
}))
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The only supported way to read a media message's files.
|
|
185
|
+
*
|
|
186
|
+
* Order of truth: the multi-attach payload when present, otherwise the flat
|
|
187
|
+
* legacy fields synthesised into a single attachment. Every message that
|
|
188
|
+
* predates this feature - and every message from a client that does not
|
|
189
|
+
* speak it - takes the second path.
|
|
190
|
+
*/
|
|
191
|
+
export const getMessageAttachments = (
|
|
192
|
+
message?: Pick<
|
|
193
|
+
IMessage,
|
|
194
|
+
| 'attachments'
|
|
195
|
+
| 'location'
|
|
196
|
+
| 'locationPreview'
|
|
197
|
+
| 'mimetype'
|
|
198
|
+
| 'originalName'
|
|
199
|
+
| 'fileName'
|
|
200
|
+
| 'size'
|
|
201
|
+
> & { duration?: unknown; mediaDuration?: unknown } | null
|
|
202
|
+
): IAttachment[] => {
|
|
203
|
+
if (!message) return [];
|
|
204
|
+
|
|
205
|
+
const parsed = parseAttachments(message.attachments);
|
|
206
|
+
if (parsed.length > 0) return parsed;
|
|
207
|
+
|
|
208
|
+
// Legacy clients may pack several files into the flat fields as a
|
|
209
|
+
// comma separated list of URLs; the other flat fields then list one value
|
|
210
|
+
// each, in the same order, or one value for all.
|
|
211
|
+
const locations = splitUrlList(message.location);
|
|
212
|
+
if (locations.length > 1) {
|
|
213
|
+
const previews = splitUrlList(message.locationPreview);
|
|
214
|
+
const mimetypes = splitList(message.mimetype);
|
|
215
|
+
const names = splitList(message.originalName);
|
|
216
|
+
return locations
|
|
217
|
+
.slice(0, MAX_ATTACHMENTS_PER_MESSAGE)
|
|
218
|
+
.map((location, index) =>
|
|
219
|
+
normalizeAttachment({
|
|
220
|
+
location,
|
|
221
|
+
locationPreview: previews.length === locations.length ? previews[index] : undefined,
|
|
222
|
+
mimetype: pickNth(mimetypes, index, locations.length),
|
|
223
|
+
originalName: pickNth(names, index, locations.length),
|
|
224
|
+
size: undefined,
|
|
225
|
+
})
|
|
226
|
+
)
|
|
227
|
+
.filter((item): item is IAttachment => item !== null);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const legacy = normalizeAttachment({
|
|
231
|
+
location: message.location,
|
|
232
|
+
locationPreview: message.locationPreview,
|
|
233
|
+
mimetype: message.mimetype,
|
|
234
|
+
originalName: message.originalName,
|
|
235
|
+
fileName: message.fileName,
|
|
236
|
+
size: message.size,
|
|
237
|
+
duration: message.duration,
|
|
238
|
+
mediaDuration: message.mediaDuration,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return legacy ? [legacy] : [];
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** "https://a/x.jpg, https://a/y.jpg" -> two URLs. A single URL stays whole, commas and all. */
|
|
245
|
+
const splitUrlList = (value: unknown): string[] =>
|
|
246
|
+
typeof value === 'string' && /,\s*https?:\/\//i.test(value)
|
|
247
|
+
? value.split(/,\s*(?=https?:\/\/)/i).map((item) => item.trim()).filter(Boolean)
|
|
248
|
+
: typeof value === 'string' && value
|
|
249
|
+
? [value]
|
|
250
|
+
: [];
|
|
251
|
+
|
|
252
|
+
const splitList = (value: unknown): string[] =>
|
|
253
|
+
typeof value === 'string' && value ? value.split(',').map((item) => item.trim()) : [];
|
|
254
|
+
|
|
255
|
+
/** The nth entry of a parallel list, or its only entry when it is shared by all. */
|
|
256
|
+
const pickNth = (list: string[], index: number, total: number): string | undefined =>
|
|
257
|
+
list.length === total ? list[index] : list.length === 1 ? list[0] : undefined;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* True when the message carries a file: flagged `isMediafile`, or (older
|
|
261
|
+
* senders that never set the flag) with a real file URL or attachment. The
|
|
262
|
+
* one test every surface uses for "is this a media bubble".
|
|
263
|
+
*/
|
|
264
|
+
export const isMediaMessage = (
|
|
265
|
+
message?:
|
|
266
|
+
| (Partial<Pick<IMessage, 'isDeleted' | 'isMediafile' | 'attachments'>> & {
|
|
267
|
+
location?: unknown;
|
|
268
|
+
mimetype?: unknown;
|
|
269
|
+
originalName?: unknown;
|
|
270
|
+
fileName?: unknown;
|
|
271
|
+
locationPreview?: unknown;
|
|
272
|
+
})
|
|
273
|
+
| null
|
|
274
|
+
): boolean => {
|
|
275
|
+
if (!message || message.isDeleted) return false;
|
|
276
|
+
if (String(message.isMediafile) === 'true') return true;
|
|
277
|
+
return getMessageAttachments(message as never).some(
|
|
278
|
+
(attachment) => Boolean(attachment.location)
|
|
279
|
+
);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Maps one object from POST /files/ `results` to the attachment a sent
|
|
284
|
+
* message carries. Field names here follow the API's own spelling
|
|
285
|
+
* (`originalname`, `filename`), not the wire attribute names.
|
|
286
|
+
*/
|
|
287
|
+
export const toUploadedAttachment = (raw: any): IAttachment => ({
|
|
288
|
+
attachmentId: raw?._id,
|
|
289
|
+
location: raw?.location,
|
|
290
|
+
locationPreview: raw?.locationPreview,
|
|
291
|
+
mimetype: raw?.mimetype,
|
|
292
|
+
originalName:
|
|
293
|
+
typeof raw?.originalname === 'string'
|
|
294
|
+
? repairFilenameEncoding(raw.originalname)
|
|
295
|
+
: raw?.originalname,
|
|
296
|
+
fileName:
|
|
297
|
+
typeof raw?.filename === 'string'
|
|
298
|
+
? repairFilenameEncoding(raw.filename)
|
|
299
|
+
: raw?.filename,
|
|
300
|
+
size: raw?.size?.toString?.() ?? raw?.size,
|
|
301
|
+
duration: raw?.duration,
|
|
302
|
+
ownerKey: raw?.ownerKey,
|
|
303
|
+
userId: raw?.userId,
|
|
304
|
+
createdAt: raw?.createdAt,
|
|
305
|
+
updatedAt: raw?.updatedAt,
|
|
306
|
+
expiresAt: raw?.expiresAt,
|
|
307
|
+
isVisible: raw?.isVisible,
|
|
308
|
+
isPrivate: raw?.isPrivate,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
/** Name to show for an attachment, with the URL tail as the last resort. */
|
|
312
|
+
export const getAttachmentName = (attachment: IAttachment): string =>
|
|
313
|
+
attachment.originalName ||
|
|
314
|
+
attachment.fileName ||
|
|
315
|
+
attachment.location?.split('/')?.pop() ||
|
|
316
|
+
'MediaFile';
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { IMentionSpan } from '../types/types';
|
|
2
|
+
import { safeJsonParse } from './safeJson';
|
|
3
|
+
import { validateMentionSpans } from './mentionSpans';
|
|
4
|
+
import { getAttachmentName, getMessageAttachments, isMediaMessage } from './attachments';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The text typed with a set of attachments, sent as part of the media
|
|
8
|
+
* message itself (never as a separate text stanza).
|
|
9
|
+
*
|
|
10
|
+
* `mentions` index into `text`, the same way a text message's mention spans
|
|
11
|
+
* index into its body.
|
|
12
|
+
*/
|
|
13
|
+
export interface CaptionInput {
|
|
14
|
+
text: string;
|
|
15
|
+
mentions?: IMentionSpan[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface NormalizedCaption {
|
|
19
|
+
caption: string;
|
|
20
|
+
mentions?: IMentionSpan[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const isSpanShape = (value: unknown): value is IMentionSpan => {
|
|
24
|
+
if (!value || typeof value !== 'object') return false;
|
|
25
|
+
const span = value as Record<string, unknown>;
|
|
26
|
+
return (
|
|
27
|
+
typeof span.jid === 'string' &&
|
|
28
|
+
typeof span.name === 'string' &&
|
|
29
|
+
typeof span.offset === 'number' &&
|
|
30
|
+
Number.isInteger(span.offset) &&
|
|
31
|
+
typeof span.length === 'number' &&
|
|
32
|
+
Number.isInteger(span.length)
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Mention spans for a caption, checked against the caption text: a span that
|
|
38
|
+
* no longer reads "@Name" at its offset is dropped. Undefined when nothing is
|
|
39
|
+
* left, so a caption without mentions carries no empty attribute.
|
|
40
|
+
*/
|
|
41
|
+
export const normalizeCaptionMentions = (
|
|
42
|
+
value: unknown,
|
|
43
|
+
caption: string
|
|
44
|
+
): IMentionSpan[] | undefined => {
|
|
45
|
+
const parsed =
|
|
46
|
+
typeof value === 'string' ? safeJsonParse<unknown>(value, []) : value;
|
|
47
|
+
if (!Array.isArray(parsed)) return undefined;
|
|
48
|
+
const spans = validateMentionSpans(caption, parsed.filter(isSpanShape));
|
|
49
|
+
return spans.length > 0 ? spans : undefined;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Turns what the composer typed into the caption that travels with the
|
|
54
|
+
* media. Undefined for blank text, which means "no caption".
|
|
55
|
+
*/
|
|
56
|
+
export const normalizeCaptionInput = (
|
|
57
|
+
input?: CaptionInput | null
|
|
58
|
+
): NormalizedCaption | undefined => {
|
|
59
|
+
const text = typeof input?.text === 'string' ? input.text : '';
|
|
60
|
+
if (!/\S/.test(text)) return undefined;
|
|
61
|
+
const mentions = normalizeCaptionMentions(input?.mentions, text);
|
|
62
|
+
return mentions ? { caption: text, mentions } : { caption: text };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** What a media message's text is, and the @-mention spans that index into it. */
|
|
66
|
+
export interface ResolvedCaption {
|
|
67
|
+
text: string;
|
|
68
|
+
mentions?: IMentionSpan[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CaptionOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The caller already knows this is a media message (a thin `lastMessage`
|
|
74
|
+
* that only says so by its id). Otherwise it is read off the message.
|
|
75
|
+
*/
|
|
76
|
+
isMedia?: boolean;
|
|
77
|
+
/** The message is sealed: only a caption that came out of the envelope counts. */
|
|
78
|
+
sealed?: boolean;
|
|
79
|
+
/** Extra names of the sender, which a body may merely echo. */
|
|
80
|
+
senderNames?: string[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Bodies that are not something a person typed: the media placeholder every
|
|
85
|
+
* SDK sends, and the labels apps generate for a file with nothing to say.
|
|
86
|
+
*/
|
|
87
|
+
const PLACEHOLDER_BODIES = new Set([
|
|
88
|
+
'media',
|
|
89
|
+
'attachment',
|
|
90
|
+
'attachments',
|
|
91
|
+
'photo',
|
|
92
|
+
'photos',
|
|
93
|
+
'image',
|
|
94
|
+
'images',
|
|
95
|
+
'picture',
|
|
96
|
+
'video',
|
|
97
|
+
'audio',
|
|
98
|
+
'voice',
|
|
99
|
+
'voice message',
|
|
100
|
+
'voice note',
|
|
101
|
+
'file',
|
|
102
|
+
'files',
|
|
103
|
+
'document',
|
|
104
|
+
'blob',
|
|
105
|
+
'undefined',
|
|
106
|
+
'null',
|
|
107
|
+
'[object object]',
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
/** `<data>` attributes older or foreign clients stamp the file's text on. */
|
|
111
|
+
const CAPTION_ALIASES = ['captionText', 'text', 'message', 'description', 'title'] as const;
|
|
112
|
+
|
|
113
|
+
const norm = (value: unknown): string =>
|
|
114
|
+
typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
115
|
+
|
|
116
|
+
const str = (value: unknown): string =>
|
|
117
|
+
typeof value === 'string' ? value : typeof value === 'number' ? String(value) : '';
|
|
118
|
+
|
|
119
|
+
const tail = (url: string): string => {
|
|
120
|
+
const path = url.split(/[?#]/)[0];
|
|
121
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const safeDecode = (value: string): string => {
|
|
125
|
+
try {
|
|
126
|
+
return decodeURIComponent(value);
|
|
127
|
+
} catch {
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** Every string a media message's `body` is allowed to merely repeat. */
|
|
133
|
+
const echoCandidates = (
|
|
134
|
+
message: Record<string, any>,
|
|
135
|
+
options: CaptionOptions
|
|
136
|
+
): Set<string> => {
|
|
137
|
+
const out = new Set<string>();
|
|
138
|
+
const add = (value: unknown) => {
|
|
139
|
+
const v = norm(value);
|
|
140
|
+
if (v) out.add(v);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// The file itself: its names and its URLs, as sent and as stored.
|
|
144
|
+
const attachments = getMessageAttachments(message as never);
|
|
145
|
+
for (const attachment of attachments) {
|
|
146
|
+
add(getAttachmentName(attachment));
|
|
147
|
+
add(attachment.originalName);
|
|
148
|
+
add(attachment.fileName);
|
|
149
|
+
for (const url of [attachment.location, attachment.locationPreview]) {
|
|
150
|
+
if (!url) continue;
|
|
151
|
+
add(url);
|
|
152
|
+
add(safeDecode(url));
|
|
153
|
+
add(tail(url));
|
|
154
|
+
add(safeDecode(tail(url)));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
add(message.originalName);
|
|
158
|
+
add(message.fileName);
|
|
159
|
+
add(message.location);
|
|
160
|
+
add(message.locationPreview);
|
|
161
|
+
|
|
162
|
+
// The sender: some clients put their own name, e-mail or username in the
|
|
163
|
+
// body next to the file.
|
|
164
|
+
const user = (message.user ?? {}) as Record<string, unknown>;
|
|
165
|
+
const first = str(message.senderFirstName) || str(message.firstName) || str(user.firstName);
|
|
166
|
+
const last = str(message.senderLastName) || str(message.lastName) || str(user.lastName);
|
|
167
|
+
add(user.name);
|
|
168
|
+
add(`${first} ${last}`);
|
|
169
|
+
add(first && !last ? first : '');
|
|
170
|
+
add(user.email);
|
|
171
|
+
add(user.username);
|
|
172
|
+
add(message.email);
|
|
173
|
+
add(message.userName);
|
|
174
|
+
add(message.username);
|
|
175
|
+
add(message.senderName);
|
|
176
|
+
const idLocal = str(user.id).split('@')[0];
|
|
177
|
+
add(idLocal);
|
|
178
|
+
add(str(user.id).split('_').pop());
|
|
179
|
+
add(str(message.senderJID).split('/')[0].split('@')[0]);
|
|
180
|
+
for (const name of options.senderNames ?? []) add(name);
|
|
181
|
+
return out;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/** "etest etest" is echoed as "etest": every word of the name is the body. */
|
|
185
|
+
const isRepeatedName = (name: string, text: string): boolean =>
|
|
186
|
+
Boolean(name && text) && name.split(/\s+/).every((part) => part === text);
|
|
187
|
+
|
|
188
|
+
const isRealCaptionText = (
|
|
189
|
+
text: string,
|
|
190
|
+
message: Record<string, any>,
|
|
191
|
+
options: CaptionOptions
|
|
192
|
+
): boolean => {
|
|
193
|
+
const t = text.trim();
|
|
194
|
+
if (!t) return false;
|
|
195
|
+
const n = t.toLowerCase();
|
|
196
|
+
if (PLACEHOLDER_BODIES.has(n)) return false;
|
|
197
|
+
// The key envelope a sealed message carries in its body is never text.
|
|
198
|
+
if (/^\{\s*"v"\s*:\s*\d+\s*,\s*"keys"/.test(t)) return false;
|
|
199
|
+
const candidates = echoCandidates(message, options);
|
|
200
|
+
if (candidates.has(n)) return false;
|
|
201
|
+
for (const name of candidates) if (isRepeatedName(name, n)) return false;
|
|
202
|
+
return true;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const asRecord = (message: unknown): Record<string, any> | undefined =>
|
|
206
|
+
message && typeof message === 'object' ? (message as Record<string, any>) : undefined;
|
|
207
|
+
|
|
208
|
+
const resolveSpans = (
|
|
209
|
+
message: Record<string, any>,
|
|
210
|
+
text: string,
|
|
211
|
+
keys: string[]
|
|
212
|
+
): IMentionSpan[] | undefined => {
|
|
213
|
+
for (const key of keys) {
|
|
214
|
+
const spans = normalizeCaptionMentions(message[key] ?? message.data?.[key], text);
|
|
215
|
+
if (spans) return spans;
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The text of a media message, from whichever format carried it. The one
|
|
222
|
+
* place that knows the formats, so every surface (bubble, room list preview,
|
|
223
|
+
* notification, reply quote, copy) agrees:
|
|
224
|
+
*
|
|
225
|
+
* 1. `caption` (+ `captionMentions`): what this SDK sends. The only source
|
|
226
|
+
* for a sealed message, whose caption comes out of the envelope.
|
|
227
|
+
* 2. The caption under another name on `<data>` (`captionText`, `text`,
|
|
228
|
+
* `message`, `description`, `title`) from other clients.
|
|
229
|
+
* 3. A real `body`: older clients and other SDKs put the text in the
|
|
230
|
+
* `<body>` of the media message itself. "media", the file's name or URL,
|
|
231
|
+
* the sender's own name or e-mail and generated labels are not text.
|
|
232
|
+
*
|
|
233
|
+
* Never derived for a sealed message, and never for a message with no file.
|
|
234
|
+
*/
|
|
235
|
+
export const resolveMessageCaption = (
|
|
236
|
+
message?: object | null,
|
|
237
|
+
options: CaptionOptions = {}
|
|
238
|
+
): ResolvedCaption | undefined => {
|
|
239
|
+
const source = asRecord(message);
|
|
240
|
+
if (!source || source.isDeleted) return undefined;
|
|
241
|
+
|
|
242
|
+
const explicit = source.caption;
|
|
243
|
+
if (typeof explicit === 'string' && /\S/.test(explicit)) {
|
|
244
|
+
const mentions = normalizeCaptionMentions(source.captionMentions, explicit);
|
|
245
|
+
return mentions ? { text: explicit, mentions } : { text: explicit };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const sealed =
|
|
249
|
+
options.sealed === true ||
|
|
250
|
+
source.clientEncrypted === 'true' ||
|
|
251
|
+
(Array.isArray(source.e2eeKeys) && source.e2eeKeys.length > 0);
|
|
252
|
+
if (sealed) return undefined;
|
|
253
|
+
|
|
254
|
+
const isMedia = options.isMedia ?? isMediaMessage(source as never);
|
|
255
|
+
if (!isMedia) return undefined;
|
|
256
|
+
|
|
257
|
+
for (const key of CAPTION_ALIASES) {
|
|
258
|
+
const value = str(source[key] ?? source.data?.[key]);
|
|
259
|
+
if (value && isRealCaptionText(value, source, options)) {
|
|
260
|
+
const mentions = resolveSpans(source, value, ['captionMentions']);
|
|
261
|
+
return mentions ? { text: value, mentions } : { text: value };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const body = str(source.body);
|
|
266
|
+
if (body && isRealCaptionText(body, source, options)) {
|
|
267
|
+
const mentions = resolveSpans(source, body, ['mentions']);
|
|
268
|
+
return mentions ? { text: body, mentions } : { text: body };
|
|
269
|
+
}
|
|
270
|
+
return undefined;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/** The caption a message carries, or undefined when it has none. */
|
|
274
|
+
export const getMessageCaption = (
|
|
275
|
+
message?: object | null,
|
|
276
|
+
options?: CaptionOptions
|
|
277
|
+
): string | undefined => resolveMessageCaption(message, options)?.text;
|
|
278
|
+
|
|
279
|
+
/** The mention spans of `getMessageCaption`'s text. */
|
|
280
|
+
export const getMessageCaptionMentions = (
|
|
281
|
+
message?: object | null,
|
|
282
|
+
options?: CaptionOptions
|
|
283
|
+
): IMentionSpan[] | undefined => resolveMessageCaption(message, options)?.mentions;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { IMessage } from '../types/types';
|
|
2
|
+
import { getMessageCaption } from './caption';
|
|
2
3
|
|
|
3
4
|
export const createMainMessageForThread = (message: IMessage): string => {
|
|
5
|
+
// A media message is quoted by its caption. A sealed one never is: the
|
|
6
|
+
// reply stanza travels in the clear, the caption does not.
|
|
7
|
+
const caption =
|
|
8
|
+
message.clientEncrypted === 'true' ? undefined : getMessageCaption(message);
|
|
4
9
|
const data = {
|
|
5
|
-
text: message.body,
|
|
10
|
+
text: caption ?? message.body,
|
|
6
11
|
id: message.id,
|
|
7
12
|
userName: message.user.name,
|
|
8
13
|
createdAt: message.date,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IMessage } from '../types/types';
|
|
2
2
|
import { isE2eeRoom } from '../e2ee';
|
|
3
3
|
import { composeName } from './displayName';
|
|
4
|
-
import {
|
|
4
|
+
import { parseSealedMediaPayload } from '../e2ee/sealedBody';
|
|
5
|
+
import { normalizeMediaDataAttrs } from './mediaWireData';
|
|
5
6
|
|
|
6
7
|
interface IMessageWithNewData extends IMessage {
|
|
7
8
|
[x: string]: any;
|
|
@@ -66,7 +67,9 @@ export const createMessageFromXml = async (
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
const merged: any = {
|
|
69
|
-
|
|
70
|
+
// Idempotent: the wrapped path already ran it in getDataFromXml, the
|
|
71
|
+
// positional (MAM catch-up) path hands over the raw attrs.
|
|
72
|
+
...normalizeMediaDataAttrs(inner),
|
|
70
73
|
...outerExtras,
|
|
71
74
|
isDeleted: !!outerExtras?.deleted || !!(arg as any)?.isDeleted,
|
|
72
75
|
};
|
|
@@ -140,15 +143,28 @@ export const createMessageFromXml = async (
|
|
|
140
143
|
const unencrypted =
|
|
141
144
|
merged.omemoEncrypted !== 'true' && isE2eeRoom(String(merged.roomJid || ''));
|
|
142
145
|
|
|
143
|
-
|
|
146
|
+
// A sealed media body is `{v:1,keys,caption?,captionMentions?}`. The keys
|
|
147
|
+
// and the caption are lifted next to each other; the caption is the only
|
|
148
|
+
// one a sealed message may show (any open caption attribute was dropped
|
|
149
|
+
// by normalizeMediaDataAttrs).
|
|
150
|
+
const sealed =
|
|
144
151
|
merged.clientEncrypted === 'true'
|
|
145
|
-
?
|
|
152
|
+
? parseSealedMediaPayload(merged.body)
|
|
146
153
|
: undefined;
|
|
147
154
|
|
|
148
155
|
const message: IMessage = {
|
|
149
156
|
...merged,
|
|
150
157
|
...(unencrypted ? { unencrypted: true } : {}),
|
|
151
|
-
...(
|
|
158
|
+
...(sealed
|
|
159
|
+
? {
|
|
160
|
+
e2eeKeys: sealed.keys,
|
|
161
|
+
body: 'media',
|
|
162
|
+
...(sealed.caption ? { caption: sealed.caption } : {}),
|
|
163
|
+
...(sealed.captionMentions
|
|
164
|
+
? { captionMentions: sealed.captionMentions }
|
|
165
|
+
: {}),
|
|
166
|
+
}
|
|
167
|
+
: {}),
|
|
152
168
|
user: {
|
|
153
169
|
...(merged.user || {}),
|
|
154
170
|
id: merged?.user?.id || fromResource || senderLocal,
|