@hansaka02/baileys 7.3.2 → 7.3.4
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 +247 -203
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -7
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +219 -172
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +65 -82
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +111 -96
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +8 -14
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
package/lib/Socket/chats.js
CHANGED
|
@@ -1,39 +1,64 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
5
|
+
const { default: NodeCache } = require("@cacheable/node-cache")
|
|
6
|
+
const { Boom } = require("@hapi/boom")
|
|
7
|
+
const { proto } = require("../../WAProto")
|
|
8
|
+
const {
|
|
9
|
+
CALL_VIDEO_PREFIX,
|
|
10
|
+
CALL_AUDIO_PREFIX
|
|
11
|
+
} = require("../Defaults/prefix")
|
|
12
|
+
const { DEFAULT_CACHE_TTLS } = require("../Defaults/constants")
|
|
13
|
+
const { PROCESSABLE_HISTORY_TYPES } = require("../Defaults/history")
|
|
14
|
+
const {
|
|
15
|
+
SyncState,
|
|
16
|
+
ALL_WA_PATCH_NAMES
|
|
17
|
+
} = require("../Types")
|
|
18
|
+
const {
|
|
19
|
+
newLTHashState,
|
|
20
|
+
processSyncAction,
|
|
21
|
+
extractSyncdPatches,
|
|
22
|
+
generateProfilePicture,
|
|
23
|
+
decodeSyncdSnapshot,
|
|
24
|
+
decodePatches,
|
|
25
|
+
encodeSyncdPatch,
|
|
26
|
+
chatModificationToAppPatch,
|
|
27
|
+
getHistoryMsg,
|
|
28
|
+
processMessage
|
|
29
|
+
} = require("../Utils")
|
|
30
|
+
const { makeMutex } = require("../Utils/make-mutex")
|
|
31
|
+
const {
|
|
32
|
+
getBinaryNodeChild,
|
|
33
|
+
getBinaryNodeChildren,
|
|
34
|
+
jidDecode,
|
|
35
|
+
jidNormalizedUser,
|
|
36
|
+
reduceBinaryNodeToDictionary,
|
|
37
|
+
S_WHATSAPP_NET
|
|
38
|
+
} = require("../WABinary")
|
|
39
|
+
const {
|
|
40
|
+
USyncUser,
|
|
41
|
+
USyncQuery
|
|
42
|
+
} = require("../WAUSync")
|
|
43
|
+
const { makeSocket } = require("./socket")
|
|
19
44
|
const MAX_SYNC_ATTEMPTS = 2
|
|
20
45
|
|
|
21
46
|
const makeChatsSocket = (config) => {
|
|
22
47
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config
|
|
23
|
-
const suki =
|
|
48
|
+
const suki = makeSocket(config)
|
|
24
49
|
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, groupFetchAllParticipating } = suki
|
|
25
50
|
|
|
26
51
|
let privacySettings
|
|
27
|
-
let syncState =
|
|
52
|
+
let syncState = SyncState.Connecting
|
|
28
53
|
|
|
29
54
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
30
|
-
const processingMutex =
|
|
55
|
+
const processingMutex = makeMutex()
|
|
31
56
|
|
|
32
57
|
// Timeout for AwaitingInitialSync State
|
|
33
58
|
let awaitingSyncTimeout
|
|
34
59
|
|
|
35
|
-
const placeholderResendCache = config.placeholderResendCache || new
|
|
36
|
-
stdTTL:
|
|
60
|
+
const placeholderResendCache = config.placeholderResendCache || new NodeCache({
|
|
61
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
37
62
|
useClones: false
|
|
38
63
|
})
|
|
39
64
|
|
|
@@ -53,14 +78,14 @@ const makeChatsSocket = (config) => {
|
|
|
53
78
|
tag: 'iq',
|
|
54
79
|
attrs: {
|
|
55
80
|
xmlns: 'privacy',
|
|
56
|
-
to:
|
|
81
|
+
to: S_WHATSAPP_NET,
|
|
57
82
|
type: 'get'
|
|
58
83
|
},
|
|
59
84
|
content: [
|
|
60
85
|
{ tag: 'privacy', attrs: {} }
|
|
61
86
|
]
|
|
62
87
|
})
|
|
63
|
-
privacySettings =
|
|
88
|
+
privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category')
|
|
64
89
|
}
|
|
65
90
|
return privacySettings
|
|
66
91
|
}
|
|
@@ -71,7 +96,7 @@ const makeChatsSocket = (config) => {
|
|
|
71
96
|
tag: 'iq',
|
|
72
97
|
attrs: {
|
|
73
98
|
xmlns: 'privacy',
|
|
74
|
-
to:
|
|
99
|
+
to: S_WHATSAPP_NET,
|
|
75
100
|
type: 'set'
|
|
76
101
|
},
|
|
77
102
|
content: [{
|
|
@@ -124,7 +149,7 @@ const makeChatsSocket = (config) => {
|
|
|
124
149
|
tag: 'iq',
|
|
125
150
|
attrs: {
|
|
126
151
|
xmlns: 'disappearing_mode',
|
|
127
|
-
to:
|
|
152
|
+
to: S_WHATSAPP_NET,
|
|
128
153
|
type: 'set'
|
|
129
154
|
},
|
|
130
155
|
content: [{
|
|
@@ -141,7 +166,7 @@ const makeChatsSocket = (config) => {
|
|
|
141
166
|
tag: 'iq',
|
|
142
167
|
attrs: {
|
|
143
168
|
xmlns: 'bot',
|
|
144
|
-
to:
|
|
169
|
+
to: S_WHATSAPP_NET,
|
|
145
170
|
type: 'get'
|
|
146
171
|
},
|
|
147
172
|
content: [{
|
|
@@ -152,13 +177,13 @@ const makeChatsSocket = (config) => {
|
|
|
152
177
|
}]
|
|
153
178
|
})
|
|
154
179
|
|
|
155
|
-
const botNode =
|
|
180
|
+
const botNode = getBinaryNodeChild(resp, 'bot')
|
|
156
181
|
|
|
157
182
|
const botList = []
|
|
158
183
|
|
|
159
|
-
for(const section of
|
|
184
|
+
for(const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
160
185
|
if(section.attrs.type === 'all') {
|
|
161
|
-
for(const bot of
|
|
186
|
+
for(const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
162
187
|
botList.push({
|
|
163
188
|
jid: bot.attrs.jid,
|
|
164
189
|
personaId: bot.attrs['persona_id']
|
|
@@ -171,16 +196,16 @@ const makeChatsSocket = (config) => {
|
|
|
171
196
|
|
|
172
197
|
const getLidUser = async (jid) => {
|
|
173
198
|
if (!jid) {
|
|
174
|
-
throw new
|
|
199
|
+
throw new Boom('Please input a jid user')
|
|
175
200
|
}
|
|
176
201
|
|
|
177
|
-
if (!
|
|
178
|
-
throw new
|
|
202
|
+
if (!isJidUser(jid)) {
|
|
203
|
+
throw new Boom('Invalid JID: Not a user JID!')
|
|
179
204
|
}
|
|
180
205
|
|
|
181
|
-
const targetJid =
|
|
206
|
+
const targetJid = jidNormalizedUser(jid)
|
|
182
207
|
|
|
183
|
-
const usyncQuery = new
|
|
208
|
+
const usyncQuery = new USyncQuery()
|
|
184
209
|
usyncQuery.protocols.push({
|
|
185
210
|
name: 'lid',
|
|
186
211
|
getQueryElement: () => ({
|
|
@@ -203,10 +228,10 @@ const makeChatsSocket = (config) => {
|
|
|
203
228
|
}
|
|
204
229
|
|
|
205
230
|
const fetchStatus = async (...jids) => {
|
|
206
|
-
const usyncQuery = new
|
|
231
|
+
const usyncQuery = new USyncQuery().withStatusProtocol()
|
|
207
232
|
|
|
208
233
|
for (const jid of jids) {
|
|
209
|
-
usyncQuery.withUser(new
|
|
234
|
+
usyncQuery.withUser(new USyncUser().withId(jid))
|
|
210
235
|
}
|
|
211
236
|
|
|
212
237
|
const result = await suki.executeUSyncQuery(usyncQuery)
|
|
@@ -216,10 +241,10 @@ const makeChatsSocket = (config) => {
|
|
|
216
241
|
}
|
|
217
242
|
}
|
|
218
243
|
const fetchDisappearingDuration = async (...jids) => {
|
|
219
|
-
const usyncQuery = new
|
|
244
|
+
const usyncQuery = new USyncQuery().withDisappearingModeProtocol()
|
|
220
245
|
|
|
221
246
|
for (const jid of jids) {
|
|
222
|
-
usyncQuery.withUser(new
|
|
247
|
+
usyncQuery.withUser(new USyncUser().withId(jid))
|
|
223
248
|
}
|
|
224
249
|
|
|
225
250
|
const result = await suki.executeUSyncQuery(usyncQuery)
|
|
@@ -233,20 +258,20 @@ const makeChatsSocket = (config) => {
|
|
|
233
258
|
let targetJid
|
|
234
259
|
|
|
235
260
|
if (!jid) {
|
|
236
|
-
throw new
|
|
261
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
|
|
237
262
|
}
|
|
238
263
|
|
|
239
|
-
if (
|
|
240
|
-
targetJid =
|
|
264
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
265
|
+
targetJid = jidNormalizedUser(jid) // in case it is someone other than us
|
|
241
266
|
}
|
|
242
267
|
|
|
243
|
-
const { img } = await
|
|
268
|
+
const { img } = await generateProfilePicture(content)
|
|
244
269
|
|
|
245
270
|
await query({
|
|
246
271
|
tag: 'iq',
|
|
247
272
|
attrs: {
|
|
248
273
|
target: targetJid,
|
|
249
|
-
to:
|
|
274
|
+
to: S_WHATSAPP_NET,
|
|
250
275
|
type: 'set',
|
|
251
276
|
xmlns: 'w:profile:picture'
|
|
252
277
|
},
|
|
@@ -265,18 +290,18 @@ const makeChatsSocket = (config) => {
|
|
|
265
290
|
let targetJid
|
|
266
291
|
|
|
267
292
|
if (!jid) {
|
|
268
|
-
throw new
|
|
293
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
|
|
269
294
|
}
|
|
270
295
|
|
|
271
|
-
if (
|
|
272
|
-
targetJid =
|
|
296
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
297
|
+
targetJid = jidNormalizedUser(jid) // in case it is someone other than us
|
|
273
298
|
}
|
|
274
299
|
|
|
275
300
|
await query({
|
|
276
301
|
tag: 'iq',
|
|
277
302
|
attrs: {
|
|
278
303
|
target: targetJid,
|
|
279
|
-
to:
|
|
304
|
+
to: S_WHATSAPP_NET,
|
|
280
305
|
type: 'set',
|
|
281
306
|
xmlns: 'w:profile:picture'
|
|
282
307
|
}
|
|
@@ -288,7 +313,7 @@ const makeChatsSocket = (config) => {
|
|
|
288
313
|
await query({
|
|
289
314
|
tag: 'iq',
|
|
290
315
|
attrs: {
|
|
291
|
-
to:
|
|
316
|
+
to: S_WHATSAPP_NET,
|
|
292
317
|
type: 'set',
|
|
293
318
|
xmlns: 'status'
|
|
294
319
|
},
|
|
@@ -311,14 +336,14 @@ const makeChatsSocket = (config) => {
|
|
|
311
336
|
tag: 'iq',
|
|
312
337
|
attrs: {
|
|
313
338
|
xmlns: 'blocklist',
|
|
314
|
-
to:
|
|
339
|
+
to: S_WHATSAPP_NET,
|
|
315
340
|
type: 'get'
|
|
316
341
|
}
|
|
317
342
|
})
|
|
318
343
|
|
|
319
|
-
const listNode =
|
|
344
|
+
const listNode = getBinaryNodeChild(result, 'list')
|
|
320
345
|
|
|
321
|
-
return
|
|
346
|
+
return getBinaryNodeChildren(listNode, 'item').map((n) => n.attrs.jid)
|
|
322
347
|
}
|
|
323
348
|
|
|
324
349
|
const updateBlockStatus = async (jid, action) => {
|
|
@@ -326,7 +351,7 @@ const makeChatsSocket = (config) => {
|
|
|
326
351
|
tag: 'iq',
|
|
327
352
|
attrs: {
|
|
328
353
|
xmlns: 'blocklist',
|
|
329
|
-
to:
|
|
354
|
+
to: S_WHATSAPP_NET,
|
|
330
355
|
type: 'set'
|
|
331
356
|
},
|
|
332
357
|
content: [
|
|
@@ -359,19 +384,19 @@ const makeChatsSocket = (config) => {
|
|
|
359
384
|
}]
|
|
360
385
|
})
|
|
361
386
|
|
|
362
|
-
const profileNode =
|
|
387
|
+
const profileNode = getBinaryNodeChild(results, 'business_profile')
|
|
363
388
|
|
|
364
|
-
const profiles =
|
|
389
|
+
const profiles = getBinaryNodeChild(profileNode, 'profile')
|
|
365
390
|
|
|
366
391
|
if (profiles) {
|
|
367
|
-
const address =
|
|
368
|
-
const description =
|
|
369
|
-
const website =
|
|
370
|
-
const email =
|
|
371
|
-
const category =
|
|
372
|
-
const businessHours =
|
|
392
|
+
const address = getBinaryNodeChild(profiles, 'address')
|
|
393
|
+
const description = getBinaryNodeChild(profiles, 'description')
|
|
394
|
+
const website = getBinaryNodeChild(profiles, 'website')
|
|
395
|
+
const email = getBinaryNodeChild(profiles, 'email')
|
|
396
|
+
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category')
|
|
397
|
+
const businessHours = getBinaryNodeChild(profiles, 'business_hours')
|
|
373
398
|
const businessHoursConfig = businessHours
|
|
374
|
-
?
|
|
399
|
+
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
375
400
|
: undefined
|
|
376
401
|
const websiteStr = website?.content?.toString()
|
|
377
402
|
|
|
@@ -395,7 +420,7 @@ const makeChatsSocket = (config) => {
|
|
|
395
420
|
await sendNode({
|
|
396
421
|
tag: 'iq',
|
|
397
422
|
attrs: {
|
|
398
|
-
to:
|
|
423
|
+
to: S_WHATSAPP_NET,
|
|
399
424
|
type: 'set',
|
|
400
425
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
401
426
|
id: generateMessageTag(),
|
|
@@ -415,7 +440,7 @@ const makeChatsSocket = (config) => {
|
|
|
415
440
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
416
441
|
return {
|
|
417
442
|
onMutation(mutation) {
|
|
418
|
-
|
|
443
|
+
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger)
|
|
419
444
|
}
|
|
420
445
|
}
|
|
421
446
|
}
|
|
@@ -445,7 +470,7 @@ const makeChatsSocket = (config) => {
|
|
|
445
470
|
}
|
|
446
471
|
}
|
|
447
472
|
else {
|
|
448
|
-
state =
|
|
473
|
+
state = newLTHashState()
|
|
449
474
|
}
|
|
450
475
|
states[name] = state
|
|
451
476
|
logger.info(`resyncing ${name} from v${state.version}`)
|
|
@@ -463,7 +488,7 @@ const makeChatsSocket = (config) => {
|
|
|
463
488
|
const result = await query({
|
|
464
489
|
tag: 'iq',
|
|
465
490
|
attrs: {
|
|
466
|
-
to:
|
|
491
|
+
to: S_WHATSAPP_NET,
|
|
467
492
|
xmlns: 'w:sync:app:state',
|
|
468
493
|
type: 'set'
|
|
469
494
|
},
|
|
@@ -477,14 +502,14 @@ const makeChatsSocket = (config) => {
|
|
|
477
502
|
})
|
|
478
503
|
|
|
479
504
|
// extract from binary node
|
|
480
|
-
const decoded = await
|
|
505
|
+
const decoded = await extractSyncdPatches(result, config?.options)
|
|
481
506
|
|
|
482
507
|
for (const key in decoded) {
|
|
483
508
|
const name = key
|
|
484
509
|
const { patches, hasMorePatches, snapshot } = decoded[name]
|
|
485
510
|
try {
|
|
486
511
|
if (snapshot) {
|
|
487
|
-
const { state: newState, mutationMap } = await
|
|
512
|
+
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
|
|
488
513
|
states[name] = newState
|
|
489
514
|
Object.assign(globalMutationMap, mutationMap)
|
|
490
515
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`)
|
|
@@ -493,7 +518,7 @@ const makeChatsSocket = (config) => {
|
|
|
493
518
|
|
|
494
519
|
// only process if there are syncd patches
|
|
495
520
|
if (patches.length) {
|
|
496
|
-
const { state: newState, mutationMap } = await
|
|
521
|
+
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch)
|
|
497
522
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
|
|
498
523
|
logger.info(`synced ${name} to v${newState.version}`)
|
|
499
524
|
initialVersionMap[name] = newState.version
|
|
@@ -562,10 +587,10 @@ const makeChatsSocket = (config) => {
|
|
|
562
587
|
}]
|
|
563
588
|
}, timeoutMs)
|
|
564
589
|
|
|
565
|
-
const child =
|
|
590
|
+
const child = getBinaryNodeChild(result, 'link_create')
|
|
566
591
|
const token = child?.attrs?.token
|
|
567
592
|
|
|
568
|
-
return type === 'audio' ?
|
|
593
|
+
return type === 'audio' ? CALL_AUDIO_PREFIX + token : CALL_VIDEO_PREFIX + token
|
|
569
594
|
}
|
|
570
595
|
|
|
571
596
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
@@ -587,7 +612,7 @@ const makeChatsSocket = (config) => {
|
|
|
587
612
|
})
|
|
588
613
|
}
|
|
589
614
|
else {
|
|
590
|
-
const { server } =
|
|
615
|
+
const { server } = jidDecode(toJid)
|
|
591
616
|
|
|
592
617
|
await sendNode({
|
|
593
618
|
tag: 'chatstate',
|
|
@@ -672,7 +697,7 @@ const makeChatsSocket = (config) => {
|
|
|
672
697
|
const myAppStateKeyId = authState.creds.myAppStateKeyId
|
|
673
698
|
|
|
674
699
|
if (!myAppStateKeyId) {
|
|
675
|
-
throw new
|
|
700
|
+
throw new Boom('App state key not present!', { statusCode: 400 })
|
|
676
701
|
}
|
|
677
702
|
|
|
678
703
|
let initial
|
|
@@ -683,14 +708,14 @@ const makeChatsSocket = (config) => {
|
|
|
683
708
|
logger.debug({ patch: patchCreate }, 'applying app patch')
|
|
684
709
|
await resyncAppState([name], false)
|
|
685
710
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name])
|
|
686
|
-
initial = currentSyncVersion ||
|
|
687
|
-
encodeResult = await
|
|
711
|
+
initial = currentSyncVersion || newLTHashState()
|
|
712
|
+
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey)
|
|
688
713
|
const { patch, state } = encodeResult
|
|
689
714
|
|
|
690
715
|
const node = {
|
|
691
716
|
tag: 'iq',
|
|
692
717
|
attrs: {
|
|
693
|
-
to:
|
|
718
|
+
to: S_WHATSAPP_NET,
|
|
694
719
|
type: 'set',
|
|
695
720
|
xmlns: 'w:sync:app:state'
|
|
696
721
|
},
|
|
@@ -710,7 +735,7 @@ const makeChatsSocket = (config) => {
|
|
|
710
735
|
{
|
|
711
736
|
tag: 'patch',
|
|
712
737
|
attrs: {},
|
|
713
|
-
content:
|
|
738
|
+
content: proto.SyncdPatch.encode(patch).finish()
|
|
714
739
|
}
|
|
715
740
|
]
|
|
716
741
|
}
|
|
@@ -725,7 +750,7 @@ const makeChatsSocket = (config) => {
|
|
|
725
750
|
|
|
726
751
|
if (config.emitOwnEvents) {
|
|
727
752
|
const { onMutation } = newAppStateChunkHandler(false)
|
|
728
|
-
const { mutationMap } = await
|
|
753
|
+
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger)
|
|
729
754
|
|
|
730
755
|
for (const key in mutationMap) {
|
|
731
756
|
onMutation(mutationMap[key])
|
|
@@ -738,7 +763,7 @@ const makeChatsSocket = (config) => {
|
|
|
738
763
|
const resultNode = await query({
|
|
739
764
|
tag: 'iq',
|
|
740
765
|
attrs: {
|
|
741
|
-
to:
|
|
766
|
+
to: S_WHATSAPP_NET,
|
|
742
767
|
xmlns: 'w',
|
|
743
768
|
type: 'get',
|
|
744
769
|
},
|
|
@@ -750,7 +775,7 @@ const makeChatsSocket = (config) => {
|
|
|
750
775
|
]
|
|
751
776
|
})
|
|
752
777
|
|
|
753
|
-
const propsNode =
|
|
778
|
+
const propsNode = getBinaryNodeChild(resultNode, 'props')
|
|
754
779
|
let props = {}
|
|
755
780
|
|
|
756
781
|
if (propsNode) {
|
|
@@ -759,7 +784,7 @@ const makeChatsSocket = (config) => {
|
|
|
759
784
|
ev.emit('creds.update', authState.creds)
|
|
760
785
|
}
|
|
761
786
|
|
|
762
|
-
props =
|
|
787
|
+
props = reduceBinaryNodeToDictionary(propsNode, 'prop')
|
|
763
788
|
}
|
|
764
789
|
logger.debug('fetched props')
|
|
765
790
|
return props
|
|
@@ -771,7 +796,7 @@ const makeChatsSocket = (config) => {
|
|
|
771
796
|
* requires the last messages till the last message received required for archive & unread
|
|
772
797
|
*/
|
|
773
798
|
const chatModify = (mod, jid) => {
|
|
774
|
-
const patch =
|
|
799
|
+
const patch = chatModificationToAppPatch(mod, jid)
|
|
775
800
|
return appPatch(patch)
|
|
776
801
|
}
|
|
777
802
|
|
|
@@ -920,7 +945,7 @@ const makeChatsSocket = (config) => {
|
|
|
920
945
|
ev.emit('messages.upsert', { messages: [msg], type })
|
|
921
946
|
if (!!msg.pushName) {
|
|
922
947
|
let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid)
|
|
923
|
-
jid =
|
|
948
|
+
jid = jidNormalizedUser(jid)
|
|
924
949
|
|
|
925
950
|
if (!msg.key.fromMe) {
|
|
926
951
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }])
|
|
@@ -932,36 +957,36 @@ const makeChatsSocket = (config) => {
|
|
|
932
957
|
}
|
|
933
958
|
}
|
|
934
959
|
|
|
935
|
-
const historyMsg =
|
|
960
|
+
const historyMsg = getHistoryMsg(msg.message)
|
|
936
961
|
const shouldProcessHistoryMsg = historyMsg
|
|
937
962
|
? (shouldSyncHistoryMessage(historyMsg)
|
|
938
|
-
&&
|
|
963
|
+
&& PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
939
964
|
: false
|
|
940
965
|
|
|
941
|
-
if (historyMsg && syncState ===
|
|
966
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
942
967
|
if (awaitingSyncTimeout) {
|
|
943
968
|
clearTimeout(awaitingSyncTimeout)
|
|
944
969
|
awaitingSyncTimeout = undefined
|
|
945
970
|
}
|
|
946
971
|
|
|
947
972
|
if (shouldProcessHistoryMsg) {
|
|
948
|
-
syncState =
|
|
973
|
+
syncState = SyncState.Syncing
|
|
949
974
|
logger.info('Transitioned to Syncing state')
|
|
950
975
|
// Let doAppStateSync handle the final flush after it`s done
|
|
951
976
|
} else {
|
|
952
|
-
syncState =
|
|
977
|
+
syncState = SyncState.Online
|
|
953
978
|
logger.info('History sync skipped, transitioning to Online state and flushing buffer')
|
|
954
979
|
ev.flush()
|
|
955
980
|
}
|
|
956
981
|
}
|
|
957
982
|
|
|
958
983
|
const doAppStateSync = async () => {
|
|
959
|
-
if (syncState ===
|
|
984
|
+
if (syncState === SyncState.Syncing) {
|
|
960
985
|
logger.info('Doing app state sync')
|
|
961
|
-
await resyncAppState(
|
|
986
|
+
await resyncAppState(ALL_WA_PATCH_NAMES, true)
|
|
962
987
|
|
|
963
988
|
// Sync is complete, go online and flush everything
|
|
964
|
-
syncState =
|
|
989
|
+
syncState = SyncState.Online
|
|
965
990
|
logger.info('App state sync complete, transitioning to Online state and flushing buffer')
|
|
966
991
|
ev.flush()
|
|
967
992
|
|
|
@@ -976,7 +1001,7 @@ const makeChatsSocket = (config) => {
|
|
|
976
1001
|
await doAppStateSync()
|
|
977
1002
|
}
|
|
978
1003
|
})(),
|
|
979
|
-
|
|
1004
|
+
processMessage(msg, {
|
|
980
1005
|
signalRepository,
|
|
981
1006
|
shouldProcessHistoryMsg,
|
|
982
1007
|
placeholderResendCache,
|
|
@@ -989,7 +1014,7 @@ const makeChatsSocket = (config) => {
|
|
|
989
1014
|
})
|
|
990
1015
|
])
|
|
991
1016
|
|
|
992
|
-
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState ===
|
|
1017
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
|
|
993
1018
|
logger.info('App state sync key arrived, triggering app state sync')
|
|
994
1019
|
await doAppStateSync()
|
|
995
1020
|
}
|
|
@@ -998,7 +1023,7 @@ const makeChatsSocket = (config) => {
|
|
|
998
1023
|
ws.on('CB:presence', handlePresenceUpdate)
|
|
999
1024
|
ws.on('CB:chatstate', handlePresenceUpdate)
|
|
1000
1025
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
1001
|
-
const { attrs } =
|
|
1026
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty')
|
|
1002
1027
|
const type = attrs.type
|
|
1003
1028
|
|
|
1004
1029
|
switch (type) {
|
|
@@ -1032,21 +1057,21 @@ const makeChatsSocket = (config) => {
|
|
|
1032
1057
|
.catch(error => onUnexpectedError(error, 'presence update requests'))
|
|
1033
1058
|
}
|
|
1034
1059
|
|
|
1035
|
-
if (!receivedPendingNotifications || syncState !==
|
|
1060
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
1036
1061
|
return
|
|
1037
1062
|
}
|
|
1038
1063
|
|
|
1039
|
-
syncState =
|
|
1064
|
+
syncState = SyncState.AwaitingInitialSync
|
|
1040
1065
|
logger.info('Connection is now AwaitingInitialSync, buffering events')
|
|
1041
1066
|
ev.buffer()
|
|
1042
1067
|
|
|
1043
|
-
const willSyncHistory = shouldSyncHistoryMessage(
|
|
1044
|
-
syncType:
|
|
1068
|
+
const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.fromObject({
|
|
1069
|
+
syncType: proto.HistorySync.HistorySyncType.RECENT
|
|
1045
1070
|
}))
|
|
1046
1071
|
|
|
1047
1072
|
if (!willSyncHistory) {
|
|
1048
1073
|
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.')
|
|
1049
|
-
syncState =
|
|
1074
|
+
syncState = SyncState.Online
|
|
1050
1075
|
setTimeout(() => ev.flush(), 0)
|
|
1051
1076
|
return
|
|
1052
1077
|
}
|
|
@@ -1058,9 +1083,9 @@ const makeChatsSocket = (config) => {
|
|
|
1058
1083
|
}
|
|
1059
1084
|
|
|
1060
1085
|
awaitingSyncTimeout = setTimeout(() => {
|
|
1061
|
-
if (syncState ===
|
|
1086
|
+
if (syncState === SyncState.AwaitingInitialSync) {
|
|
1062
1087
|
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer')
|
|
1063
|
-
syncState =
|
|
1088
|
+
syncState = SyncState.Online
|
|
1064
1089
|
ev.flush()
|
|
1065
1090
|
}
|
|
1066
1091
|
}, 20_000)
|