@yui-bails/yui-bails 0.0.0-stage → 1.1.0
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 +22 -0
- package/README.md +1837 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +139 -0
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +1198 -0
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +322 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +111 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1772 -0
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1159 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/session-manager.d.ts +408 -0
- package/lib/Socket/session-manager.d.ts.map +1 -0
- package/lib/Socket/session-manager.js +177 -0
- package/lib/Socket/session-manager.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +1039 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +274 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +402 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +188 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -0
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/automation.d.ts +34 -0
- package/lib/Utils/automation.d.ts.map +1 -0
- package/lib/Utils/automation.js +44 -0
- package/lib/Utils/automation.js.map +1 -0
- package/lib/Utils/banner.d.ts +28 -0
- package/lib/Utils/banner.d.ts.map +1 -0
- package/lib/Utils/banner.js +99 -0
- package/lib/Utils/banner.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/button-builder.d.ts +10 -0
- package/lib/Utils/button-builder.d.ts.map +1 -0
- package/lib/Utils/button-builder.js +48 -0
- package/lib/Utils/button-builder.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/console-filter.d.ts +10 -0
- package/lib/Utils/console-filter.d.ts.map +1 -0
- package/lib/Utils/console-filter.js +44 -0
- package/lib/Utils/console-filter.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +395 -0
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/group-cache.d.ts +22 -0
- package/lib/Utils/group-cache.d.ts.map +1 -0
- package/lib/Utils/group-cache.js +31 -0
- package/lib/Utils/group-cache.js.map +1 -0
- package/lib/Utils/group-fetch.d.ts +19 -0
- package/lib/Utils/group-fetch.d.ts.map +1 -0
- package/lib/Utils/group-fetch.js +43 -0
- package/lib/Utils/group-fetch.js.map +1 -0
- package/lib/Utils/group-tools.d.ts +38 -0
- package/lib/Utils/group-tools.d.ts.map +1 -0
- package/lib/Utils/group-tools.js +75 -0
- package/lib/Utils/group-tools.js.map +1 -0
- package/lib/Utils/helpers.d.ts +180 -0
- package/lib/Utils/helpers.d.ts.map +1 -0
- package/lib/Utils/helpers.js +279 -0
- package/lib/Utils/helpers.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +35 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +35 -0
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/insights.d.ts +80 -0
- package/lib/Utils/insights.d.ts.map +1 -0
- package/lib/Utils/insights.js +188 -0
- package/lib/Utils/insights.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/mentions.d.ts +11 -0
- package/lib/Utils/mentions.d.ts.map +1 -0
- package/lib/Utils/mentions.js +29 -0
- package/lib/Utils/mentions.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/message-store.d.ts +19 -0
- package/lib/Utils/message-store.d.ts.map +1 -0
- package/lib/Utils/message-store.js +26 -0
- package/lib/Utils/message-store.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +788 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +95 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1094 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/pretty-log.d.ts +33 -0
- package/lib/Utils/pretty-log.d.ts.map +1 -0
- package/lib/Utils/pretty-log.js +117 -0
- package/lib/Utils/pretty-log.js.map +1 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/replies.d.ts +60 -0
- package/lib/Utils/replies.d.ts.map +1 -0
- package/lib/Utils/replies.js +154 -0
- package/lib/Utils/replies.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/send-queue.d.ts +50 -0
- package/lib/Utils/send-queue.d.ts.map +1 -0
- package/lib/Utils/send-queue.js +124 -0
- package/lib/Utils/send-queue.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +164 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +154 -0
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/Utils/wa-version.d.ts +33 -0
- package/lib/Utils/wa-version.d.ts.map +1 -0
- package/lib/Utils/wa-version.js +92 -0
- package/lib/Utils/wa-version.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +213 -0
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/package.json +150 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { prepareWAMessageMedia } from './messages.js';
|
|
2
|
+
import { extractImageThumb, getHttpStream } from './messages-media.js';
|
|
3
|
+
const THUMBNAIL_WIDTH_PX = 192;
|
|
4
|
+
/** Fetches an image and generates a thumbnail for it */
|
|
5
|
+
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
6
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
7
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
12
|
+
* Return undefined if the fetch failed or no URL was found
|
|
13
|
+
* @param text first matched URL in text
|
|
14
|
+
* @returns the URL info required to generate link preview
|
|
15
|
+
*/
|
|
16
|
+
export const getUrlInfo = async (text, opts = {
|
|
17
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
18
|
+
fetchOpts: { timeout: 3000 }
|
|
19
|
+
}) => {
|
|
20
|
+
try {
|
|
21
|
+
// retries
|
|
22
|
+
let retries = 0;
|
|
23
|
+
const maxRetry = 5;
|
|
24
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
25
|
+
let previewLink = text;
|
|
26
|
+
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
27
|
+
previewLink = 'https://' + previewLink;
|
|
28
|
+
}
|
|
29
|
+
const info = await getLinkPreview(previewLink, {
|
|
30
|
+
...opts.fetchOpts,
|
|
31
|
+
followRedirects: 'follow',
|
|
32
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
33
|
+
const urlObj = new URL(baseURL);
|
|
34
|
+
const forwardedURLObj = new URL(forwardedURL);
|
|
35
|
+
if (retries >= maxRetry) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (forwardedURLObj.hostname === urlObj.hostname ||
|
|
39
|
+
forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
|
|
40
|
+
'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
41
|
+
retries += 1;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
headers: opts.fetchOpts?.headers
|
|
49
|
+
});
|
|
50
|
+
if (info && 'title' in info && info.title) {
|
|
51
|
+
const [image] = info.images;
|
|
52
|
+
const urlInfo = {
|
|
53
|
+
'canonical-url': info.url,
|
|
54
|
+
'matched-text': text,
|
|
55
|
+
title: info.title,
|
|
56
|
+
description: info.description,
|
|
57
|
+
originalThumbnailUrl: image
|
|
58
|
+
};
|
|
59
|
+
if (opts.uploadImage) {
|
|
60
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
|
|
61
|
+
upload: opts.uploadImage,
|
|
62
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
63
|
+
options: opts.fetchOpts
|
|
64
|
+
});
|
|
65
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
66
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
try {
|
|
70
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return urlInfo;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (!error.message.includes('receive a valid')) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=link-preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-preview.js","sourceRoot":"","sources":["../../src/Utils/link-preview.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEnE,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAE9B,wDAAwD;AACxD,MAAM,0BAA0B,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE,cAAc,EAAE,SAAS,EAAwB,EAAE,EAAE;IAC7G,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IAClD,MAAM,MAAM,G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C,OAAO,KAAU,EAAE,CAAC;oBACrB,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,+BAA+B,CAAC,CAAA;gBAC5F,CAAC;YACF,CAAC;YAED,OAAO,OAAO,CAAA;QACf,CAAC;IACF,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAChD,MAAM,KAAK,CAAA;QACZ,CAAC;IACF,CAAC;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import P from 'pino';
|
|
2
|
+
export interface ILogger {
|
|
3
|
+
level: string;
|
|
4
|
+
child(obj: Record<string, unknown>): ILogger;
|
|
5
|
+
trace(obj: unknown, msg?: string): void;
|
|
6
|
+
debug(obj: unknown, msg?: string): void;
|
|
7
|
+
info(obj: unknown, msg?: string): void;
|
|
8
|
+
warn(obj: unknown, msg?: string): void;
|
|
9
|
+
error(obj: unknown, msg?: string): void;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: P.Logger<never, boolean>;
|
|
12
|
+
export default _default;
|
|
13
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/Utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,MAAM,CAAA;AAEpB,MAAM,WAAW,OAAO;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAA;IAC5C,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC;;AAKD,wBAGE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import P from 'pino';
|
|
2
|
+
// silent by default: pino serializes every log call to JSON, which burns CPU
|
|
3
|
+
// and floods hosting panels on busy bots. Set YUI_BAILS_LOG_LEVEL (e.g. 'info',
|
|
4
|
+
// 'debug') or pass your own `logger` in the socket config to see logs again.
|
|
5
|
+
export default P({
|
|
6
|
+
timestamp: () => `,"time":"${new Date().toJSON()}"`,
|
|
7
|
+
level: process.env.YUI_BAILS_LOG_LEVEL || 'silent'
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/Utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,MAAM,CAAA;AAYpB,6EAA6E;AAC7E,gFAAgF;AAChF,6EAA6E;AAC7E,eAAe,CAAC,CAAC;IAChB,SAAS,EAAE,GAAG,EAAE,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG;IACnD,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,QAAQ;CAClD,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
|
|
2
|
+
/**
|
|
3
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
4
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
5
|
+
* if the same series of mutations was made sequentially.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
|
|
8
|
+
//# sourceMappingURL=lt-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lt-hash.d.ts","sourceRoot":"","sources":["../../src/Utils/lt-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,qBAA4B,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
|
|
2
|
+
/**
|
|
3
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
4
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
5
|
+
* if the same series of mutations was made sequentially.
|
|
6
|
+
*/
|
|
7
|
+
export const LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
|
|
8
|
+
//# sourceMappingURL=lt-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lt-hash.js","sourceRoot":"","sources":["../../src/Utils/lt-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const makeMutex: () => {
|
|
2
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
3
|
+
};
|
|
4
|
+
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
|
+
export declare const makeKeyedMutex: () => {
|
|
6
|
+
mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
export type KeyedMutex = ReturnType<typeof makeKeyedMutex>;
|
|
9
|
+
//# sourceMappingURL=make-mutex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-mutex.d.ts","sourceRoot":"","sources":["../../src/Utils/make-mutex.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS;UAId,CAAC,QAAQ,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAIjD,CAAA;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAA;AAEhD,eAAO,MAAM,cAAc;UAIb,CAAC,OAAO,MAAM,QAAQ,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAqBpE,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Mutex as AsyncMutex } from 'async-mutex';
|
|
2
|
+
export const makeMutex = () => {
|
|
3
|
+
const mutex = new AsyncMutex();
|
|
4
|
+
return {
|
|
5
|
+
mutex(code) {
|
|
6
|
+
return mutex.runExclusive(code);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export const makeKeyedMutex = () => {
|
|
11
|
+
const map = new Map();
|
|
12
|
+
return {
|
|
13
|
+
async mutex(key, task) {
|
|
14
|
+
let entry = map.get(key);
|
|
15
|
+
if (!entry) {
|
|
16
|
+
entry = { mutex: new AsyncMutex(), refCount: 0 };
|
|
17
|
+
map.set(key, entry);
|
|
18
|
+
}
|
|
19
|
+
entry.refCount++;
|
|
20
|
+
try {
|
|
21
|
+
return await entry.mutex.runExclusive(task);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
entry.refCount--;
|
|
25
|
+
// only delete it if this is still the current entry
|
|
26
|
+
if (entry.refCount === 0 && map.get(key) === entry) {
|
|
27
|
+
map.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=make-mutex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-mutex.js","sourceRoot":"","sources":["../../src/Utils/make-mutex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC7B,MAAM,KAAK,GAAG,IAAI,UAAU,EAAE,CAAA;IAE9B,OAAO;QACN,KAAK,CAAI,IAA0B;YAClC,OAAO,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;KACD,CAAA;AACF,CAAC,CAAA;AAID,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IAClC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmD,CAAA;IAEtE,OAAO;QACN,KAAK,CAAC,KAAK,CAAI,GAAW,EAAE,IAA0B;YACrD,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAExB,IAAI,CAAC,KAAK,EAAE,CAAC;gBACZ,KAAK,GAAG,EAAE,KAAK,EAAE,IAAI,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAA;gBAChD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACpB,CAAC;YAED,KAAK,CAAC,QAAQ,EAAE,CAAA;YAEhB,IAAI,CAAC;gBACJ,OAAO,MAAM,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;YAC5C,CAAC;oBAAS,CAAC;gBACV,KAAK,CAAC,QAAQ,EAAE,CAAA;gBAChB,oDAAoD;gBACpD,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;oBACpD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBAChB,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds `@5191…` style mentions in a text and returns their jids.
|
|
3
|
+
* Only digits count; `@name` is left alone.
|
|
4
|
+
*/
|
|
5
|
+
export declare const parseMentions: (text: string | null | undefined) => string[];
|
|
6
|
+
/**
|
|
7
|
+
* Adds `mentions` to a message that writes `@number` in its text or caption, unless the
|
|
8
|
+
* message already sets `mentions` itself. Anything else is returned untouched.
|
|
9
|
+
*/
|
|
10
|
+
export declare const withAutoMentions: <T>(content: T) => T;
|
|
11
|
+
//# sourceMappingURL=mentions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../../src/Utils/mentions.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,MAAM,EAOrE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,SAAS,CAAC,KAAG,CAUhD,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** the number must not be glued to a word or another @ (so e-mails are not mentions) */
|
|
2
|
+
const MENTION = /(?<![\w@])@(\d{7,15})(?!\d)/g;
|
|
3
|
+
/**
|
|
4
|
+
* Finds `@5191…` style mentions in a text and returns their jids.
|
|
5
|
+
* Only digits count; `@name` is left alone.
|
|
6
|
+
*/
|
|
7
|
+
export const parseMentions = (text) => {
|
|
8
|
+
if (!text)
|
|
9
|
+
return [];
|
|
10
|
+
const jids = new Set();
|
|
11
|
+
for (const match of text.matchAll(MENTION))
|
|
12
|
+
jids.add(`${match[1]}@s.whatsapp.net`);
|
|
13
|
+
return [...jids];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Adds `mentions` to a message that writes `@number` in its text or caption, unless the
|
|
17
|
+
* message already sets `mentions` itself. Anything else is returned untouched.
|
|
18
|
+
*/
|
|
19
|
+
export const withAutoMentions = (content) => {
|
|
20
|
+
if (!content || typeof content !== 'object')
|
|
21
|
+
return content;
|
|
22
|
+
const message = content;
|
|
23
|
+
if (message.mentions !== undefined)
|
|
24
|
+
return content;
|
|
25
|
+
const text = typeof message.text === 'string' ? message.text : message.caption;
|
|
26
|
+
const jids = typeof text === 'string' ? parseMentions(text) : [];
|
|
27
|
+
return jids.length ? { ...message, mentions: jids } : content;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=mentions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.js","sourceRoot":"","sources":["../../src/Utils/mentions.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,OAAO,GAAG,8BAA8B,CAAA;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAA+B,EAAY,EAAE;IAC1E,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IAEpB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;IAElF,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;AACjB,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAI,OAAU,EAAK,EAAE;IACpD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAA;IAE3D,MAAM,OAAO,GAAG,OAAkC,CAAA;IAClD,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS;QAAE,OAAO,OAAO,CAAA;IAElD,MAAM,IAAI,GAAG,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAA;IAC9E,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEhE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAQ,CAAC,CAAC,CAAC,OAAO,CAAA;AACrE,CAAC,CAAA"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { ILogger } from './logger.js';
|
|
3
|
+
export interface RecentMessageKey {
|
|
4
|
+
to: string;
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export interface RecentMessage {
|
|
8
|
+
message: proto.IMessage;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SessionRecreateHistory {
|
|
12
|
+
[jid: string]: number;
|
|
13
|
+
}
|
|
14
|
+
export interface RetryCounter {
|
|
15
|
+
[messageId: string]: number;
|
|
16
|
+
}
|
|
17
|
+
export type PendingPhoneRequest = Record<string, ReturnType<typeof setTimeout>>;
|
|
18
|
+
export interface RetryStatistics {
|
|
19
|
+
totalRetries: number;
|
|
20
|
+
successfulRetries: number;
|
|
21
|
+
failedRetries: number;
|
|
22
|
+
mediaRetries: number;
|
|
23
|
+
sessionRecreations: number;
|
|
24
|
+
phoneRequests: number;
|
|
25
|
+
}
|
|
26
|
+
export declare enum RetryReason {
|
|
27
|
+
UnknownError = 0,
|
|
28
|
+
SignalErrorNoSession = 1,
|
|
29
|
+
SignalErrorInvalidKey = 2,
|
|
30
|
+
SignalErrorInvalidKeyId = 3,
|
|
31
|
+
/** MAC verification failed - most common cause of decryption failures */
|
|
32
|
+
SignalErrorInvalidMessage = 4,
|
|
33
|
+
SignalErrorInvalidSignature = 5,
|
|
34
|
+
SignalErrorFutureMessage = 6,
|
|
35
|
+
/** Explicit MAC failure - session is definitely out of sync */
|
|
36
|
+
SignalErrorBadMac = 7,
|
|
37
|
+
SignalErrorInvalidSession = 8,
|
|
38
|
+
SignalErrorInvalidMsgKey = 9,
|
|
39
|
+
BadBroadcastEphemeralSetting = 10,
|
|
40
|
+
UnknownCompanionNoPrekey = 11,
|
|
41
|
+
AdvFailure = 12,
|
|
42
|
+
StatusRevokeDelay = 13
|
|
43
|
+
}
|
|
44
|
+
export declare class MessageRetryManager {
|
|
45
|
+
private logger;
|
|
46
|
+
private recentMessagesMap;
|
|
47
|
+
private messageKeyIndex;
|
|
48
|
+
private sessionRecreateHistory;
|
|
49
|
+
private retryCounters;
|
|
50
|
+
private baseKeys;
|
|
51
|
+
private pendingPhoneRequests;
|
|
52
|
+
private readonly maxMsgRetryCount;
|
|
53
|
+
private statistics;
|
|
54
|
+
constructor(logger: ILogger, maxMsgRetryCount: number);
|
|
55
|
+
/**
|
|
56
|
+
* Add a recent message to the cache for retry handling
|
|
57
|
+
*/
|
|
58
|
+
addRecentMessage(to: string, id: string, message: proto.IMessage): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get a recent message from the cache
|
|
61
|
+
*/
|
|
62
|
+
getRecentMessage(to: string, id: string): RecentMessage | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a session should be recreated based on retry count, history, and error code.
|
|
65
|
+
* MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
|
|
66
|
+
*/
|
|
67
|
+
shouldRecreateSession(jid: string, hasSession: boolean, errorCode?: RetryReason): {
|
|
68
|
+
reason: string;
|
|
69
|
+
recreate: boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Parse error code from retry receipt's retry node.
|
|
73
|
+
* Returns undefined if no error code is present.
|
|
74
|
+
*/
|
|
75
|
+
parseRetryErrorCode(errorAttr: string | undefined): RetryReason | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Check if an error code indicates a MAC failure
|
|
78
|
+
*/
|
|
79
|
+
isMacError(errorCode: RetryReason | undefined): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Increment retry counter for a message
|
|
82
|
+
*/
|
|
83
|
+
incrementRetryCount(messageId: string): number;
|
|
84
|
+
/**
|
|
85
|
+
* Get retry count for a message
|
|
86
|
+
*/
|
|
87
|
+
getRetryCount(messageId: string): number;
|
|
88
|
+
/**
|
|
89
|
+
* Check if message has exceeded maximum retry attempts
|
|
90
|
+
*/
|
|
91
|
+
hasExceededMaxRetries(messageId: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Mark retry as successful
|
|
94
|
+
*/
|
|
95
|
+
markRetrySuccess(messageId: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Mark retry as failed
|
|
98
|
+
*/
|
|
99
|
+
markRetryFailed(messageId: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Schedule a phone request with delay
|
|
102
|
+
*/
|
|
103
|
+
schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Cancel pending phone request
|
|
106
|
+
*/
|
|
107
|
+
cancelPendingPhoneRequest(messageId: string): void;
|
|
108
|
+
clear(): void;
|
|
109
|
+
saveBaseKey(addr: string, msgId: string, baseKey: Uint8Array): void;
|
|
110
|
+
hasSameBaseKey(addr: string, msgId: string, baseKey: Uint8Array): boolean;
|
|
111
|
+
deleteBaseKey(addr: string, msgId: string): void;
|
|
112
|
+
private keyToString;
|
|
113
|
+
private removeRecentMessage;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=message-retry-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-retry-manager.d.ts","sourceRoot":"","sources":["../../src/Utils/message-retry-manager.ts"],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,IAAI,EAAE,KAAK,GAAE,MAA4B,GAAG,IAAI;IAaxG;;OAEG;IACH,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IASlD,KAAK,IAAI,IAAI;IAoBb,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI;IAInE,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO;IAazE,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIhD,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,mBAAmB;CAS3B"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { LRUCache } from 'lru-cache';
|
|
2
|
+
/** Number of sent messages to cache in memory for handling retry receipts */
|
|
3
|
+
const RECENT_MESSAGES_SIZE = 512;
|
|
4
|
+
const MESSAGE_KEY_SEPARATOR = '\u0000';
|
|
5
|
+
/** Timeout for session recreation - 1 hour */
|
|
6
|
+
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
|
|
7
|
+
const PHONE_REQUEST_DELAY = 3000;
|
|
8
|
+
// Retry reason codes matching WhatsApp Web's Signal error codes.
|
|
9
|
+
export var RetryReason;
|
|
10
|
+
(function (RetryReason) {
|
|
11
|
+
RetryReason[RetryReason["UnknownError"] = 0] = "UnknownError";
|
|
12
|
+
RetryReason[RetryReason["SignalErrorNoSession"] = 1] = "SignalErrorNoSession";
|
|
13
|
+
RetryReason[RetryReason["SignalErrorInvalidKey"] = 2] = "SignalErrorInvalidKey";
|
|
14
|
+
RetryReason[RetryReason["SignalErrorInvalidKeyId"] = 3] = "SignalErrorInvalidKeyId";
|
|
15
|
+
/** MAC verification failed - most common cause of decryption failures */
|
|
16
|
+
RetryReason[RetryReason["SignalErrorInvalidMessage"] = 4] = "SignalErrorInvalidMessage";
|
|
17
|
+
RetryReason[RetryReason["SignalErrorInvalidSignature"] = 5] = "SignalErrorInvalidSignature";
|
|
18
|
+
RetryReason[RetryReason["SignalErrorFutureMessage"] = 6] = "SignalErrorFutureMessage";
|
|
19
|
+
/** Explicit MAC failure - session is definitely out of sync */
|
|
20
|
+
RetryReason[RetryReason["SignalErrorBadMac"] = 7] = "SignalErrorBadMac";
|
|
21
|
+
RetryReason[RetryReason["SignalErrorInvalidSession"] = 8] = "SignalErrorInvalidSession";
|
|
22
|
+
RetryReason[RetryReason["SignalErrorInvalidMsgKey"] = 9] = "SignalErrorInvalidMsgKey";
|
|
23
|
+
RetryReason[RetryReason["BadBroadcastEphemeralSetting"] = 10] = "BadBroadcastEphemeralSetting";
|
|
24
|
+
RetryReason[RetryReason["UnknownCompanionNoPrekey"] = 11] = "UnknownCompanionNoPrekey";
|
|
25
|
+
RetryReason[RetryReason["AdvFailure"] = 12] = "AdvFailure";
|
|
26
|
+
RetryReason[RetryReason["StatusRevokeDelay"] = 13] = "StatusRevokeDelay";
|
|
27
|
+
})(RetryReason || (RetryReason = {}));
|
|
28
|
+
/** Error codes that indicate a MAC failure and require immediate session recreation */
|
|
29
|
+
const MAC_ERROR_CODES = new Set([RetryReason.SignalErrorInvalidMessage, RetryReason.SignalErrorBadMac]);
|
|
30
|
+
export class MessageRetryManager {
|
|
31
|
+
constructor(logger, maxMsgRetryCount) {
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
this.recentMessagesMap = new LRUCache({
|
|
34
|
+
max: RECENT_MESSAGES_SIZE,
|
|
35
|
+
ttl: 5 * 60 * 1000,
|
|
36
|
+
ttlAutopurge: true,
|
|
37
|
+
dispose: (_value, key) => {
|
|
38
|
+
const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR);
|
|
39
|
+
if (separatorIndex > -1) {
|
|
40
|
+
const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length);
|
|
41
|
+
this.messageKeyIndex.delete(messageId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.messageKeyIndex = new Map();
|
|
46
|
+
this.sessionRecreateHistory = new LRUCache({
|
|
47
|
+
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
48
|
+
ttlAutopurge: true
|
|
49
|
+
});
|
|
50
|
+
this.retryCounters = new LRUCache({
|
|
51
|
+
ttl: 15 * 60 * 1000,
|
|
52
|
+
ttlAutopurge: true,
|
|
53
|
+
updateAgeOnGet: true
|
|
54
|
+
}); // 15 minutes TTL
|
|
55
|
+
this.baseKeys = new LRUCache({
|
|
56
|
+
max: 1024,
|
|
57
|
+
ttl: 15 * 60 * 1000,
|
|
58
|
+
ttlAutopurge: true
|
|
59
|
+
});
|
|
60
|
+
this.pendingPhoneRequests = {};
|
|
61
|
+
this.maxMsgRetryCount = 5;
|
|
62
|
+
this.statistics = {
|
|
63
|
+
totalRetries: 0,
|
|
64
|
+
successfulRetries: 0,
|
|
65
|
+
failedRetries: 0,
|
|
66
|
+
mediaRetries: 0,
|
|
67
|
+
sessionRecreations: 0,
|
|
68
|
+
phoneRequests: 0
|
|
69
|
+
};
|
|
70
|
+
this.maxMsgRetryCount = maxMsgRetryCount;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Add a recent message to the cache for retry handling
|
|
74
|
+
*/
|
|
75
|
+
addRecentMessage(to, id, message) {
|
|
76
|
+
const key = { to, id };
|
|
77
|
+
const keyStr = this.keyToString(key);
|
|
78
|
+
// Add new message
|
|
79
|
+
this.recentMessagesMap.set(keyStr, {
|
|
80
|
+
message,
|
|
81
|
+
timestamp: Date.now()
|
|
82
|
+
});
|
|
83
|
+
this.messageKeyIndex.set(id, keyStr);
|
|
84
|
+
this.logger.debug(`Added message to retry cache: ${to}/${id}`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get a recent message from the cache
|
|
88
|
+
*/
|
|
89
|
+
getRecentMessage(to, id) {
|
|
90
|
+
const key = { to, id };
|
|
91
|
+
const keyStr = this.keyToString(key);
|
|
92
|
+
return this.recentMessagesMap.get(keyStr);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if a session should be recreated based on retry count, history, and error code.
|
|
96
|
+
* MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
|
|
97
|
+
*/
|
|
98
|
+
shouldRecreateSession(jid, hasSession, errorCode) {
|
|
99
|
+
// If we don't have a session, always recreate
|
|
100
|
+
if (!hasSession) {
|
|
101
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
102
|
+
this.statistics.sessionRecreations++;
|
|
103
|
+
return {
|
|
104
|
+
reason: "we don't have a Signal session with them",
|
|
105
|
+
recreate: true
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// IMMEDIATE recreation for MAC errors - session is definitely out of sync
|
|
109
|
+
if (errorCode !== undefined && MAC_ERROR_CODES.has(errorCode)) {
|
|
110
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
111
|
+
this.statistics.sessionRecreations++;
|
|
112
|
+
this.logger.warn({ jid, errorCode: RetryReason[errorCode] }, 'MAC error detected, forcing immediate session recreation');
|
|
113
|
+
return {
|
|
114
|
+
reason: `MAC error (code ${errorCode}: ${RetryReason[errorCode]}), immediate session recreation`,
|
|
115
|
+
recreate: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
const prevTime = this.sessionRecreateHistory.get(jid);
|
|
120
|
+
// If no previous recreation or it's been more than an hour
|
|
121
|
+
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
122
|
+
this.sessionRecreateHistory.set(jid, now);
|
|
123
|
+
this.statistics.sessionRecreations++;
|
|
124
|
+
return {
|
|
125
|
+
reason: 'retry count > 1 and over an hour since last recreation',
|
|
126
|
+
recreate: true
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return { reason: '', recreate: false };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse error code from retry receipt's retry node.
|
|
133
|
+
* Returns undefined if no error code is present.
|
|
134
|
+
*/
|
|
135
|
+
parseRetryErrorCode(errorAttr) {
|
|
136
|
+
if (errorAttr === undefined || errorAttr === '') {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const code = parseInt(errorAttr, 10);
|
|
140
|
+
if (Number.isNaN(code)) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
// Validate it's a known RetryReason
|
|
144
|
+
if (code >= RetryReason.UnknownError && code <= RetryReason.StatusRevokeDelay) {
|
|
145
|
+
return code;
|
|
146
|
+
}
|
|
147
|
+
return RetryReason.UnknownError;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Check if an error code indicates a MAC failure
|
|
151
|
+
*/
|
|
152
|
+
isMacError(errorCode) {
|
|
153
|
+
return errorCode !== undefined && MAC_ERROR_CODES.has(errorCode);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Increment retry counter for a message
|
|
157
|
+
*/
|
|
158
|
+
incrementRetryCount(messageId) {
|
|
159
|
+
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
|
|
160
|
+
this.statistics.totalRetries++;
|
|
161
|
+
return this.retryCounters.get(messageId);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get retry count for a message
|
|
165
|
+
*/
|
|
166
|
+
getRetryCount(messageId) {
|
|
167
|
+
return this.retryCounters.get(messageId) || 0;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if message has exceeded maximum retry attempts
|
|
171
|
+
*/
|
|
172
|
+
hasExceededMaxRetries(messageId) {
|
|
173
|
+
return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Mark retry as successful
|
|
177
|
+
*/
|
|
178
|
+
markRetrySuccess(messageId) {
|
|
179
|
+
this.statistics.successfulRetries++;
|
|
180
|
+
// Clean up retry counter for successful message
|
|
181
|
+
this.retryCounters.delete(messageId);
|
|
182
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
183
|
+
this.removeRecentMessage(messageId);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Mark retry as failed
|
|
187
|
+
*/
|
|
188
|
+
markRetryFailed(messageId) {
|
|
189
|
+
this.statistics.failedRetries++;
|
|
190
|
+
this.retryCounters.delete(messageId);
|
|
191
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
192
|
+
this.removeRecentMessage(messageId);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Schedule a phone request with delay
|
|
196
|
+
*/
|
|
197
|
+
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
198
|
+
// Cancel any existing request for this message
|
|
199
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
200
|
+
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
201
|
+
delete this.pendingPhoneRequests[messageId];
|
|
202
|
+
this.statistics.phoneRequests++;
|
|
203
|
+
callback();
|
|
204
|
+
}, delay);
|
|
205
|
+
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Cancel pending phone request
|
|
209
|
+
*/
|
|
210
|
+
cancelPendingPhoneRequest(messageId) {
|
|
211
|
+
const timeout = this.pendingPhoneRequests[messageId];
|
|
212
|
+
if (timeout) {
|
|
213
|
+
clearTimeout(timeout);
|
|
214
|
+
delete this.pendingPhoneRequests[messageId];
|
|
215
|
+
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
clear() {
|
|
219
|
+
this.recentMessagesMap.clear();
|
|
220
|
+
this.messageKeyIndex.clear();
|
|
221
|
+
this.sessionRecreateHistory.clear();
|
|
222
|
+
this.retryCounters.clear();
|
|
223
|
+
this.baseKeys.clear();
|
|
224
|
+
for (const messageId of Object.keys(this.pendingPhoneRequests)) {
|
|
225
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
226
|
+
}
|
|
227
|
+
this.statistics = {
|
|
228
|
+
totalRetries: 0,
|
|
229
|
+
successfulRetries: 0,
|
|
230
|
+
failedRetries: 0,
|
|
231
|
+
mediaRetries: 0,
|
|
232
|
+
sessionRecreations: 0,
|
|
233
|
+
phoneRequests: 0
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
saveBaseKey(addr, msgId, baseKey) {
|
|
237
|
+
this.baseKeys.set(`${addr}:${msgId}`, baseKey);
|
|
238
|
+
}
|
|
239
|
+
hasSameBaseKey(addr, msgId, baseKey) {
|
|
240
|
+
const stored = this.baseKeys.get(`${addr}:${msgId}`);
|
|
241
|
+
if (!stored || stored.length !== baseKey.length) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
for (let i = 0; i < stored.length; i++) {
|
|
245
|
+
if (stored[i] !== baseKey[i])
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
deleteBaseKey(addr, msgId) {
|
|
251
|
+
this.baseKeys.delete(`${addr}:${msgId}`);
|
|
252
|
+
}
|
|
253
|
+
keyToString(key) {
|
|
254
|
+
return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
|
|
255
|
+
}
|
|
256
|
+
removeRecentMessage(messageId) {
|
|
257
|
+
const keyStr = this.messageKeyIndex.get(messageId);
|
|
258
|
+
if (!keyStr) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
this.recentMessagesMap.delete(keyStr);
|
|
262
|
+
this.messageKeyIndex.delete(messageId);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=message-retry-manager.js.map
|