@pontalabs/baileys 1.0.4 → 1.0.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/LICENSE +1 -1
- package/README.md +267 -839
- package/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -55
- package/WAProto/index.js +97689 -29
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +72 -74
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +94 -108
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +8 -7
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -16
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +11 -13
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +19 -61
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +14 -16
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +41 -70
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -61
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +9 -14
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +10 -58
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +13 -34
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +28 -36
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +38 -45
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +14 -15
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +20 -31
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +24 -25
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +18 -35
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +29 -34
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +37 -100
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -10
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +15 -22
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -8
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +279 -121
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -28
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +277 -184
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -22
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +8 -15
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +29 -37
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +208 -178
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +91 -127
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +120 -93
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +727 -652
- 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/dugong.js +261 -0
- package/lib/Socket/dugong.js.bak +204 -0
- package/lib/Socket/groups.d.ts +143 -111
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +165 -177
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +252 -183
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +38 -18
- package/lib/Socket/index.js.bak +44 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +196 -167
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1443 -1563
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +192 -158
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1102 -1208
- package/lib/Socket/messages-send.js.bak +1400 -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 +163 -138
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +153 -249
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +50 -36
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +749 -820
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.d.ts.map +1 -0
- package/lib/Store/index.js +4 -24
- package/lib/Store/index.js.map +1 -0
- package/lib/Store/make-in-memory-store.d.ts +44 -104
- package/lib/Store/make-in-memory-store.d.ts.map +1 -0
- package/lib/Store/make-in-memory-store.js +199 -213
- package/lib/Store/make-in-memory-store.js.map +1 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -12
- package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
- package/lib/Store/make-ordered-dictionary.js +38 -45
- package/lib/Store/make-ordered-dictionary.js.map +1 -0
- package/lib/Store/object-repository.d.ts +11 -10
- package/lib/Store/object-repository.d.ts.map +1 -0
- package/lib/Store/object-repository.js +9 -16
- package/lib/Store/object-repository.js.map +1 -0
- package/lib/Types/Auth.d.ts +93 -97
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -3
- 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 -3
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +14 -13
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +78 -97
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -9
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +12 -9
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +206 -176
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +53 -48
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +13 -14
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +24 -30
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +15 -20
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +6 -12
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +248 -412
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +17 -19
- 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 +58 -71
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.d.ts.map +1 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/RichType.js.bak +23 -0
- package/lib/Types/RichType.js.map +1 -0
- package/lib/Types/Signal.d.ts +71 -82
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +76 -81
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +75 -19
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -14
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +47 -62
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -50
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +13 -10
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +213 -454
- package/lib/Utils/auth-utils.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 +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +14 -20
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +110 -134
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +88 -70
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +466 -403
- 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/crypto.d.ts +27 -46
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +117 -188
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +58 -45
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +213 -303
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +14 -17
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +321 -296
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +66 -92
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +270 -436
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -23
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +106 -76
- 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 +24 -21
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +24 -41
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +12 -14
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +40 -75
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +10 -11
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -14
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -53
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +28 -44
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -88
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -160
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +105 -107
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +548 -619
- package/lib/Utils/messages-media.js.bak +786 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +52 -66
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1730 -1558
- package/lib/Utils/messages.js.backup +1768 -0
- package/lib/Utils/messages.js.bak +1809 -0
- package/lib/Utils/messages.js.bak2 +893 -0
- package/lib/Utils/messages.js.bak3 +1183 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +176 -130
- 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/process-message.d.ts +43 -32
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +484 -282
- package/lib/Utils/process-message.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/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.d.ts.map +1 -0
- package/lib/Utils/rich-message-utils.js +1220 -724
- package/lib/Utils/rich-message-utils.js.backup +706 -0
- package/lib/Utils/rich-message-utils.js.bak +246 -0
- package/lib/Utils/rich-message-utils.js.map +1 -0
- package/lib/Utils/rich-message-utils.js.original +1332 -0
- package/lib/Utils/signal.d.ts +37 -32
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +140 -105
- 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 +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +70 -120
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -13
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +92 -66
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -13
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +128 -113
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1451 -1292
- package/lib/WABinary/constants.js.bak +1373 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -9
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +163 -189
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +14 -27
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +177 -105
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -25
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +41 -51
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +83 -120
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +10 -13
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -15
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +7 -14
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +30 -37
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19193 -11711
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +95 -109
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -23
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -21
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
- 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 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -26
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +27 -28
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +68 -62
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +15 -10
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +20 -19
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -23
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +11 -12
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -39
- package/lib/index.js.map +1 -0
- package/package.json +86 -42
|
@@ -1,66 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const LabelAssociation_1 = require("../Types/LabelAssociation")
|
|
12
|
-
const Utils_1 = require("../Utils")
|
|
13
|
-
const WABinary_1 = require("../WABinary")
|
|
14
|
-
const Store_1 = require("./make-ordered-dictionary")
|
|
15
|
-
const object_repository_1 = require("./object-repository")
|
|
16
|
-
|
|
17
|
-
const waChatKey = (pin) => ({
|
|
1
|
+
import keyedDB from '@adiwajshing/keyed-db';
|
|
2
|
+
import { writeFileSync, readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { WAProto } from '../Types/index.js';
|
|
4
|
+
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
5
|
+
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
6
|
+
import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from '../Utils/index.js';
|
|
7
|
+
import { jidDecode, jidNormalizedUser } from '../WABinary/index.js';
|
|
8
|
+
import { makeOrderedDictionary } from './make-ordered-dictionary.js';
|
|
9
|
+
import { ObjectRepository } from './object-repository.js';
|
|
10
|
+
export const waChatKey = (pin) => ({
|
|
18
11
|
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
19
12
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const waLabelAssociationKey = {
|
|
25
|
-
key: (la) => (la.type === LabelAssociation_1.LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
13
|
+
});
|
|
14
|
+
export const waMessageID = (m) => m.key.id || '';
|
|
15
|
+
export const waLabelAssociationKey = {
|
|
16
|
+
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
26
17
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const labels = new object_repository_1.ObjectRepository()
|
|
44
|
-
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
|
|
18
|
+
};
|
|
19
|
+
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
|
|
20
|
+
export const makeInMemoryStore = (config = {}) => {
|
|
21
|
+
const socket = config.socket;
|
|
22
|
+
const chatKey = config.chatKey || waChatKey(true);
|
|
23
|
+
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
|
|
24
|
+
const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
25
|
+
const KeyedDB = keyedDB?.default ?? keyedDB;
|
|
26
|
+
const chats = new KeyedDB(chatKey, c => c.id);
|
|
27
|
+
const messages = {};
|
|
28
|
+
const contacts = {};
|
|
29
|
+
const groupMetadata = {};
|
|
30
|
+
const presences = {};
|
|
31
|
+
const state = { connection: 'close' };
|
|
32
|
+
const labels = new ObjectRepository();
|
|
33
|
+
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
|
|
45
34
|
const assertMessageList = (jid) => {
|
|
46
35
|
if (!messages[jid]) {
|
|
47
|
-
messages[jid] = makeMessagesDictionary()
|
|
36
|
+
messages[jid] = makeMessagesDictionary();
|
|
48
37
|
}
|
|
49
|
-
return messages[jid]
|
|
50
|
-
}
|
|
38
|
+
return messages[jid];
|
|
39
|
+
};
|
|
51
40
|
const contactsUpsert = (newContacts) => {
|
|
52
|
-
const oldContacts = new Set(Object.keys(contacts))
|
|
41
|
+
const oldContacts = new Set(Object.keys(contacts));
|
|
53
42
|
for (const contact of newContacts) {
|
|
54
|
-
oldContacts.delete(contact.id)
|
|
55
|
-
contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact)
|
|
43
|
+
oldContacts.delete(contact.id);
|
|
44
|
+
contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
|
|
56
45
|
}
|
|
57
|
-
return oldContacts
|
|
58
|
-
}
|
|
46
|
+
return oldContacts;
|
|
47
|
+
};
|
|
59
48
|
const labelsUpsert = (newLabels) => {
|
|
60
49
|
for (const label of newLabels) {
|
|
61
|
-
labels.upsertById(label.id, label)
|
|
50
|
+
labels.upsertById(label.id, label);
|
|
62
51
|
}
|
|
63
|
-
}
|
|
52
|
+
};
|
|
64
53
|
/**
|
|
65
54
|
* binds to a BaileysEventEmitter.
|
|
66
55
|
* It listens to all events and constructs a state that you can query accurate data from.
|
|
@@ -69,237 +58,252 @@ const makeInMemoryStore = (config) => {
|
|
|
69
58
|
*/
|
|
70
59
|
const bind = (ev) => {
|
|
71
60
|
ev.on('connection.update', update => {
|
|
72
|
-
Object.assign(state, update)
|
|
73
|
-
})
|
|
61
|
+
Object.assign(state, update);
|
|
62
|
+
});
|
|
74
63
|
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
75
|
-
if (syncType ===
|
|
76
|
-
return // FOR NOW,
|
|
64
|
+
if (syncType === WAProto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
65
|
+
return; // FOR NOW,
|
|
77
66
|
//TODO: HANDLE
|
|
78
67
|
}
|
|
79
68
|
if (isLatest) {
|
|
80
|
-
chats.clear()
|
|
69
|
+
chats.clear();
|
|
81
70
|
for (const id in messages) {
|
|
82
|
-
delete messages[id]
|
|
71
|
+
delete messages[id];
|
|
83
72
|
}
|
|
84
73
|
}
|
|
85
|
-
const chatsAdded = chats.insertIfAbsent(...newChats).length
|
|
86
|
-
logger.debug({ chatsAdded }, 'synced chats')
|
|
87
|
-
const oldContacts = contactsUpsert(newContacts)
|
|
74
|
+
const chatsAdded = chats.insertIfAbsent(...newChats).length;
|
|
75
|
+
logger.debug({ chatsAdded }, 'synced chats');
|
|
76
|
+
const oldContacts = contactsUpsert(newContacts);
|
|
88
77
|
if (isLatest) {
|
|
89
78
|
for (const jid of oldContacts) {
|
|
90
|
-
delete contacts[jid]
|
|
79
|
+
delete contacts[jid];
|
|
91
80
|
}
|
|
92
81
|
}
|
|
93
|
-
logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts')
|
|
82
|
+
logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
|
|
94
83
|
for (const msg of newMessages) {
|
|
95
|
-
const jid = msg.key.remoteJid
|
|
96
|
-
const list = assertMessageList(jid)
|
|
97
|
-
list.upsert(msg, 'prepend')
|
|
84
|
+
const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
|
|
85
|
+
const list = assertMessageList(jid);
|
|
86
|
+
list.upsert(msg, 'prepend');
|
|
98
87
|
}
|
|
99
|
-
logger.debug({ messages: newMessages.length }, 'synced messages')
|
|
100
|
-
})
|
|
88
|
+
logger.debug({ messages: newMessages.length }, 'synced messages');
|
|
89
|
+
});
|
|
101
90
|
ev.on('contacts.upsert', contacts => {
|
|
102
|
-
contactsUpsert(contacts)
|
|
103
|
-
})
|
|
91
|
+
contactsUpsert(contacts);
|
|
92
|
+
});
|
|
104
93
|
ev.on('contacts.update', async (updates) => {
|
|
94
|
+
var _a;
|
|
105
95
|
for (const update of updates) {
|
|
106
|
-
let contact
|
|
96
|
+
let contact;
|
|
107
97
|
if (contacts[update.id]) {
|
|
108
|
-
contact = contacts[update.id]
|
|
98
|
+
contact = contacts[update.id];
|
|
109
99
|
}
|
|
110
100
|
else {
|
|
111
101
|
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
112
|
-
const { user } =
|
|
113
|
-
return [contactId, (await
|
|
114
|
-
}))
|
|
115
|
-
contact = contacts[contactHashes.find(([, b]) => b === update.id
|
|
102
|
+
const { user } = jidDecode(contactId);
|
|
103
|
+
return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
|
104
|
+
}));
|
|
105
|
+
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
|
116
106
|
}
|
|
117
107
|
if (contact) {
|
|
118
108
|
if (update.imgUrl === 'changed') {
|
|
119
|
-
contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined
|
|
109
|
+
contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
|
|
120
110
|
}
|
|
121
111
|
else if (update.imgUrl === 'removed') {
|
|
122
|
-
delete contact.imgUrl
|
|
112
|
+
delete contact.imgUrl;
|
|
123
113
|
}
|
|
124
114
|
}
|
|
125
115
|
else {
|
|
126
|
-
return logger.debug({ update }, 'got update for non-existant contact')
|
|
116
|
+
return logger.debug({ update }, 'got update for non-existant contact');
|
|
127
117
|
}
|
|
128
|
-
Object.assign(contacts[contact.id], contact)
|
|
118
|
+
Object.assign(contacts[contact.id], contact);
|
|
129
119
|
}
|
|
130
|
-
})
|
|
120
|
+
});
|
|
131
121
|
ev.on('chats.upsert', newChats => {
|
|
132
|
-
chats.upsert(...newChats)
|
|
133
|
-
})
|
|
122
|
+
chats.upsert(...newChats);
|
|
123
|
+
});
|
|
134
124
|
ev.on('chats.update', updates => {
|
|
135
125
|
for (let update of updates) {
|
|
136
126
|
const result = chats.update(update.id, chat => {
|
|
137
127
|
if (update.unreadCount > 0) {
|
|
138
|
-
update = { ...update }
|
|
139
|
-
update.unreadCount = (chat.unreadCount || 0) + update.unreadCount
|
|
128
|
+
update = { ...update };
|
|
129
|
+
update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
|
|
140
130
|
}
|
|
141
|
-
Object.assign(chat, update)
|
|
142
|
-
})
|
|
131
|
+
Object.assign(chat, update);
|
|
132
|
+
});
|
|
143
133
|
if (!result) {
|
|
144
|
-
logger.debug({ update }, 'got update for non-existant chat')
|
|
134
|
+
logger.debug({ update }, 'got update for non-existant chat');
|
|
145
135
|
}
|
|
146
136
|
}
|
|
147
|
-
})
|
|
137
|
+
});
|
|
148
138
|
ev.on('labels.edit', (label) => {
|
|
149
139
|
if (label.deleted) {
|
|
150
|
-
return labels.deleteById(label.id)
|
|
140
|
+
return labels.deleteById(label.id);
|
|
151
141
|
}
|
|
152
142
|
// WhatsApp can store only up to 20 labels
|
|
153
143
|
if (labels.count() < 20) {
|
|
154
|
-
return labels.upsertById(label.id, label)
|
|
144
|
+
return labels.upsertById(label.id, label);
|
|
155
145
|
}
|
|
156
|
-
logger.error('Labels count exceed')
|
|
157
|
-
})
|
|
146
|
+
logger.error('Labels count exceed');
|
|
147
|
+
});
|
|
158
148
|
ev.on('labels.association', ({ type, association }) => {
|
|
159
149
|
switch (type) {
|
|
160
150
|
case 'add':
|
|
161
|
-
labelAssociations.upsert(association)
|
|
162
|
-
break
|
|
151
|
+
labelAssociations.upsert(association);
|
|
152
|
+
break;
|
|
163
153
|
case 'remove':
|
|
164
|
-
labelAssociations.delete(association)
|
|
165
|
-
break
|
|
154
|
+
labelAssociations.delete(association);
|
|
155
|
+
break;
|
|
166
156
|
default:
|
|
167
|
-
console.error(`unknown operation type [${type}]`)
|
|
157
|
+
console.error(`unknown operation type [${type}]`);
|
|
168
158
|
}
|
|
169
|
-
})
|
|
159
|
+
});
|
|
170
160
|
ev.on('presence.update', ({ id, presences: update }) => {
|
|
171
|
-
presences[id] = presences[id] || {}
|
|
172
|
-
Object.assign(presences[id], update)
|
|
173
|
-
})
|
|
161
|
+
presences[id] = presences[id] || {};
|
|
162
|
+
Object.assign(presences[id], update);
|
|
163
|
+
});
|
|
174
164
|
ev.on('chats.delete', deletions => {
|
|
175
165
|
for (const item of deletions) {
|
|
176
166
|
if (chats.get(item)) {
|
|
177
|
-
chats.deleteById(item)
|
|
167
|
+
chats.deleteById(item);
|
|
178
168
|
}
|
|
179
169
|
}
|
|
180
|
-
})
|
|
170
|
+
});
|
|
181
171
|
ev.on('messages.upsert', ({ messages: newMessages, type }) => {
|
|
182
172
|
switch (type) {
|
|
183
173
|
case 'append':
|
|
184
174
|
case 'notify':
|
|
185
175
|
for (const msg of newMessages) {
|
|
186
|
-
const jid =
|
|
187
|
-
const list = assertMessageList(jid)
|
|
188
|
-
list.upsert(msg, 'append')
|
|
176
|
+
const jid = jidNormalizedUser(msg.key.remoteJidAlt || msg.key.remoteJid);
|
|
177
|
+
const list = assertMessageList(jid);
|
|
178
|
+
list.upsert(msg, 'append');
|
|
189
179
|
if (type === 'notify' && !chats.get(jid)) {
|
|
190
180
|
ev.emit('chats.upsert', [
|
|
191
181
|
{
|
|
192
182
|
id: jid,
|
|
193
|
-
conversationTimestamp:
|
|
183
|
+
conversationTimestamp: toNumber(msg.messageTimestamp),
|
|
194
184
|
unreadCount: 1
|
|
195
185
|
}
|
|
196
|
-
])
|
|
186
|
+
]);
|
|
197
187
|
}
|
|
198
188
|
}
|
|
199
|
-
break
|
|
189
|
+
break;
|
|
200
190
|
}
|
|
201
|
-
})
|
|
191
|
+
});
|
|
202
192
|
ev.on('messages.update', updates => {
|
|
193
|
+
var _a;
|
|
203
194
|
for (const { update, key } of updates) {
|
|
204
|
-
const list = assertMessageList(
|
|
205
|
-
if (update
|
|
206
|
-
const listStatus = list.get(key.id)
|
|
207
|
-
if (listStatus && update
|
|
208
|
-
logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update')
|
|
209
|
-
delete update.status
|
|
210
|
-
logger.debug({ update }, 'new update object')
|
|
195
|
+
const list = assertMessageList(jidNormalizedUser(key.remoteJid));
|
|
196
|
+
if (update === null || update === void 0 ? void 0 : update.status) {
|
|
197
|
+
const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
|
|
198
|
+
if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
|
|
199
|
+
logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
|
|
200
|
+
delete update.status;
|
|
201
|
+
logger.debug({ update }, 'new update object');
|
|
211
202
|
}
|
|
212
203
|
}
|
|
213
|
-
const result = list.updateAssign(key.id, update)
|
|
204
|
+
const result = list.updateAssign(key.id, update);
|
|
214
205
|
if (!result) {
|
|
215
|
-
logger.debug({ update }, 'got update for non-existent message')
|
|
206
|
+
logger.debug({ update }, 'got update for non-existent message');
|
|
216
207
|
}
|
|
217
208
|
}
|
|
218
|
-
})
|
|
209
|
+
});
|
|
219
210
|
ev.on('messages.delete', item => {
|
|
220
211
|
if ('all' in item) {
|
|
221
|
-
const list = messages[item.jid]
|
|
222
|
-
list
|
|
212
|
+
const list = messages[item.jid];
|
|
213
|
+
list === null || list === void 0 ? void 0 : list.clear();
|
|
223
214
|
}
|
|
224
215
|
else {
|
|
225
|
-
const jid = item.keys[0].remoteJid
|
|
226
|
-
const list = messages[jid]
|
|
216
|
+
const jid = item.keys[0].remoteJidAlt || item.keys[0].remoteJid;
|
|
217
|
+
const list = messages[jid];
|
|
227
218
|
if (list) {
|
|
228
|
-
const idSet = new Set(item.keys.map(k => k.id))
|
|
229
|
-
list.filter(m => !idSet.has(m.key.id))
|
|
219
|
+
const idSet = new Set(item.keys.map(k => k.id));
|
|
220
|
+
list.filter(m => !idSet.has(m.key.id));
|
|
230
221
|
}
|
|
231
222
|
}
|
|
232
|
-
})
|
|
223
|
+
});
|
|
233
224
|
ev.on('groups.update', updates => {
|
|
234
225
|
for (const update of updates) {
|
|
235
|
-
const id = update.id
|
|
226
|
+
const id = update.id;
|
|
236
227
|
if (groupMetadata[id]) {
|
|
237
|
-
Object.assign(groupMetadata[id], update)
|
|
228
|
+
Object.assign(groupMetadata[id], update);
|
|
238
229
|
}
|
|
239
230
|
else {
|
|
240
|
-
logger.debug({ update }, 'got update for non-existant group metadata')
|
|
231
|
+
logger.debug({ update }, 'got update for non-existant group metadata');
|
|
241
232
|
}
|
|
242
233
|
}
|
|
243
|
-
})
|
|
234
|
+
});
|
|
244
235
|
ev.on('group-participants.update', ({ id, participants, action }) => {
|
|
245
|
-
const metadata = groupMetadata[id]
|
|
236
|
+
const metadata = groupMetadata[id];
|
|
246
237
|
if (metadata) {
|
|
247
238
|
switch (action) {
|
|
248
239
|
case 'add':
|
|
249
|
-
metadata.participants.push(...participants.map(
|
|
250
|
-
break
|
|
240
|
+
metadata.participants.push(...participants.map(participant => ({ id: participant.id, phoneNumber: participant.phoneNumber, admin: participant.admin })));
|
|
241
|
+
break;
|
|
251
242
|
case 'demote':
|
|
252
243
|
case 'promote':
|
|
253
244
|
for (const participant of metadata.participants) {
|
|
254
|
-
|
|
255
|
-
participant.
|
|
245
|
+
for (const participantData of participants) {
|
|
246
|
+
if (participantData.id === participant.id || participantData.phoneNumber === participant.phoneNumber) {
|
|
247
|
+
participant.admin = action === 'promote' && 'admin';
|
|
248
|
+
}
|
|
256
249
|
}
|
|
257
250
|
}
|
|
258
|
-
break
|
|
251
|
+
break;
|
|
259
252
|
case 'remove':
|
|
260
|
-
|
|
261
|
-
|
|
253
|
+
const removeSet = new Set();
|
|
254
|
+
for (const p of participants) {
|
|
255
|
+
if (p.id)
|
|
256
|
+
removeSet.add(p.id);
|
|
257
|
+
if (p.phoneNumber)
|
|
258
|
+
removeSet.add(p.phoneNumber);
|
|
259
|
+
}
|
|
260
|
+
metadata.participants = metadata.participants.reduce((acc, p) => {
|
|
261
|
+
if (!removeSet.has(p.id) && !removeSet.has(p.phoneNumber))
|
|
262
|
+
acc.push(p);
|
|
263
|
+
return acc;
|
|
264
|
+
}, []);
|
|
265
|
+
break;
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
|
-
})
|
|
268
|
+
});
|
|
265
269
|
ev.on('message-receipt.update', updates => {
|
|
266
270
|
for (const { key, receipt } of updates) {
|
|
267
|
-
const obj = messages[key.remoteJid]
|
|
268
|
-
const msg = obj
|
|
271
|
+
const obj = messages[key.remoteJidAlt || key.remoteJid];
|
|
272
|
+
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
269
273
|
if (msg) {
|
|
270
|
-
|
|
274
|
+
updateMessageWithReceipt(msg, receipt);
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
|
-
})
|
|
277
|
+
});
|
|
274
278
|
ev.on('messages.reaction', (reactions) => {
|
|
275
279
|
for (const { key, reaction } of reactions) {
|
|
276
|
-
const obj = messages[key.remoteJid]
|
|
277
|
-
const msg = obj
|
|
280
|
+
const obj = messages[key.remoteJidAlt || key.remoteJid];
|
|
281
|
+
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
278
282
|
if (msg) {
|
|
279
|
-
|
|
283
|
+
updateMessageWithReaction(msg, reaction);
|
|
280
284
|
}
|
|
281
285
|
}
|
|
282
|
-
})
|
|
283
|
-
}
|
|
286
|
+
});
|
|
287
|
+
};
|
|
284
288
|
const toJSON = () => ({
|
|
285
289
|
chats,
|
|
286
290
|
contacts,
|
|
287
291
|
messages,
|
|
288
292
|
labels,
|
|
289
293
|
labelAssociations
|
|
290
|
-
})
|
|
294
|
+
});
|
|
291
295
|
const fromJSON = (json) => {
|
|
292
|
-
chats.upsert(...json.chats)
|
|
293
|
-
labelAssociations.upsert(...json.labelAssociations || [])
|
|
294
|
-
contactsUpsert(Object.values(json.contacts))
|
|
295
|
-
labelsUpsert(Object.values(json.labels || {}))
|
|
296
|
+
chats.upsert(...json.chats);
|
|
297
|
+
labelAssociations.upsert(...json.labelAssociations || []);
|
|
298
|
+
contactsUpsert(Object.values(json.contacts));
|
|
299
|
+
labelsUpsert(Object.values(json.labels || {}));
|
|
296
300
|
for (const jid in json.messages) {
|
|
297
|
-
const list = assertMessageList(jid)
|
|
301
|
+
const list = assertMessageList(jid);
|
|
298
302
|
for (const msg of json.messages[jid]) {
|
|
299
|
-
list.upsert(
|
|
303
|
+
list.upsert(WAProto.WebMessageInfo.fromObject(msg), 'append');
|
|
300
304
|
}
|
|
301
305
|
}
|
|
302
|
-
}
|
|
306
|
+
};
|
|
303
307
|
return {
|
|
304
308
|
chats,
|
|
305
309
|
contacts,
|
|
@@ -312,28 +316,28 @@ const makeInMemoryStore = (config) => {
|
|
|
312
316
|
bind,
|
|
313
317
|
/** loads messages from the store, if not found -- uses the legacy connection */
|
|
314
318
|
loadMessages: async (jid, count, cursor) => {
|
|
315
|
-
const list = assertMessageList(jid)
|
|
316
|
-
const mode = !cursor || 'before' in cursor ? 'before' : 'after'
|
|
317
|
-
const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined
|
|
318
|
-
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined
|
|
319
|
-
let messages
|
|
319
|
+
const list = assertMessageList(jid);
|
|
320
|
+
const mode = !cursor || 'before' in cursor ? 'before' : 'after';
|
|
321
|
+
const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
|
|
322
|
+
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
|
|
323
|
+
let messages;
|
|
320
324
|
if (list && mode === 'before' && (!cursorKey || cursorValue)) {
|
|
321
325
|
if (cursorValue) {
|
|
322
|
-
const msgIdx = list.array.findIndex(m => m.key.id === cursorKey
|
|
323
|
-
messages = list.array.slice(0, msgIdx)
|
|
326
|
+
const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
|
|
327
|
+
messages = list.array.slice(0, msgIdx);
|
|
324
328
|
}
|
|
325
329
|
else {
|
|
326
|
-
messages = list.array
|
|
330
|
+
messages = list.array;
|
|
327
331
|
}
|
|
328
|
-
const diff = count - messages.length
|
|
332
|
+
const diff = count - messages.length;
|
|
329
333
|
if (diff < 0) {
|
|
330
|
-
messages = messages.slice(-count) // get the last X messages
|
|
334
|
+
messages = messages.slice(-count); // get the last X messages
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
337
|
else {
|
|
334
|
-
messages = []
|
|
338
|
+
messages = [];
|
|
335
339
|
}
|
|
336
|
-
return messages
|
|
340
|
+
return messages;
|
|
337
341
|
},
|
|
338
342
|
/**
|
|
339
343
|
* Get all available labels for profile
|
|
@@ -342,7 +346,7 @@ const makeInMemoryStore = (config) => {
|
|
|
342
346
|
* that were "caught" during their editing.
|
|
343
347
|
*/
|
|
344
348
|
getLabels: () => {
|
|
345
|
-
return labels
|
|
349
|
+
return labels;
|
|
346
350
|
},
|
|
347
351
|
/**
|
|
348
352
|
* Get labels for chat
|
|
@@ -350,7 +354,7 @@ const makeInMemoryStore = (config) => {
|
|
|
350
354
|
* @returns Label IDs
|
|
351
355
|
**/
|
|
352
356
|
getChatLabels: (chatId) => {
|
|
353
|
-
return labelAssociations.filter((la) => la.chatId === chatId).all()
|
|
357
|
+
return labelAssociations.filter((la) => la.chatId === chatId).all();
|
|
354
358
|
},
|
|
355
359
|
/**
|
|
356
360
|
* Get labels for message
|
|
@@ -360,70 +364,52 @@ const makeInMemoryStore = (config) => {
|
|
|
360
364
|
getMessageLabels: (messageId) => {
|
|
361
365
|
const associations = labelAssociations
|
|
362
366
|
.filter((la) => la.messageId === messageId)
|
|
363
|
-
.all()
|
|
364
|
-
return associations.map(({ labelId }) => labelId)
|
|
367
|
+
.all();
|
|
368
|
+
return associations.map(({ labelId }) => labelId);
|
|
365
369
|
},
|
|
366
|
-
loadMessage: async (jid, id) => messages[jid]
|
|
370
|
+
loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
|
|
367
371
|
mostRecentMessage: async (jid) => {
|
|
368
|
-
|
|
369
|
-
|
|
372
|
+
var _a;
|
|
373
|
+
const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
|
|
374
|
+
return message;
|
|
370
375
|
},
|
|
371
376
|
fetchImageUrl: async (jid, sock) => {
|
|
372
|
-
const contact = contacts[jid]
|
|
377
|
+
const contact = contacts[jid];
|
|
373
378
|
if (!contact) {
|
|
374
|
-
return sock
|
|
379
|
+
return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
|
|
375
380
|
}
|
|
376
381
|
if (typeof contact.imgUrl === 'undefined') {
|
|
377
|
-
contact.imgUrl = await sock
|
|
382
|
+
contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
|
|
378
383
|
}
|
|
379
|
-
return contact.imgUrl
|
|
384
|
+
return contact.imgUrl;
|
|
380
385
|
},
|
|
381
386
|
fetchGroupMetadata: async (jid, sock) => {
|
|
382
387
|
if (!groupMetadata[jid]) {
|
|
383
|
-
const metadata = await sock
|
|
388
|
+
const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
|
|
384
389
|
if (metadata) {
|
|
385
|
-
groupMetadata[jid] = metadata
|
|
390
|
+
groupMetadata[jid] = metadata;
|
|
386
391
|
}
|
|
387
392
|
}
|
|
388
|
-
return groupMetadata[jid]
|
|
393
|
+
return groupMetadata[jid];
|
|
389
394
|
},
|
|
390
|
-
// fetchBroadcastListInfo: async(jid: string, sock: WASocket | undefined) => {
|
|
391
|
-
// if(!groupMetadata[jid]) {
|
|
392
|
-
// const metadata = await sock?.getBroadcastListInfo(jid)
|
|
393
|
-
// if(metadata) {
|
|
394
|
-
// groupMetadata[jid] = metadata
|
|
395
|
-
// }
|
|
396
|
-
// }
|
|
397
|
-
// return groupMetadata[jid]
|
|
398
|
-
// },
|
|
399
395
|
fetchMessageReceipts: async ({ remoteJid, id }) => {
|
|
400
|
-
const list = messages[remoteJid]
|
|
401
|
-
const msg = list
|
|
402
|
-
return msg
|
|
396
|
+
const list = messages[remoteJid];
|
|
397
|
+
const msg = list === null || list === void 0 ? void 0 : list.get(id);
|
|
398
|
+
return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
|
|
403
399
|
},
|
|
404
400
|
toJSON,
|
|
405
401
|
fromJSON,
|
|
406
402
|
writeToFile: (path) => {
|
|
407
|
-
|
|
408
|
-
const { writeFileSync } = require('fs')
|
|
409
|
-
writeFileSync(path, JSON.stringify(toJSON()))
|
|
403
|
+
writeFileSync(path, JSON.stringify(toJSON()));
|
|
410
404
|
},
|
|
411
405
|
readFromFile: (path) => {
|
|
412
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
413
|
-
const { readFileSync, existsSync } = require('fs')
|
|
414
406
|
if (existsSync(path)) {
|
|
415
|
-
logger.debug({ path }, 'reading from file')
|
|
416
|
-
const jsonStr = readFileSync(path, { encoding: 'utf-8' })
|
|
417
|
-
const json = JSON.parse(jsonStr)
|
|
418
|
-
fromJSON(json)
|
|
407
|
+
logger.debug({ path }, 'reading from file');
|
|
408
|
+
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
409
|
+
const json = JSON.parse(jsonStr);
|
|
410
|
+
fromJSON(json);
|
|
419
411
|
}
|
|
420
412
|
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
module.exports = {
|
|
425
|
-
waChatKey,
|
|
426
|
-
waMessageID,
|
|
427
|
-
waLabelAssociationKey,
|
|
428
|
-
makeInMemoryStore
|
|
429
|
-
}
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
//# sourceMappingURL=make-in-memory-store.js.map
|