@d0v3riz/baileys 6.7.22 → 6.7.23
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/WAProto/GenerateStatics.sh +3 -2
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +4136 -4138
- package/lib/Defaults/index.d.ts +3 -2
- 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 +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +4 -3
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +3 -2
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +14 -16
- 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 -57
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +2 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +8 -44
- 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 +5 -5
- package/lib/Signal/Group/queue-job.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +7 -9
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +6 -9
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +10 -12
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +2 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +9 -12
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +3 -2
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +6 -9
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +5 -7
- 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 +22 -55
- 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 +66 -64
- 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 +21 -19
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +176 -141
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +219 -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 +37 -35
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +56 -63
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +102 -70
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +16 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +51 -49
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +180 -173
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +48 -46
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +75 -84
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +2 -1
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +12 -16
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +46 -44
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +23 -27
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +13 -12
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +135 -115
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +15 -14
- 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 +10 -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 +1 -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 +11 -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 -2
- 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 +9 -7
- 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 +1 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +5 -7
- 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 +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -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 -14
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -31
- 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 +25 -34
- 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 +8 -7
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +130 -137
- 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 +5 -4
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +38 -44
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +37 -50
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +9 -8
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +87 -114
- 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 +32 -40
- 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 +10 -47
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +8 -6
- 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 +23 -26
- 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 +11 -10
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +141 -203
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +7 -6
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +190 -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 +95 -104
- 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 +52 -58
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +1 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +9 -11
- 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 +6 -9
- 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 -26
package/lib/Socket/chats.js
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 { SyncState } from '../Types/State.js';
|
|
7
|
+
import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
|
|
8
|
+
import { makeMutex } from '../Utils/make-mutex.js';
|
|
9
|
+
import processMessage from '../Utils/process-message.js';
|
|
10
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
|
+
import { makeUSyncSocket } from './usync.js';
|
|
18
13
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
|
-
const makeChatsSocket = (config) => {
|
|
14
|
+
export const makeChatsSocket = (config) => {
|
|
20
15
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
21
|
-
const sock =
|
|
16
|
+
const sock = makeUSyncSocket(config);
|
|
22
17
|
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
23
18
|
let privacySettings;
|
|
24
|
-
let
|
|
25
|
-
let pendingAppStateSync = false;
|
|
19
|
+
let syncState = SyncState.Connecting;
|
|
26
20
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
|
-
const processingMutex =
|
|
21
|
+
const processingMutex = makeMutex();
|
|
22
|
+
// Timeout for AwaitingInitialSync state
|
|
23
|
+
let awaitingSyncTimeout;
|
|
28
24
|
const placeholderResendCache = config.placeholderResendCache ||
|
|
29
|
-
new
|
|
30
|
-
stdTTL:
|
|
25
|
+
new NodeCache({
|
|
26
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
31
27
|
useClones: false
|
|
32
28
|
});
|
|
33
29
|
if (!config.placeholderResendCache) {
|
|
@@ -44,12 +40,12 @@ const makeChatsSocket = (config) => {
|
|
|
44
40
|
tag: 'iq',
|
|
45
41
|
attrs: {
|
|
46
42
|
xmlns: 'privacy',
|
|
47
|
-
to:
|
|
43
|
+
to: S_WHATSAPP_NET,
|
|
48
44
|
type: 'get'
|
|
49
45
|
},
|
|
50
46
|
content: [{ tag: 'privacy', attrs: {} }]
|
|
51
47
|
});
|
|
52
|
-
privacySettings =
|
|
48
|
+
privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
|
|
53
49
|
}
|
|
54
50
|
return privacySettings;
|
|
55
51
|
};
|
|
@@ -59,7 +55,7 @@ const makeChatsSocket = (config) => {
|
|
|
59
55
|
tag: 'iq',
|
|
60
56
|
attrs: {
|
|
61
57
|
xmlns: 'privacy',
|
|
62
|
-
to:
|
|
58
|
+
to: S_WHATSAPP_NET,
|
|
63
59
|
type: 'set'
|
|
64
60
|
},
|
|
65
61
|
content: [
|
|
@@ -105,7 +101,7 @@ const makeChatsSocket = (config) => {
|
|
|
105
101
|
tag: 'iq',
|
|
106
102
|
attrs: {
|
|
107
103
|
xmlns: 'disappearing_mode',
|
|
108
|
-
to:
|
|
104
|
+
to: S_WHATSAPP_NET,
|
|
109
105
|
type: 'set'
|
|
110
106
|
},
|
|
111
107
|
content: [
|
|
@@ -123,7 +119,7 @@ const makeChatsSocket = (config) => {
|
|
|
123
119
|
tag: 'iq',
|
|
124
120
|
attrs: {
|
|
125
121
|
xmlns: 'bot',
|
|
126
|
-
to:
|
|
122
|
+
to: S_WHATSAPP_NET,
|
|
127
123
|
type: 'get'
|
|
128
124
|
},
|
|
129
125
|
content: [
|
|
@@ -135,11 +131,11 @@ const makeChatsSocket = (config) => {
|
|
|
135
131
|
}
|
|
136
132
|
]
|
|
137
133
|
});
|
|
138
|
-
const botNode =
|
|
134
|
+
const botNode = getBinaryNodeChild(resp, 'bot');
|
|
139
135
|
const botList = [];
|
|
140
|
-
for (const section of
|
|
136
|
+
for (const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
141
137
|
if (section.attrs.type === 'all') {
|
|
142
|
-
for (const bot of
|
|
138
|
+
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
143
139
|
botList.push({
|
|
144
140
|
jid: bot.attrs.jid,
|
|
145
141
|
personaId: bot.attrs['persona_id']
|
|
@@ -150,10 +146,10 @@ const makeChatsSocket = (config) => {
|
|
|
150
146
|
return botList;
|
|
151
147
|
};
|
|
152
148
|
const onWhatsApp = async (...jids) => {
|
|
153
|
-
const usyncQuery = new
|
|
149
|
+
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
|
|
154
150
|
for (const jid of jids) {
|
|
155
|
-
const phone = `+${jid.replace('+', '').split('@')[0]
|
|
156
|
-
usyncQuery.withUser(new
|
|
151
|
+
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
152
|
+
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
157
153
|
}
|
|
158
154
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
159
155
|
if (results) {
|
|
@@ -161,9 +157,9 @@ const makeChatsSocket = (config) => {
|
|
|
161
157
|
}
|
|
162
158
|
};
|
|
163
159
|
const fetchStatus = async (...jids) => {
|
|
164
|
-
const usyncQuery = new
|
|
160
|
+
const usyncQuery = new USyncQuery().withStatusProtocol();
|
|
165
161
|
for (const jid of jids) {
|
|
166
|
-
usyncQuery.withUser(new
|
|
162
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
167
163
|
}
|
|
168
164
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
169
165
|
if (result) {
|
|
@@ -171,9 +167,9 @@ const makeChatsSocket = (config) => {
|
|
|
171
167
|
}
|
|
172
168
|
};
|
|
173
169
|
const fetchDisappearingDuration = async (...jids) => {
|
|
174
|
-
const usyncQuery = new
|
|
170
|
+
const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
|
|
175
171
|
for (const jid of jids) {
|
|
176
|
-
usyncQuery.withUser(new
|
|
172
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
177
173
|
}
|
|
178
174
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
179
175
|
if (result) {
|
|
@@ -184,19 +180,22 @@ const makeChatsSocket = (config) => {
|
|
|
184
180
|
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
185
181
|
let targetJid;
|
|
186
182
|
if (!jid) {
|
|
187
|
-
throw new
|
|
183
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
184
|
+
}
|
|
185
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
186
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
188
187
|
}
|
|
189
|
-
|
|
190
|
-
targetJid =
|
|
188
|
+
else {
|
|
189
|
+
targetJid = undefined;
|
|
191
190
|
}
|
|
192
|
-
const { img } = await
|
|
191
|
+
const { img } = await generateProfilePicture(content, dimensions);
|
|
193
192
|
await query({
|
|
194
193
|
tag: 'iq',
|
|
195
194
|
attrs: {
|
|
196
|
-
|
|
197
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
195
|
+
to: S_WHATSAPP_NET,
|
|
198
196
|
type: 'set',
|
|
199
|
-
xmlns: 'w:profile:picture'
|
|
197
|
+
xmlns: 'w:profile:picture',
|
|
198
|
+
...(targetJid ? { target: targetJid } : {})
|
|
200
199
|
},
|
|
201
200
|
content: [
|
|
202
201
|
{
|
|
@@ -211,18 +210,21 @@ const makeChatsSocket = (config) => {
|
|
|
211
210
|
const removeProfilePicture = async (jid) => {
|
|
212
211
|
let targetJid;
|
|
213
212
|
if (!jid) {
|
|
214
|
-
throw new
|
|
213
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
215
214
|
}
|
|
216
|
-
if (
|
|
217
|
-
targetJid =
|
|
215
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
216
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
targetJid = undefined;
|
|
218
220
|
}
|
|
219
221
|
await query({
|
|
220
222
|
tag: 'iq',
|
|
221
223
|
attrs: {
|
|
222
|
-
|
|
223
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
224
|
+
to: S_WHATSAPP_NET,
|
|
224
225
|
type: 'set',
|
|
225
|
-
xmlns: 'w:profile:picture'
|
|
226
|
+
xmlns: 'w:profile:picture',
|
|
227
|
+
...(targetJid ? { target: targetJid } : {})
|
|
226
228
|
}
|
|
227
229
|
});
|
|
228
230
|
};
|
|
@@ -231,7 +233,7 @@ const makeChatsSocket = (config) => {
|
|
|
231
233
|
await query({
|
|
232
234
|
tag: 'iq',
|
|
233
235
|
attrs: {
|
|
234
|
-
to:
|
|
236
|
+
to: S_WHATSAPP_NET,
|
|
235
237
|
type: 'set',
|
|
236
238
|
xmlns: 'status'
|
|
237
239
|
},
|
|
@@ -252,19 +254,19 @@ const makeChatsSocket = (config) => {
|
|
|
252
254
|
tag: 'iq',
|
|
253
255
|
attrs: {
|
|
254
256
|
xmlns: 'blocklist',
|
|
255
|
-
to:
|
|
257
|
+
to: S_WHATSAPP_NET,
|
|
256
258
|
type: 'get'
|
|
257
259
|
}
|
|
258
260
|
});
|
|
259
|
-
const listNode =
|
|
260
|
-
return
|
|
261
|
+
const listNode = getBinaryNodeChild(result, 'list');
|
|
262
|
+
return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
|
|
261
263
|
};
|
|
262
264
|
const updateBlockStatus = async (jid, action) => {
|
|
263
265
|
await query({
|
|
264
266
|
tag: 'iq',
|
|
265
267
|
attrs: {
|
|
266
268
|
xmlns: 'blocklist',
|
|
267
|
-
to:
|
|
269
|
+
to: S_WHATSAPP_NET,
|
|
268
270
|
type: 'set'
|
|
269
271
|
},
|
|
270
272
|
content: [
|
|
@@ -279,7 +281,6 @@ const makeChatsSocket = (config) => {
|
|
|
279
281
|
});
|
|
280
282
|
};
|
|
281
283
|
const getBusinessProfile = async (jid) => {
|
|
282
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
283
284
|
const results = await query({
|
|
284
285
|
tag: 'iq',
|
|
285
286
|
attrs: {
|
|
@@ -300,29 +301,29 @@ const makeChatsSocket = (config) => {
|
|
|
300
301
|
}
|
|
301
302
|
]
|
|
302
303
|
});
|
|
303
|
-
const profileNode =
|
|
304
|
-
const profiles =
|
|
304
|
+
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
305
|
+
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
305
306
|
if (profiles) {
|
|
306
|
-
const address =
|
|
307
|
-
const description =
|
|
308
|
-
const website =
|
|
309
|
-
const email =
|
|
310
|
-
const category =
|
|
311
|
-
const businessHours =
|
|
307
|
+
const address = getBinaryNodeChild(profiles, 'address');
|
|
308
|
+
const description = getBinaryNodeChild(profiles, 'description');
|
|
309
|
+
const website = getBinaryNodeChild(profiles, 'website');
|
|
310
|
+
const email = getBinaryNodeChild(profiles, 'email');
|
|
311
|
+
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
|
|
312
|
+
const businessHours = getBinaryNodeChild(profiles, 'business_hours');
|
|
312
313
|
const businessHoursConfig = businessHours
|
|
313
|
-
?
|
|
314
|
+
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
314
315
|
: undefined;
|
|
315
|
-
const websiteStr =
|
|
316
|
+
const websiteStr = website?.content?.toString();
|
|
316
317
|
return {
|
|
317
|
-
wid:
|
|
318
|
-
address:
|
|
319
|
-
description:
|
|
318
|
+
wid: profiles.attrs?.jid,
|
|
319
|
+
address: address?.content?.toString(),
|
|
320
|
+
description: description?.content?.toString() || '',
|
|
320
321
|
website: websiteStr ? [websiteStr] : [],
|
|
321
|
-
email:
|
|
322
|
-
category:
|
|
322
|
+
email: email?.content?.toString(),
|
|
323
|
+
category: category?.content?.toString(),
|
|
323
324
|
business_hours: {
|
|
324
|
-
timezone:
|
|
325
|
-
business_config: businessHoursConfig
|
|
325
|
+
timezone: businessHours?.attrs?.timezone,
|
|
326
|
+
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
326
327
|
}
|
|
327
328
|
};
|
|
328
329
|
}
|
|
@@ -332,7 +333,7 @@ const makeChatsSocket = (config) => {
|
|
|
332
333
|
await sendNode({
|
|
333
334
|
tag: 'iq',
|
|
334
335
|
attrs: {
|
|
335
|
-
to:
|
|
336
|
+
to: S_WHATSAPP_NET,
|
|
336
337
|
type: 'set',
|
|
337
338
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
338
339
|
id: generateMessageTag()
|
|
@@ -351,7 +352,7 @@ const makeChatsSocket = (config) => {
|
|
|
351
352
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
352
353
|
return {
|
|
353
354
|
onMutation(mutation) {
|
|
354
|
-
|
|
355
|
+
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
355
356
|
}
|
|
356
357
|
};
|
|
357
358
|
};
|
|
@@ -361,7 +362,6 @@ const makeChatsSocket = (config) => {
|
|
|
361
362
|
const initialVersionMap = {};
|
|
362
363
|
const globalMutationMap = {};
|
|
363
364
|
await authState.keys.transaction(async () => {
|
|
364
|
-
var _a;
|
|
365
365
|
const collectionsToHandle = new Set(collections);
|
|
366
366
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
367
367
|
const attemptsMap = {};
|
|
@@ -380,7 +380,7 @@ const makeChatsSocket = (config) => {
|
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
382
|
else {
|
|
383
|
-
state =
|
|
383
|
+
state = newLTHashState();
|
|
384
384
|
}
|
|
385
385
|
states[name] = state;
|
|
386
386
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -397,7 +397,7 @@ const makeChatsSocket = (config) => {
|
|
|
397
397
|
const result = await query({
|
|
398
398
|
tag: 'iq',
|
|
399
399
|
attrs: {
|
|
400
|
-
to:
|
|
400
|
+
to: S_WHATSAPP_NET,
|
|
401
401
|
xmlns: 'w:sync:app:state',
|
|
402
402
|
type: 'set'
|
|
403
403
|
},
|
|
@@ -410,13 +410,13 @@ const makeChatsSocket = (config) => {
|
|
|
410
410
|
]
|
|
411
411
|
});
|
|
412
412
|
// extract from binary node
|
|
413
|
-
const decoded = await
|
|
413
|
+
const decoded = await extractSyncdPatches(result, config?.options);
|
|
414
414
|
for (const key in decoded) {
|
|
415
415
|
const name = key;
|
|
416
416
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
417
417
|
try {
|
|
418
418
|
if (snapshot) {
|
|
419
|
-
const { state: newState, mutationMap } = await
|
|
419
|
+
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
420
420
|
states[name] = newState;
|
|
421
421
|
Object.assign(globalMutationMap, mutationMap);
|
|
422
422
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
@@ -424,7 +424,7 @@ const makeChatsSocket = (config) => {
|
|
|
424
424
|
}
|
|
425
425
|
// only process if there are syncd patches
|
|
426
426
|
if (patches.length) {
|
|
427
|
-
const { state: newState, mutationMap } = await
|
|
427
|
+
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
428
428
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
429
429
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
430
430
|
initialVersionMap[name] = newState.version;
|
|
@@ -442,7 +442,7 @@ const makeChatsSocket = (config) => {
|
|
|
442
442
|
// if retry attempts overshoot
|
|
443
443
|
// or key not found
|
|
444
444
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
445
|
-
|
|
445
|
+
error.output?.statusCode === 404 ||
|
|
446
446
|
error.name === 'TypeError';
|
|
447
447
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
448
448
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
@@ -467,20 +467,19 @@ const makeChatsSocket = (config) => {
|
|
|
467
467
|
* type = "image for the high res picture"
|
|
468
468
|
*/
|
|
469
469
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
470
|
-
|
|
471
|
-
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
470
|
+
jid = jidNormalizedUser(jid);
|
|
472
471
|
const result = await query({
|
|
473
472
|
tag: 'iq',
|
|
474
473
|
attrs: {
|
|
475
474
|
target: jid,
|
|
476
|
-
to:
|
|
475
|
+
to: S_WHATSAPP_NET,
|
|
477
476
|
type: 'get',
|
|
478
477
|
xmlns: 'w:profile:picture'
|
|
479
478
|
},
|
|
480
479
|
content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
|
|
481
480
|
}, timeoutMs);
|
|
482
|
-
const child =
|
|
483
|
-
return
|
|
481
|
+
const child = getBinaryNodeChild(result, 'picture');
|
|
482
|
+
return child?.attrs?.url;
|
|
484
483
|
};
|
|
485
484
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
486
485
|
const me = authState.creds.me;
|
|
@@ -499,7 +498,7 @@ const makeChatsSocket = (config) => {
|
|
|
499
498
|
});
|
|
500
499
|
}
|
|
501
500
|
else {
|
|
502
|
-
const { server } =
|
|
501
|
+
const { server } = jidDecode(toJid);
|
|
503
502
|
const isLid = server === 'lid';
|
|
504
503
|
await sendNode({
|
|
505
504
|
tag: 'chatstate',
|
|
@@ -538,7 +537,6 @@ const makeChatsSocket = (config) => {
|
|
|
538
537
|
: undefined
|
|
539
538
|
});
|
|
540
539
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
541
|
-
var _a;
|
|
542
540
|
let presence;
|
|
543
541
|
const jid = attrs.from;
|
|
544
542
|
const participant = attrs.participant || attrs.from;
|
|
@@ -557,7 +555,7 @@ const makeChatsSocket = (config) => {
|
|
|
557
555
|
if (type === 'paused') {
|
|
558
556
|
type = 'available';
|
|
559
557
|
}
|
|
560
|
-
if (
|
|
558
|
+
if (firstChild.attrs?.media === 'audio') {
|
|
561
559
|
type = 'recording';
|
|
562
560
|
}
|
|
563
561
|
presence = { lastKnownPresence: type };
|
|
@@ -573,7 +571,7 @@ const makeChatsSocket = (config) => {
|
|
|
573
571
|
const name = patchCreate.type;
|
|
574
572
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
575
573
|
if (!myAppStateKeyId) {
|
|
576
|
-
throw new
|
|
574
|
+
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
577
575
|
}
|
|
578
576
|
let initial;
|
|
579
577
|
let encodeResult;
|
|
@@ -582,13 +580,13 @@ const makeChatsSocket = (config) => {
|
|
|
582
580
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
583
581
|
await resyncAppState([name], false);
|
|
584
582
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
585
|
-
initial = currentSyncVersion ||
|
|
586
|
-
encodeResult = await
|
|
583
|
+
initial = currentSyncVersion || newLTHashState();
|
|
584
|
+
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
587
585
|
const { patch, state } = encodeResult;
|
|
588
586
|
const node = {
|
|
589
587
|
tag: 'iq',
|
|
590
588
|
attrs: {
|
|
591
|
-
to:
|
|
589
|
+
to: S_WHATSAPP_NET,
|
|
592
590
|
type: 'set',
|
|
593
591
|
xmlns: 'w:sync:app:state'
|
|
594
592
|
},
|
|
@@ -608,7 +606,7 @@ const makeChatsSocket = (config) => {
|
|
|
608
606
|
{
|
|
609
607
|
tag: 'patch',
|
|
610
608
|
attrs: {},
|
|
611
|
-
content:
|
|
609
|
+
content: proto.SyncdPatch.encode(patch).finish()
|
|
612
610
|
}
|
|
613
611
|
]
|
|
614
612
|
}
|
|
@@ -622,7 +620,7 @@ const makeChatsSocket = (config) => {
|
|
|
622
620
|
});
|
|
623
621
|
if (config.emitOwnEvents) {
|
|
624
622
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
625
|
-
const { mutationMap } = await
|
|
623
|
+
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
626
624
|
for (const key in mutationMap) {
|
|
627
625
|
onMutation(mutationMap[key]);
|
|
628
626
|
}
|
|
@@ -630,11 +628,10 @@ const makeChatsSocket = (config) => {
|
|
|
630
628
|
};
|
|
631
629
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
632
630
|
const fetchProps = async () => {
|
|
633
|
-
var _a, _b, _c;
|
|
634
631
|
const resultNode = await query({
|
|
635
632
|
tag: 'iq',
|
|
636
633
|
attrs: {
|
|
637
|
-
to:
|
|
634
|
+
to: S_WHATSAPP_NET,
|
|
638
635
|
xmlns: 'w',
|
|
639
636
|
type: 'get'
|
|
640
637
|
},
|
|
@@ -643,20 +640,20 @@ const makeChatsSocket = (config) => {
|
|
|
643
640
|
tag: 'props',
|
|
644
641
|
attrs: {
|
|
645
642
|
protocol: '2',
|
|
646
|
-
hash:
|
|
643
|
+
hash: authState?.creds?.lastPropHash || ''
|
|
647
644
|
}
|
|
648
645
|
}
|
|
649
646
|
]
|
|
650
647
|
});
|
|
651
|
-
const propsNode =
|
|
648
|
+
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
652
649
|
let props = {};
|
|
653
650
|
if (propsNode) {
|
|
654
|
-
if (
|
|
651
|
+
if (propsNode.attrs?.hash) {
|
|
655
652
|
// on some clients, the hash is returning as undefined
|
|
656
|
-
authState.creds.lastPropHash =
|
|
653
|
+
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
657
654
|
ev.emit('creds.update', authState.creds);
|
|
658
655
|
}
|
|
659
|
-
props =
|
|
656
|
+
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
660
657
|
}
|
|
661
658
|
logger.debug('fetched props');
|
|
662
659
|
return props;
|
|
@@ -667,9 +664,17 @@ const makeChatsSocket = (config) => {
|
|
|
667
664
|
* requires the last messages till the last message received; required for archive & unread
|
|
668
665
|
*/
|
|
669
666
|
const chatModify = (mod, jid) => {
|
|
670
|
-
const patch =
|
|
667
|
+
const patch = chatModificationToAppPatch(mod, jid);
|
|
671
668
|
return appPatch(patch);
|
|
672
669
|
};
|
|
670
|
+
/**
|
|
671
|
+
* Enable/Disable link preview privacy, not related to baileys link preview generation
|
|
672
|
+
*/
|
|
673
|
+
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
674
|
+
return chatModify({
|
|
675
|
+
disableLinkPreviews: { isPreviewsDisabled }
|
|
676
|
+
}, '');
|
|
677
|
+
};
|
|
673
678
|
/**
|
|
674
679
|
* Star or Unstar a message
|
|
675
680
|
*/
|
|
@@ -757,35 +762,58 @@ const makeChatsSocket = (config) => {
|
|
|
757
762
|
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
758
763
|
};
|
|
759
764
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
760
|
-
var _a, _b, _c;
|
|
761
765
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
762
766
|
if (!!msg.pushName) {
|
|
763
767
|
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
764
|
-
jid =
|
|
768
|
+
jid = jidNormalizedUser(jid);
|
|
765
769
|
if (!msg.key.fromMe) {
|
|
766
770
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
767
771
|
}
|
|
768
772
|
// update our pushname too
|
|
769
|
-
if (msg.key.fromMe && msg.pushName &&
|
|
773
|
+
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
770
774
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
771
775
|
}
|
|
772
776
|
}
|
|
773
|
-
const historyMsg =
|
|
777
|
+
const historyMsg = getHistoryMsg(msg.message);
|
|
774
778
|
const shouldProcessHistoryMsg = historyMsg
|
|
775
|
-
? shouldSyncHistoryMessage(historyMsg) &&
|
|
779
|
+
? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
776
780
|
: false;
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
781
|
+
// State machine: decide on sync and flush
|
|
782
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
783
|
+
if (awaitingSyncTimeout) {
|
|
784
|
+
clearTimeout(awaitingSyncTimeout);
|
|
785
|
+
awaitingSyncTimeout = undefined;
|
|
786
|
+
}
|
|
787
|
+
if (shouldProcessHistoryMsg) {
|
|
788
|
+
syncState = SyncState.Syncing;
|
|
789
|
+
logger.info('Transitioned to Syncing state');
|
|
790
|
+
// Let doAppStateSync handle the final flush after it's done
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
syncState = SyncState.Online;
|
|
794
|
+
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
795
|
+
ev.flush();
|
|
796
|
+
}
|
|
780
797
|
}
|
|
798
|
+
const doAppStateSync = async () => {
|
|
799
|
+
if (syncState === SyncState.Syncing) {
|
|
800
|
+
logger.info('Doing app state sync');
|
|
801
|
+
await resyncAppState(ALL_WA_PATCH_NAMES, true);
|
|
802
|
+
// Sync is complete, go online and flush everything
|
|
803
|
+
syncState = SyncState.Online;
|
|
804
|
+
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
805
|
+
ev.flush();
|
|
806
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
807
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
808
|
+
}
|
|
809
|
+
};
|
|
781
810
|
await Promise.all([
|
|
782
811
|
(async () => {
|
|
783
|
-
if (
|
|
784
|
-
pendingAppStateSync = false;
|
|
812
|
+
if (shouldProcessHistoryMsg) {
|
|
785
813
|
await doAppStateSync();
|
|
786
814
|
}
|
|
787
815
|
})(),
|
|
788
|
-
(
|
|
816
|
+
processMessage(msg, {
|
|
789
817
|
shouldProcessHistoryMsg,
|
|
790
818
|
placeholderResendCache,
|
|
791
819
|
ev,
|
|
@@ -795,27 +823,16 @@ const makeChatsSocket = (config) => {
|
|
|
795
823
|
options: config.options
|
|
796
824
|
})
|
|
797
825
|
]);
|
|
798
|
-
|
|
826
|
+
// If the app state key arrives and we are waiting to sync, trigger the sync now.
|
|
827
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
|
|
828
|
+
logger.info('App state sync key arrived, triggering app state sync');
|
|
799
829
|
await doAppStateSync();
|
|
800
|
-
pendingAppStateSync = false;
|
|
801
|
-
}
|
|
802
|
-
async function doAppStateSync() {
|
|
803
|
-
if (!authState.creds.accountSyncCounter) {
|
|
804
|
-
logger.info('doing initial app state sync');
|
|
805
|
-
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
806
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
807
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
808
|
-
if (needToFlushWithAppStateSync) {
|
|
809
|
-
logger.debug('flushing with app state sync');
|
|
810
|
-
ev.flush();
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
830
|
}
|
|
814
831
|
});
|
|
815
832
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
816
833
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
817
834
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
818
|
-
const { attrs } =
|
|
835
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
819
836
|
const type = attrs.type;
|
|
820
837
|
switch (type) {
|
|
821
838
|
case 'account_sync':
|
|
@@ -837,21 +854,38 @@ const makeChatsSocket = (config) => {
|
|
|
837
854
|
}
|
|
838
855
|
});
|
|
839
856
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
840
|
-
var _a;
|
|
841
857
|
if (connection === 'open') {
|
|
842
858
|
if (fireInitQueries) {
|
|
843
859
|
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
844
860
|
}
|
|
845
861
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
846
862
|
}
|
|
847
|
-
if (receivedPendingNotifications
|
|
848
|
-
|
|
849
|
-
// the key and can sync the messages
|
|
850
|
-
// todo scrutinize
|
|
851
|
-
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
852
|
-
ev.buffer();
|
|
853
|
-
needToFlushWithAppStateSync = true;
|
|
863
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
864
|
+
return;
|
|
854
865
|
}
|
|
866
|
+
syncState = SyncState.AwaitingInitialSync;
|
|
867
|
+
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
868
|
+
ev.buffer();
|
|
869
|
+
const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.fromObject({
|
|
870
|
+
syncType: proto.HistorySync.HistorySyncType.RECENT
|
|
871
|
+
}));
|
|
872
|
+
if (!willSyncHistory) {
|
|
873
|
+
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
874
|
+
syncState = SyncState.Online;
|
|
875
|
+
setTimeout(() => ev.flush(), 0);
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
|
|
879
|
+
if (awaitingSyncTimeout) {
|
|
880
|
+
clearTimeout(awaitingSyncTimeout);
|
|
881
|
+
}
|
|
882
|
+
awaitingSyncTimeout = setTimeout(() => {
|
|
883
|
+
if (syncState === SyncState.AwaitingInitialSync) {
|
|
884
|
+
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
885
|
+
syncState = SyncState.Online;
|
|
886
|
+
ev.flush();
|
|
887
|
+
}
|
|
888
|
+
}, 20000);
|
|
855
889
|
});
|
|
856
890
|
return {
|
|
857
891
|
...sock,
|
|
@@ -872,6 +906,7 @@ const makeChatsSocket = (config) => {
|
|
|
872
906
|
updateProfileStatus,
|
|
873
907
|
updateProfileName,
|
|
874
908
|
updateBlockStatus,
|
|
909
|
+
updateDisableLinkPreviewsPrivacy,
|
|
875
910
|
updateCallPrivacy,
|
|
876
911
|
updateMessagesPrivacy,
|
|
877
912
|
updateLastSeenPrivacy,
|
|
@@ -895,4 +930,4 @@ const makeChatsSocket = (config) => {
|
|
|
895
930
|
star
|
|
896
931
|
};
|
|
897
932
|
};
|
|
898
|
-
|
|
933
|
+
//# sourceMappingURL=chats.js.map
|