@periskope/baileys 6.7.18-alpha.2 → 6.7.18-alpha.21
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/README.md +1 -1
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +4136 -4138
- package/lib/Defaults/index.d.ts +4 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +36 -40
- 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 +18 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +94 -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 +19 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/queue-job.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 +32 -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 +67 -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 +50 -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 +96 -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/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +27 -39
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +3 -2
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +37 -57
- package/lib/Signal/libsignal.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 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +2 -1
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +2 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +14 -26
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +88 -59
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +32 -37
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +27 -21
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +132 -119
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +218 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +42 -35
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +57 -63
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +124 -65
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +6 -7
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +74 -45
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +294 -164
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +71 -42
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +100 -83
- 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 +142 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +179 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +12 -11
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +100 -106
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +14 -13
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +9 -11
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +4 -3
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +11 -7
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +2 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +5 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +44 -10
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +1 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +17 -9
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +2 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +8 -7
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +4 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +2 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +15 -13
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -30
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +3 -2
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +24 -33
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +2 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/baileys-event-stream.js.map +1 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +61 -70
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +141 -139
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +2 -1
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +37 -86
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +7 -7
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +43 -43
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +3 -2
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +24 -30
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +11 -9
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +88 -111
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +4 -3
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +18 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +18 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -3
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +11 -48
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +6 -5
- 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 +9 -8
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +21 -24
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +5 -9
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +20 -11
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +200 -234
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +9 -8
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +217 -199
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +22 -26
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +125 -130
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +5 -4
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +47 -52
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -26
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +55 -61
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +5 -4
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1174 -1176
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +13 -51
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +5 -41
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +4 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +30 -38
- 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 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +21 -35
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -1
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +1 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +4 -6
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +12 -14
- 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 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +19 -21
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +4 -3
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +18 -20
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- 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 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +9 -8
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -30
- package/lib/index.js.map +1 -0
- package/package.json +26 -28
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
package/lib/Socket/chats.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const Utils_1 = require("../Utils");
|
|
13
|
-
const make_mutex_1 = require("../Utils/make-mutex");
|
|
14
|
-
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
15
|
-
const WABinary_1 = require("../WABinary");
|
|
16
|
-
const WAUSync_1 = require("../WAUSync");
|
|
17
|
-
const usync_1 = require("./usync");
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
|
|
5
|
+
import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
|
|
6
|
+
import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
|
|
7
|
+
import { makeMutex } from '../Utils/make-mutex.js';
|
|
8
|
+
import processMessage from '../Utils/process-message.js';
|
|
9
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
10
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
11
|
+
import { makeUSyncSocket } from './usync.js';
|
|
18
12
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
|
-
const makeChatsSocket = (config) => {
|
|
13
|
+
export const makeChatsSocket = (config) => {
|
|
20
14
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
21
|
-
const sock =
|
|
15
|
+
const sock = makeUSyncSocket(config);
|
|
22
16
|
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
23
17
|
let privacySettings;
|
|
24
18
|
let needToFlushWithAppStateSync = false;
|
|
25
19
|
let pendingAppStateSync = false;
|
|
26
20
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
|
-
const processingMutex =
|
|
21
|
+
const processingMutex = makeMutex();
|
|
28
22
|
const placeholderResendCache = config.placeholderResendCache ||
|
|
29
|
-
new
|
|
30
|
-
stdTTL:
|
|
23
|
+
new NodeCache({
|
|
24
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
31
25
|
useClones: false
|
|
32
26
|
});
|
|
33
27
|
if (!config.placeholderResendCache) {
|
|
@@ -44,12 +38,12 @@ const makeChatsSocket = (config) => {
|
|
|
44
38
|
tag: 'iq',
|
|
45
39
|
attrs: {
|
|
46
40
|
xmlns: 'privacy',
|
|
47
|
-
to:
|
|
41
|
+
to: S_WHATSAPP_NET,
|
|
48
42
|
type: 'get'
|
|
49
43
|
},
|
|
50
44
|
content: [{ tag: 'privacy', attrs: {} }]
|
|
51
45
|
});
|
|
52
|
-
privacySettings =
|
|
46
|
+
privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
|
|
53
47
|
}
|
|
54
48
|
return privacySettings;
|
|
55
49
|
};
|
|
@@ -59,7 +53,7 @@ const makeChatsSocket = (config) => {
|
|
|
59
53
|
tag: 'iq',
|
|
60
54
|
attrs: {
|
|
61
55
|
xmlns: 'privacy',
|
|
62
|
-
to:
|
|
56
|
+
to: S_WHATSAPP_NET,
|
|
63
57
|
type: 'set'
|
|
64
58
|
},
|
|
65
59
|
content: [
|
|
@@ -105,7 +99,7 @@ const makeChatsSocket = (config) => {
|
|
|
105
99
|
tag: 'iq',
|
|
106
100
|
attrs: {
|
|
107
101
|
xmlns: 'disappearing_mode',
|
|
108
|
-
to:
|
|
102
|
+
to: S_WHATSAPP_NET,
|
|
109
103
|
type: 'set'
|
|
110
104
|
},
|
|
111
105
|
content: [
|
|
@@ -123,7 +117,7 @@ const makeChatsSocket = (config) => {
|
|
|
123
117
|
tag: 'iq',
|
|
124
118
|
attrs: {
|
|
125
119
|
xmlns: 'bot',
|
|
126
|
-
to:
|
|
120
|
+
to: S_WHATSAPP_NET,
|
|
127
121
|
type: 'get'
|
|
128
122
|
},
|
|
129
123
|
content: [
|
|
@@ -135,11 +129,11 @@ const makeChatsSocket = (config) => {
|
|
|
135
129
|
}
|
|
136
130
|
]
|
|
137
131
|
});
|
|
138
|
-
const botNode =
|
|
132
|
+
const botNode = getBinaryNodeChild(resp, 'bot');
|
|
139
133
|
const botList = [];
|
|
140
|
-
for (const section of
|
|
134
|
+
for (const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
141
135
|
if (section.attrs.type === 'all') {
|
|
142
|
-
for (const bot of
|
|
136
|
+
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
143
137
|
botList.push({
|
|
144
138
|
jid: bot.attrs.jid,
|
|
145
139
|
personaId: bot.attrs['persona_id']
|
|
@@ -150,10 +144,10 @@ const makeChatsSocket = (config) => {
|
|
|
150
144
|
return botList;
|
|
151
145
|
};
|
|
152
146
|
const onWhatsApp = async (...jids) => {
|
|
153
|
-
const usyncQuery = new
|
|
147
|
+
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
|
|
154
148
|
for (const jid of jids) {
|
|
155
|
-
const phone = `+${jid.replace('+', '').split('@')[0]
|
|
156
|
-
usyncQuery.withUser(new
|
|
149
|
+
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
150
|
+
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
157
151
|
}
|
|
158
152
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
159
153
|
if (results) {
|
|
@@ -161,9 +155,9 @@ const makeChatsSocket = (config) => {
|
|
|
161
155
|
}
|
|
162
156
|
};
|
|
163
157
|
const fetchStatus = async (...jids) => {
|
|
164
|
-
const usyncQuery = new
|
|
158
|
+
const usyncQuery = new USyncQuery().withStatusProtocol();
|
|
165
159
|
for (const jid of jids) {
|
|
166
|
-
usyncQuery.withUser(new
|
|
160
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
167
161
|
}
|
|
168
162
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
169
163
|
if (result) {
|
|
@@ -171,9 +165,9 @@ const makeChatsSocket = (config) => {
|
|
|
171
165
|
}
|
|
172
166
|
};
|
|
173
167
|
const fetchDisappearingDuration = async (...jids) => {
|
|
174
|
-
const usyncQuery = new
|
|
168
|
+
const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
|
|
175
169
|
for (const jid of jids) {
|
|
176
|
-
usyncQuery.withUser(new
|
|
170
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
177
171
|
}
|
|
178
172
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
179
173
|
if (result) {
|
|
@@ -181,22 +175,25 @@ const makeChatsSocket = (config) => {
|
|
|
181
175
|
}
|
|
182
176
|
};
|
|
183
177
|
/** update the profile picture for yourself or a group */
|
|
184
|
-
const updateProfilePicture = async (jid, content) => {
|
|
178
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
185
179
|
let targetJid;
|
|
186
180
|
if (!jid) {
|
|
187
|
-
throw new
|
|
181
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
182
|
+
}
|
|
183
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
184
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
188
185
|
}
|
|
189
|
-
|
|
190
|
-
targetJid =
|
|
186
|
+
else {
|
|
187
|
+
targetJid = undefined;
|
|
191
188
|
}
|
|
192
|
-
const { img } = await (
|
|
189
|
+
const { img } = await generateProfilePicture(content, dimensions);
|
|
193
190
|
await query({
|
|
194
191
|
tag: 'iq',
|
|
195
192
|
attrs: {
|
|
196
|
-
|
|
197
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
193
|
+
to: S_WHATSAPP_NET,
|
|
198
194
|
type: 'set',
|
|
199
|
-
xmlns: 'w:profile:picture'
|
|
195
|
+
xmlns: 'w:profile:picture',
|
|
196
|
+
...(targetJid ? { target: targetJid } : {})
|
|
200
197
|
},
|
|
201
198
|
content: [
|
|
202
199
|
{
|
|
@@ -211,18 +208,21 @@ const makeChatsSocket = (config) => {
|
|
|
211
208
|
const removeProfilePicture = async (jid) => {
|
|
212
209
|
let targetJid;
|
|
213
210
|
if (!jid) {
|
|
214
|
-
throw new
|
|
211
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
215
212
|
}
|
|
216
|
-
if (
|
|
217
|
-
targetJid =
|
|
213
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
214
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
targetJid = undefined;
|
|
218
218
|
}
|
|
219
219
|
await query({
|
|
220
220
|
tag: 'iq',
|
|
221
221
|
attrs: {
|
|
222
|
-
|
|
223
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
222
|
+
to: S_WHATSAPP_NET,
|
|
224
223
|
type: 'set',
|
|
225
|
-
xmlns: 'w:profile:picture'
|
|
224
|
+
xmlns: 'w:profile:picture',
|
|
225
|
+
...(targetJid ? { target: targetJid } : {})
|
|
226
226
|
}
|
|
227
227
|
});
|
|
228
228
|
};
|
|
@@ -231,7 +231,7 @@ const makeChatsSocket = (config) => {
|
|
|
231
231
|
await query({
|
|
232
232
|
tag: 'iq',
|
|
233
233
|
attrs: {
|
|
234
|
-
to:
|
|
234
|
+
to: S_WHATSAPP_NET,
|
|
235
235
|
type: 'set',
|
|
236
236
|
xmlns: 'status'
|
|
237
237
|
},
|
|
@@ -252,19 +252,19 @@ const makeChatsSocket = (config) => {
|
|
|
252
252
|
tag: 'iq',
|
|
253
253
|
attrs: {
|
|
254
254
|
xmlns: 'blocklist',
|
|
255
|
-
to:
|
|
255
|
+
to: S_WHATSAPP_NET,
|
|
256
256
|
type: 'get'
|
|
257
257
|
}
|
|
258
258
|
});
|
|
259
|
-
const listNode =
|
|
260
|
-
return
|
|
259
|
+
const listNode = getBinaryNodeChild(result, 'list');
|
|
260
|
+
return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
|
|
261
261
|
};
|
|
262
262
|
const updateBlockStatus = async (jid, action) => {
|
|
263
263
|
await query({
|
|
264
264
|
tag: 'iq',
|
|
265
265
|
attrs: {
|
|
266
266
|
xmlns: 'blocklist',
|
|
267
|
-
to:
|
|
267
|
+
to: S_WHATSAPP_NET,
|
|
268
268
|
type: 'set'
|
|
269
269
|
},
|
|
270
270
|
content: [
|
|
@@ -279,7 +279,6 @@ const makeChatsSocket = (config) => {
|
|
|
279
279
|
});
|
|
280
280
|
};
|
|
281
281
|
const getBusinessProfile = async (jid) => {
|
|
282
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
283
282
|
const results = await query({
|
|
284
283
|
tag: 'iq',
|
|
285
284
|
attrs: {
|
|
@@ -300,29 +299,29 @@ const makeChatsSocket = (config) => {
|
|
|
300
299
|
}
|
|
301
300
|
]
|
|
302
301
|
});
|
|
303
|
-
const profileNode =
|
|
304
|
-
const profiles =
|
|
302
|
+
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
303
|
+
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
305
304
|
if (profiles) {
|
|
306
|
-
const address =
|
|
307
|
-
const description =
|
|
308
|
-
const website =
|
|
309
|
-
const email =
|
|
310
|
-
const category =
|
|
311
|
-
const businessHours =
|
|
305
|
+
const address = getBinaryNodeChild(profiles, 'address');
|
|
306
|
+
const description = getBinaryNodeChild(profiles, 'description');
|
|
307
|
+
const website = getBinaryNodeChild(profiles, 'website');
|
|
308
|
+
const email = getBinaryNodeChild(profiles, 'email');
|
|
309
|
+
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
|
|
310
|
+
const businessHours = getBinaryNodeChild(profiles, 'business_hours');
|
|
312
311
|
const businessHoursConfig = businessHours
|
|
313
|
-
?
|
|
312
|
+
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
314
313
|
: undefined;
|
|
315
|
-
const websiteStr =
|
|
314
|
+
const websiteStr = website?.content?.toString();
|
|
316
315
|
return {
|
|
317
|
-
wid:
|
|
318
|
-
address:
|
|
319
|
-
description:
|
|
316
|
+
wid: profiles.attrs?.jid,
|
|
317
|
+
address: address?.content?.toString(),
|
|
318
|
+
description: description?.content?.toString() || '',
|
|
320
319
|
website: websiteStr ? [websiteStr] : [],
|
|
321
|
-
email:
|
|
322
|
-
category:
|
|
320
|
+
email: email?.content?.toString(),
|
|
321
|
+
category: category?.content?.toString(),
|
|
323
322
|
business_hours: {
|
|
324
|
-
timezone:
|
|
325
|
-
business_config: businessHoursConfig
|
|
323
|
+
timezone: businessHours?.attrs?.timezone,
|
|
324
|
+
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
326
325
|
}
|
|
327
326
|
};
|
|
328
327
|
}
|
|
@@ -332,7 +331,7 @@ const makeChatsSocket = (config) => {
|
|
|
332
331
|
await sendNode({
|
|
333
332
|
tag: 'iq',
|
|
334
333
|
attrs: {
|
|
335
|
-
to:
|
|
334
|
+
to: S_WHATSAPP_NET,
|
|
336
335
|
type: 'set',
|
|
337
336
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
338
337
|
id: generateMessageTag()
|
|
@@ -351,7 +350,7 @@ const makeChatsSocket = (config) => {
|
|
|
351
350
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
352
351
|
return {
|
|
353
352
|
onMutation(mutation) {
|
|
354
|
-
|
|
353
|
+
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
355
354
|
}
|
|
356
355
|
};
|
|
357
356
|
};
|
|
@@ -361,7 +360,6 @@ const makeChatsSocket = (config) => {
|
|
|
361
360
|
const initialVersionMap = {};
|
|
362
361
|
const globalMutationMap = {};
|
|
363
362
|
await authState.keys.transaction(async () => {
|
|
364
|
-
var _a;
|
|
365
363
|
const collectionsToHandle = new Set(collections);
|
|
366
364
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
367
365
|
const attemptsMap = {};
|
|
@@ -380,7 +378,7 @@ const makeChatsSocket = (config) => {
|
|
|
380
378
|
}
|
|
381
379
|
}
|
|
382
380
|
else {
|
|
383
|
-
state =
|
|
381
|
+
state = newLTHashState();
|
|
384
382
|
}
|
|
385
383
|
states[name] = state;
|
|
386
384
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -397,7 +395,7 @@ const makeChatsSocket = (config) => {
|
|
|
397
395
|
const result = await query({
|
|
398
396
|
tag: 'iq',
|
|
399
397
|
attrs: {
|
|
400
|
-
to:
|
|
398
|
+
to: S_WHATSAPP_NET,
|
|
401
399
|
xmlns: 'w:sync:app:state',
|
|
402
400
|
type: 'set'
|
|
403
401
|
},
|
|
@@ -410,13 +408,13 @@ const makeChatsSocket = (config) => {
|
|
|
410
408
|
]
|
|
411
409
|
});
|
|
412
410
|
// extract from binary node
|
|
413
|
-
const decoded = await
|
|
411
|
+
const decoded = await extractSyncdPatches(result, config?.options);
|
|
414
412
|
for (const key in decoded) {
|
|
415
413
|
const name = key;
|
|
416
414
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
417
415
|
try {
|
|
418
416
|
if (snapshot) {
|
|
419
|
-
const { state: newState, mutationMap } = await
|
|
417
|
+
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
420
418
|
states[name] = newState;
|
|
421
419
|
Object.assign(globalMutationMap, mutationMap);
|
|
422
420
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
@@ -424,7 +422,7 @@ const makeChatsSocket = (config) => {
|
|
|
424
422
|
}
|
|
425
423
|
// only process if there are syncd patches
|
|
426
424
|
if (patches.length) {
|
|
427
|
-
const { state: newState, mutationMap } = await
|
|
425
|
+
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
428
426
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
429
427
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
430
428
|
initialVersionMap[name] = newState.version;
|
|
@@ -442,7 +440,7 @@ const makeChatsSocket = (config) => {
|
|
|
442
440
|
// if retry attempts overshoot
|
|
443
441
|
// or key not found
|
|
444
442
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
445
|
-
|
|
443
|
+
error.output?.statusCode === 404 ||
|
|
446
444
|
error.name === 'TypeError';
|
|
447
445
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
448
446
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
@@ -467,20 +465,19 @@ const makeChatsSocket = (config) => {
|
|
|
467
465
|
* type = "image for the high res picture"
|
|
468
466
|
*/
|
|
469
467
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
470
|
-
|
|
471
|
-
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
468
|
+
jid = jidNormalizedUser(jid);
|
|
472
469
|
const result = await query({
|
|
473
470
|
tag: 'iq',
|
|
474
471
|
attrs: {
|
|
475
472
|
target: jid,
|
|
476
|
-
to:
|
|
473
|
+
to: S_WHATSAPP_NET,
|
|
477
474
|
type: 'get',
|
|
478
475
|
xmlns: 'w:profile:picture'
|
|
479
476
|
},
|
|
480
477
|
content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
|
|
481
478
|
}, timeoutMs);
|
|
482
|
-
const child =
|
|
483
|
-
return
|
|
479
|
+
const child = getBinaryNodeChild(result, 'picture');
|
|
480
|
+
return child?.attrs?.url;
|
|
484
481
|
};
|
|
485
482
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
486
483
|
const me = authState.creds.me;
|
|
@@ -493,16 +490,18 @@ const makeChatsSocket = (config) => {
|
|
|
493
490
|
await sendNode({
|
|
494
491
|
tag: 'presence',
|
|
495
492
|
attrs: {
|
|
496
|
-
name: me.name,
|
|
493
|
+
name: me.name.replace(/@/g, ''),
|
|
497
494
|
type
|
|
498
495
|
}
|
|
499
496
|
});
|
|
500
497
|
}
|
|
501
498
|
else {
|
|
499
|
+
const { server } = jidDecode(toJid);
|
|
500
|
+
const isLid = server === 'lid';
|
|
502
501
|
await sendNode({
|
|
503
502
|
tag: 'chatstate',
|
|
504
503
|
attrs: {
|
|
505
|
-
from: me.id,
|
|
504
|
+
from: isLid ? me.lid : me.id,
|
|
506
505
|
to: toJid
|
|
507
506
|
},
|
|
508
507
|
content: [
|
|
@@ -536,7 +535,6 @@ const makeChatsSocket = (config) => {
|
|
|
536
535
|
: undefined
|
|
537
536
|
});
|
|
538
537
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
539
|
-
var _a;
|
|
540
538
|
let presence;
|
|
541
539
|
const jid = attrs.from;
|
|
542
540
|
const participant = attrs.participant || attrs.from;
|
|
@@ -555,7 +553,7 @@ const makeChatsSocket = (config) => {
|
|
|
555
553
|
if (type === 'paused') {
|
|
556
554
|
type = 'available';
|
|
557
555
|
}
|
|
558
|
-
if (
|
|
556
|
+
if (firstChild.attrs?.media === 'audio') {
|
|
559
557
|
type = 'recording';
|
|
560
558
|
}
|
|
561
559
|
presence = { lastKnownPresence: type };
|
|
@@ -571,7 +569,7 @@ const makeChatsSocket = (config) => {
|
|
|
571
569
|
const name = patchCreate.type;
|
|
572
570
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
573
571
|
if (!myAppStateKeyId) {
|
|
574
|
-
throw new
|
|
572
|
+
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
575
573
|
}
|
|
576
574
|
let initial;
|
|
577
575
|
let encodeResult;
|
|
@@ -580,13 +578,13 @@ const makeChatsSocket = (config) => {
|
|
|
580
578
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
581
579
|
await resyncAppState([name], false);
|
|
582
580
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
583
|
-
initial = currentSyncVersion ||
|
|
584
|
-
encodeResult = await
|
|
581
|
+
initial = currentSyncVersion || newLTHashState();
|
|
582
|
+
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
585
583
|
const { patch, state } = encodeResult;
|
|
586
584
|
const node = {
|
|
587
585
|
tag: 'iq',
|
|
588
586
|
attrs: {
|
|
589
|
-
to:
|
|
587
|
+
to: S_WHATSAPP_NET,
|
|
590
588
|
type: 'set',
|
|
591
589
|
xmlns: 'w:sync:app:state'
|
|
592
590
|
},
|
|
@@ -606,7 +604,7 @@ const makeChatsSocket = (config) => {
|
|
|
606
604
|
{
|
|
607
605
|
tag: 'patch',
|
|
608
606
|
attrs: {},
|
|
609
|
-
content:
|
|
607
|
+
content: proto.SyncdPatch.encode(patch).finish()
|
|
610
608
|
}
|
|
611
609
|
]
|
|
612
610
|
}
|
|
@@ -620,7 +618,7 @@ const makeChatsSocket = (config) => {
|
|
|
620
618
|
});
|
|
621
619
|
if (config.emitOwnEvents) {
|
|
622
620
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
623
|
-
const { mutationMap } = await
|
|
621
|
+
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
624
622
|
for (const key in mutationMap) {
|
|
625
623
|
onMutation(mutationMap[key]);
|
|
626
624
|
}
|
|
@@ -628,11 +626,10 @@ const makeChatsSocket = (config) => {
|
|
|
628
626
|
};
|
|
629
627
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
630
628
|
const fetchProps = async () => {
|
|
631
|
-
var _a, _b, _c;
|
|
632
629
|
const resultNode = await query({
|
|
633
630
|
tag: 'iq',
|
|
634
631
|
attrs: {
|
|
635
|
-
to:
|
|
632
|
+
to: S_WHATSAPP_NET,
|
|
636
633
|
xmlns: 'w',
|
|
637
634
|
type: 'get'
|
|
638
635
|
},
|
|
@@ -641,20 +638,20 @@ const makeChatsSocket = (config) => {
|
|
|
641
638
|
tag: 'props',
|
|
642
639
|
attrs: {
|
|
643
640
|
protocol: '2',
|
|
644
|
-
hash:
|
|
641
|
+
hash: authState?.creds?.lastPropHash || ''
|
|
645
642
|
}
|
|
646
643
|
}
|
|
647
644
|
]
|
|
648
645
|
});
|
|
649
|
-
const propsNode =
|
|
646
|
+
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
650
647
|
let props = {};
|
|
651
648
|
if (propsNode) {
|
|
652
|
-
if (
|
|
649
|
+
if (propsNode.attrs?.hash) {
|
|
653
650
|
// on some clients, the hash is returning as undefined
|
|
654
|
-
authState.creds.lastPropHash =
|
|
651
|
+
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
655
652
|
ev.emit('creds.update', authState.creds);
|
|
656
653
|
}
|
|
657
|
-
props =
|
|
654
|
+
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
658
655
|
}
|
|
659
656
|
logger.debug('fetched props');
|
|
660
657
|
return props;
|
|
@@ -665,7 +662,7 @@ const makeChatsSocket = (config) => {
|
|
|
665
662
|
* requires the last messages till the last message received; required for archive & unread
|
|
666
663
|
*/
|
|
667
664
|
const chatModify = (mod, jid) => {
|
|
668
|
-
const patch =
|
|
665
|
+
const patch = chatModificationToAppPatch(mod, jid);
|
|
669
666
|
return appPatch(patch);
|
|
670
667
|
};
|
|
671
668
|
/**
|
|
@@ -679,6 +676,22 @@ const makeChatsSocket = (config) => {
|
|
|
679
676
|
}
|
|
680
677
|
}, jid);
|
|
681
678
|
};
|
|
679
|
+
/**
|
|
680
|
+
* Add or Edit Contact
|
|
681
|
+
*/
|
|
682
|
+
const addOrEditContact = (jid, contact) => {
|
|
683
|
+
return chatModify({
|
|
684
|
+
contact
|
|
685
|
+
}, jid);
|
|
686
|
+
};
|
|
687
|
+
/**
|
|
688
|
+
* Remove Contact
|
|
689
|
+
*/
|
|
690
|
+
const removeContact = (jid) => {
|
|
691
|
+
return chatModify({
|
|
692
|
+
contact: null
|
|
693
|
+
}, jid);
|
|
694
|
+
};
|
|
682
695
|
/**
|
|
683
696
|
* Adds label
|
|
684
697
|
*/
|
|
@@ -739,22 +752,21 @@ const makeChatsSocket = (config) => {
|
|
|
739
752
|
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
740
753
|
};
|
|
741
754
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
742
|
-
var _a, _b, _c;
|
|
743
755
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
744
756
|
if (!!msg.pushName) {
|
|
745
757
|
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
746
|
-
jid =
|
|
758
|
+
jid = jidNormalizedUser(jid);
|
|
747
759
|
if (!msg.key.fromMe) {
|
|
748
|
-
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
760
|
+
ev.emit('contacts.update', [{ id: jid, lid: msg.key.participantLid || msg.key.senderLid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
749
761
|
}
|
|
750
762
|
// update our pushname too
|
|
751
|
-
if (msg.key.fromMe && msg.pushName &&
|
|
763
|
+
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
752
764
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
753
765
|
}
|
|
754
766
|
}
|
|
755
|
-
const historyMsg =
|
|
767
|
+
const historyMsg = getHistoryMsg(msg.message);
|
|
756
768
|
const shouldProcessHistoryMsg = historyMsg
|
|
757
|
-
? shouldSyncHistoryMessage(historyMsg) &&
|
|
769
|
+
? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
758
770
|
: false;
|
|
759
771
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
760
772
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
@@ -767,7 +779,7 @@ const makeChatsSocket = (config) => {
|
|
|
767
779
|
await doAppStateSync();
|
|
768
780
|
}
|
|
769
781
|
})(),
|
|
770
|
-
(
|
|
782
|
+
processMessage(msg, {
|
|
771
783
|
shouldProcessHistoryMsg,
|
|
772
784
|
placeholderResendCache,
|
|
773
785
|
ev,
|
|
@@ -778,14 +790,14 @@ const makeChatsSocket = (config) => {
|
|
|
778
790
|
getMessage: config.getMessage
|
|
779
791
|
})
|
|
780
792
|
]);
|
|
781
|
-
if (
|
|
793
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && pendingAppStateSync) {
|
|
782
794
|
await doAppStateSync();
|
|
783
795
|
pendingAppStateSync = false;
|
|
784
796
|
}
|
|
785
797
|
async function doAppStateSync() {
|
|
786
798
|
if (!authState.creds.accountSyncCounter) {
|
|
787
799
|
logger.info('doing initial app state sync');
|
|
788
|
-
await resyncAppState(
|
|
800
|
+
await resyncAppState(ALL_WA_PATCH_NAMES, true);
|
|
789
801
|
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
790
802
|
ev.emit('creds.update', { accountSyncCounter });
|
|
791
803
|
if (needToFlushWithAppStateSync) {
|
|
@@ -798,7 +810,7 @@ const makeChatsSocket = (config) => {
|
|
|
798
810
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
799
811
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
800
812
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
801
|
-
const { attrs } =
|
|
813
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
802
814
|
const type = attrs.type;
|
|
803
815
|
switch (type) {
|
|
804
816
|
case 'account_sync':
|
|
@@ -820,7 +832,6 @@ const makeChatsSocket = (config) => {
|
|
|
820
832
|
}
|
|
821
833
|
});
|
|
822
834
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
823
|
-
var _a;
|
|
824
835
|
if (connection === 'open') {
|
|
825
836
|
if (fireInitQueries) {
|
|
826
837
|
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
@@ -831,7 +842,7 @@ const makeChatsSocket = (config) => {
|
|
|
831
842
|
// we keep buffering events until we finally have
|
|
832
843
|
// the key and can sync the messages
|
|
833
844
|
// todo scrutinize
|
|
834
|
-
!
|
|
845
|
+
!authState.creds?.myAppStateKeyId) {
|
|
835
846
|
ev.buffer();
|
|
836
847
|
needToFlushWithAppStateSync = true;
|
|
837
848
|
}
|
|
@@ -868,6 +879,8 @@ const makeChatsSocket = (config) => {
|
|
|
868
879
|
resyncAppState,
|
|
869
880
|
chatModify,
|
|
870
881
|
cleanDirtyBits,
|
|
882
|
+
addOrEditContact,
|
|
883
|
+
removeContact,
|
|
871
884
|
addLabel,
|
|
872
885
|
addChatLabel,
|
|
873
886
|
removeChatLabel,
|
|
@@ -876,4 +889,4 @@ const makeChatsSocket = (config) => {
|
|
|
876
889
|
star
|
|
877
890
|
};
|
|
878
891
|
};
|
|
879
|
-
|
|
892
|
+
//# sourceMappingURL=chats.js.map
|