@hbmodsofc/baileys 1.7.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/WAProto/index.js +157084 -24729
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +8 -12
- package/lib/Defaults/index.js +124 -90
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/group_cipher.d.ts +1 -0
- package/lib/Signal/Group/group_cipher.js +39 -28
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +2 -9
- package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.js +16 -47
- package/lib/Signal/libsignal.d.ts +3 -7
- package/lib/Signal/libsignal.js +39 -224
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
- package/lib/Socket/business.d.ts +78 -94
- package/lib/Socket/business.js +11 -130
- package/lib/Socket/chats.d.ts +233 -63
- package/lib/Socket/chats.js +184 -234
- package/lib/Socket/groups.d.ts +41 -62
- package/lib/Socket/groups.js +64 -76
- package/lib/Socket/hbmods.d.ts +253 -0
- package/lib/Socket/hbmods.js +1 -0
- package/lib/Socket/index.d.ts +83 -129
- package/lib/Socket/index.js +6 -13
- package/lib/Socket/messages-recv.d.ts +48 -59
- package/lib/Socket/messages-recv.js +371 -516
- package/lib/Socket/messages-send.d.ts +67 -86
- package/lib/Socket/messages-send.js +1 -1091
- package/lib/Socket/newsletter.d.ts +64 -76
- package/lib/Socket/newsletter.js +1 -184
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +13 -19
- package/lib/Socket/socket.js +1 -805
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Types/Auth.d.ts +10 -4
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +9 -29
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +14 -55
- package/lib/Types/GroupMetadata.d.ts +5 -15
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +49 -75
- package/lib/Types/Message.js +7 -10
- package/lib/Types/Newsletter.d.ts +98 -129
- package/lib/Types/Newsletter.js +38 -33
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +1 -29
- package/lib/Types/Socket.d.ts +22 -48
- package/lib/Types/State.d.ts +2 -13
- package/lib/Types/State.js +0 -12
- package/lib/Types/USync.d.ts +1 -1
- package/lib/Types/index.d.ts +3 -10
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +102 -378
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +13 -19
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +154 -201
- package/lib/Utils/crypto.d.ts +19 -18
- package/lib/Utils/crypto.js +37 -78
- package/lib/Utils/decode-wa-message.d.ts +7 -34
- package/lib/Utils/decode-wa-message.js +66 -138
- package/lib/Utils/event-buffer.d.ts +8 -6
- package/lib/Utils/event-buffer.js +43 -81
- package/lib/Utils/generics.d.ts +27 -27
- package/lib/Utils/generics.js +133 -128
- package/lib/Utils/history.d.ts +5 -9
- package/lib/Utils/history.js +23 -17
- package/lib/Utils/index.d.ts +0 -2
- package/lib/Utils/index.js +0 -2
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.js +12 -40
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/lt-hash.d.ts +8 -8
- package/lib/Utils/lt-hash.js +24 -23
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +2 -3
- package/lib/Utils/messages-media.d.ts +41 -37
- package/lib/Utils/messages-media.js +368 -252
- package/lib/Utils/messages.d.ts +15 -13
- package/lib/Utils/messages.js +261 -274
- package/lib/Utils/noise-handler.d.ts +15 -13
- package/lib/Utils/noise-handler.js +26 -20
- package/lib/Utils/process-message.d.ts +8 -9
- package/lib/Utils/process-message.js +93 -157
- package/lib/Utils/signal.d.ts +5 -6
- package/lib/Utils/signal.js +29 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.js +7 -12
- package/lib/Utils/validate-connection.d.ts +6 -5
- package/lib/Utils/validate-connection.js +97 -39
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +14 -28
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +7 -4
- package/lib/WABinary/generic-utils.js +125 -40
- package/lib/WABinary/jid-utils.d.ts +8 -13
- package/lib/WABinary/jid-utils.js +16 -27
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/constants.js +2359 -2252
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.js +11 -8
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
- package/lib/WAUSync/USyncQuery.d.ts +2 -2
- package/lib/WAUSync/USyncQuery.js +15 -19
- package/lib/WAUSync/USyncUser.d.ts +5 -5
- package/lib/WAUSync/index.d.ts +1 -1
- package/lib/WAUSync/index.js +1 -1
- package/package.json +102 -104
- package/lib/Signal/lid-mapping.d.ts +0 -26
- package/lib/Signal/lid-mapping.js +0 -146
- package/lib/Socket/communities.d.ts +0 -232
- package/lib/Socket/communities.js +0 -402
- package/lib/Socket/mex.d.ts +0 -2
- package/lib/Socket/mex.js +0 -45
- package/lib/Types/Bussines.d.ts +0 -24
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/lidToJid-test.d.ts +0 -11
- package/lib/Utils/lidToJid-test.js +0 -27
- package/lib/Utils/message-retry-manager.d.ts +0 -81
- package/lib/Utils/message-retry-manager.js +0 -152
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Socket/chats.js
CHANGED
|
@@ -4,38 +4,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeChatsSocket = void 0;
|
|
7
|
-
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
8
7
|
const boom_1 = require("@hapi/boom");
|
|
9
|
-
const
|
|
8
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
9
|
+
const WAProto_1 = require("../../WAProto");
|
|
10
10
|
const Defaults_1 = require("../Defaults");
|
|
11
11
|
const Types_1 = require("../Types");
|
|
12
|
-
const State_1 = require("../Types/State");
|
|
13
12
|
const Utils_1 = require("../Utils");
|
|
14
13
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
15
14
|
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
16
15
|
const WABinary_1 = require("../WABinary");
|
|
17
16
|
const WAUSync_1 = require("../WAUSync");
|
|
18
|
-
const
|
|
17
|
+
const usync_1 = require("./usync");
|
|
18
|
+
const chalk = require('chalk');
|
|
19
19
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
20
|
+
const SyncState = {
|
|
21
|
+
Connecting: 'connecting',
|
|
22
|
+
AwaitingInitialSync: 'awaiting_initial_sync',
|
|
23
|
+
Syncing: 'syncing',
|
|
24
|
+
Online: 'online'
|
|
25
|
+
};
|
|
20
26
|
const makeChatsSocket = (config) => {
|
|
21
|
-
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
22
|
-
const sock = (0,
|
|
23
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError } = sock;
|
|
27
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
28
|
+
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
29
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
|
|
24
30
|
let privacySettings;
|
|
25
|
-
let syncState =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// Timeout for AwaitingInitialSync state
|
|
31
|
+
let syncState = SyncState.Connecting;
|
|
32
|
+
let needToFlushWithAppStateSync = false;
|
|
33
|
+
let pendingAppStateSync = false;
|
|
29
34
|
let awaitingSyncTimeout;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
36
|
+
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
37
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
38
|
+
useClones: false
|
|
39
|
+
});
|
|
35
40
|
if (!config.placeholderResendCache) {
|
|
36
41
|
config.placeholderResendCache = placeholderResendCache;
|
|
37
42
|
}
|
|
38
|
-
/** helper function to fetch the given app state sync key */
|
|
39
43
|
const getAppStateSyncKey = async (keyId) => {
|
|
40
44
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
41
45
|
return key;
|
|
@@ -49,13 +53,14 @@ const makeChatsSocket = (config) => {
|
|
|
49
53
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
50
54
|
type: 'get'
|
|
51
55
|
},
|
|
52
|
-
content: [
|
|
56
|
+
content: [
|
|
57
|
+
{ tag: 'privacy', attrs: {} }
|
|
58
|
+
]
|
|
53
59
|
});
|
|
54
|
-
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content
|
|
60
|
+
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
55
61
|
}
|
|
56
62
|
return privacySettings;
|
|
57
63
|
};
|
|
58
|
-
/** helper function to run a privacy IQ query */
|
|
59
64
|
const privacyQuery = async (name, value) => {
|
|
60
65
|
await query({
|
|
61
66
|
tag: 'iq',
|
|
@@ -64,8 +69,7 @@ const makeChatsSocket = (config) => {
|
|
|
64
69
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
65
70
|
type: 'set'
|
|
66
71
|
},
|
|
67
|
-
content: [
|
|
68
|
-
{
|
|
72
|
+
content: [{
|
|
69
73
|
tag: 'privacy',
|
|
70
74
|
attrs: {},
|
|
71
75
|
content: [
|
|
@@ -74,8 +78,7 @@ const makeChatsSocket = (config) => {
|
|
|
74
78
|
attrs: { name, value }
|
|
75
79
|
}
|
|
76
80
|
]
|
|
77
|
-
}
|
|
78
|
-
]
|
|
81
|
+
}]
|
|
79
82
|
});
|
|
80
83
|
};
|
|
81
84
|
const updateMessagesPrivacy = async (value) => {
|
|
@@ -102,6 +105,9 @@ const makeChatsSocket = (config) => {
|
|
|
102
105
|
const updateGroupsAddPrivacy = async (value) => {
|
|
103
106
|
await privacyQuery('groupadd', value);
|
|
104
107
|
};
|
|
108
|
+
const updateDisableLinkPreviewsPrivacy = async (isPreviewsDisabled) => {
|
|
109
|
+
return chatModify({ disableLinkPreviews: { isPreviewsDisabled } }, '');
|
|
110
|
+
};
|
|
105
111
|
const updateDefaultDisappearingMode = async (duration) => {
|
|
106
112
|
await query({
|
|
107
113
|
tag: 'iq',
|
|
@@ -110,14 +116,12 @@ const makeChatsSocket = (config) => {
|
|
|
110
116
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
111
117
|
type: 'set'
|
|
112
118
|
},
|
|
113
|
-
content: [
|
|
114
|
-
{
|
|
119
|
+
content: [{
|
|
115
120
|
tag: 'disappearing_mode',
|
|
116
121
|
attrs: {
|
|
117
122
|
duration: duration.toString()
|
|
118
123
|
}
|
|
119
|
-
}
|
|
120
|
-
]
|
|
124
|
+
}]
|
|
121
125
|
});
|
|
122
126
|
};
|
|
123
127
|
const getBotListV2 = async () => {
|
|
@@ -128,14 +132,12 @@ const makeChatsSocket = (config) => {
|
|
|
128
132
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
129
133
|
type: 'get'
|
|
130
134
|
},
|
|
131
|
-
content: [
|
|
132
|
-
{
|
|
135
|
+
content: [{
|
|
133
136
|
tag: 'bot',
|
|
134
137
|
attrs: {
|
|
135
138
|
v: '2'
|
|
136
139
|
}
|
|
137
|
-
}
|
|
138
|
-
]
|
|
140
|
+
}]
|
|
139
141
|
});
|
|
140
142
|
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
141
143
|
const botList = [];
|
|
@@ -151,8 +153,22 @@ const makeChatsSocket = (config) => {
|
|
|
151
153
|
}
|
|
152
154
|
return botList;
|
|
153
155
|
};
|
|
156
|
+
const onWhatsApp = async (...jids) => {
|
|
157
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
158
|
+
.withContactProtocol()
|
|
159
|
+
.withLIDProtocol();
|
|
160
|
+
for (const jid of jids) {
|
|
161
|
+
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
162
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
163
|
+
}
|
|
164
|
+
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
165
|
+
if (results) {
|
|
166
|
+
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
167
|
+
}
|
|
168
|
+
};
|
|
154
169
|
const fetchStatus = async (...jids) => {
|
|
155
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
170
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
171
|
+
.withStatusProtocol();
|
|
156
172
|
for (const jid of jids) {
|
|
157
173
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
158
174
|
}
|
|
@@ -162,7 +178,8 @@ const makeChatsSocket = (config) => {
|
|
|
162
178
|
}
|
|
163
179
|
};
|
|
164
180
|
const fetchDisappearingDuration = async (...jids) => {
|
|
165
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
181
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
182
|
+
.withDisappearingModeProtocol();
|
|
166
183
|
for (const jid of jids) {
|
|
167
184
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
168
185
|
}
|
|
@@ -171,26 +188,22 @@ const makeChatsSocket = (config) => {
|
|
|
171
188
|
return result.list;
|
|
172
189
|
}
|
|
173
190
|
};
|
|
174
|
-
/** update the profile picture for yourself or a group */
|
|
175
191
|
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
176
192
|
let targetJid;
|
|
177
193
|
if (!jid) {
|
|
178
194
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
179
195
|
}
|
|
180
196
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
181
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
targetJid = undefined;
|
|
197
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
185
198
|
}
|
|
186
199
|
const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
|
|
187
200
|
await query({
|
|
188
201
|
tag: 'iq',
|
|
189
202
|
attrs: {
|
|
203
|
+
target: targetJid,
|
|
190
204
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
191
205
|
type: 'set',
|
|
192
|
-
xmlns: 'w:profile:picture'
|
|
193
|
-
...(targetJid ? { target: targetJid } : {})
|
|
206
|
+
xmlns: 'w:profile:picture'
|
|
194
207
|
},
|
|
195
208
|
content: [
|
|
196
209
|
{
|
|
@@ -201,29 +214,24 @@ const makeChatsSocket = (config) => {
|
|
|
201
214
|
]
|
|
202
215
|
});
|
|
203
216
|
};
|
|
204
|
-
/** remove the profile picture for yourself or a group */
|
|
205
217
|
const removeProfilePicture = async (jid) => {
|
|
206
218
|
let targetJid;
|
|
207
219
|
if (!jid) {
|
|
208
220
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
209
221
|
}
|
|
210
222
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
211
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
targetJid = undefined;
|
|
223
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
215
224
|
}
|
|
216
225
|
await query({
|
|
217
226
|
tag: 'iq',
|
|
218
227
|
attrs: {
|
|
228
|
+
target: targetJid,
|
|
219
229
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
220
230
|
type: 'set',
|
|
221
|
-
xmlns: 'w:profile:picture'
|
|
222
|
-
...(targetJid ? { target: targetJid } : {})
|
|
231
|
+
xmlns: 'w:profile:picture'
|
|
223
232
|
}
|
|
224
233
|
});
|
|
225
234
|
};
|
|
226
|
-
/** update the profile status for yourself */
|
|
227
235
|
const updateProfileStatus = async (status) => {
|
|
228
236
|
await query({
|
|
229
237
|
tag: 'iq',
|
|
@@ -254,7 +262,8 @@ const makeChatsSocket = (config) => {
|
|
|
254
262
|
}
|
|
255
263
|
});
|
|
256
264
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
257
|
-
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
265
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
266
|
+
.map(n => n.attrs.jid);
|
|
258
267
|
};
|
|
259
268
|
const updateBlockStatus = async (jid, action) => {
|
|
260
269
|
await query({
|
|
@@ -276,6 +285,7 @@ const makeChatsSocket = (config) => {
|
|
|
276
285
|
});
|
|
277
286
|
};
|
|
278
287
|
const getBusinessProfile = async (jid) => {
|
|
288
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
279
289
|
const results = await query({
|
|
280
290
|
tag: 'iq',
|
|
281
291
|
attrs: {
|
|
@@ -283,18 +293,14 @@ const makeChatsSocket = (config) => {
|
|
|
283
293
|
xmlns: 'w:biz',
|
|
284
294
|
type: 'get'
|
|
285
295
|
},
|
|
286
|
-
content: [
|
|
287
|
-
{
|
|
296
|
+
content: [{
|
|
288
297
|
tag: 'business_profile',
|
|
289
298
|
attrs: { v: '244' },
|
|
290
|
-
content: [
|
|
291
|
-
{
|
|
299
|
+
content: [{
|
|
292
300
|
tag: 'profile',
|
|
293
301
|
attrs: { jid }
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
]
|
|
302
|
+
}]
|
|
303
|
+
}]
|
|
298
304
|
});
|
|
299
305
|
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
300
306
|
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
@@ -308,17 +314,17 @@ const makeChatsSocket = (config) => {
|
|
|
308
314
|
const businessHoursConfig = businessHours
|
|
309
315
|
? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
|
|
310
316
|
: undefined;
|
|
311
|
-
const websiteStr = website
|
|
317
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
312
318
|
return {
|
|
313
|
-
wid: profiles.attrs
|
|
314
|
-
address: address
|
|
315
|
-
description: description
|
|
319
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
320
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
321
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
316
322
|
website: websiteStr ? [websiteStr] : [],
|
|
317
|
-
email: email
|
|
318
|
-
category: category
|
|
319
|
-
business_hours: {
|
|
320
|
-
timezone: businessHours
|
|
321
|
-
business_config: businessHoursConfig
|
|
323
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
324
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
325
|
+
'business_hours': {
|
|
326
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
327
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
322
328
|
}
|
|
323
329
|
};
|
|
324
330
|
}
|
|
@@ -331,14 +337,14 @@ const makeChatsSocket = (config) => {
|
|
|
331
337
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
332
338
|
type: 'set',
|
|
333
339
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
334
|
-
id: generateMessageTag()
|
|
340
|
+
id: generateMessageTag(),
|
|
335
341
|
},
|
|
336
342
|
content: [
|
|
337
343
|
{
|
|
338
344
|
tag: 'clean',
|
|
339
345
|
attrs: {
|
|
340
346
|
type,
|
|
341
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
347
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
|
|
342
348
|
}
|
|
343
349
|
}
|
|
344
350
|
]
|
|
@@ -352,17 +358,12 @@ const makeChatsSocket = (config) => {
|
|
|
352
358
|
};
|
|
353
359
|
};
|
|
354
360
|
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
355
|
-
// we use this to determine which events to fire
|
|
356
|
-
// otherwise when we resync from scratch -- all notifications will fire
|
|
357
361
|
const initialVersionMap = {};
|
|
358
362
|
const globalMutationMap = {};
|
|
359
363
|
await authState.keys.transaction(async () => {
|
|
364
|
+
var _a;
|
|
360
365
|
const collectionsToHandle = new Set(collections);
|
|
361
|
-
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
362
366
|
const attemptsMap = {};
|
|
363
|
-
// keep executing till all collections are done
|
|
364
|
-
// sometimes a single patch request will not return all the patches (God knows why)
|
|
365
|
-
// so we fetch till they're all done (this is determined by the "has_more_patches" flag)
|
|
366
367
|
while (collectionsToHandle.size) {
|
|
367
368
|
const states = {};
|
|
368
369
|
const nodes = [];
|
|
@@ -384,8 +385,7 @@ const makeChatsSocket = (config) => {
|
|
|
384
385
|
attrs: {
|
|
385
386
|
name,
|
|
386
387
|
version: state.version.toString(),
|
|
387
|
-
|
|
388
|
-
return_snapshot: (!state.version).toString()
|
|
388
|
+
'return_snapshot': (!state.version).toString()
|
|
389
389
|
}
|
|
390
390
|
});
|
|
391
391
|
}
|
|
@@ -404,8 +404,7 @@ const makeChatsSocket = (config) => {
|
|
|
404
404
|
}
|
|
405
405
|
]
|
|
406
406
|
});
|
|
407
|
-
|
|
408
|
-
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config?.options);
|
|
407
|
+
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
409
408
|
for (const key in decoded) {
|
|
410
409
|
const name = key;
|
|
411
410
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
@@ -417,7 +416,6 @@ const makeChatsSocket = (config) => {
|
|
|
417
416
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
418
417
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
419
418
|
}
|
|
420
|
-
// only process if there are syncd patches
|
|
421
419
|
if (patches.length) {
|
|
422
420
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
423
421
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
@@ -429,52 +427,60 @@ const makeChatsSocket = (config) => {
|
|
|
429
427
|
logger.info(`${name} has more patches...`);
|
|
430
428
|
}
|
|
431
429
|
else {
|
|
432
|
-
// collection is done with sync
|
|
433
430
|
collectionsToHandle.delete(name);
|
|
434
431
|
}
|
|
435
432
|
}
|
|
436
433
|
catch (error) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
error.output?.statusCode === 404 ||
|
|
441
|
-
error.name === 'TypeError';
|
|
434
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
435
|
+
|| ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
|
|
436
|
+
|| error.name === 'TypeError';
|
|
442
437
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
443
438
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
444
|
-
// increment number of retries
|
|
445
439
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
446
440
|
if (isIrrecoverableError) {
|
|
447
|
-
// stop retrying
|
|
448
441
|
collectionsToHandle.delete(name);
|
|
449
442
|
}
|
|
450
443
|
}
|
|
451
444
|
}
|
|
452
445
|
}
|
|
453
|
-
}
|
|
446
|
+
});
|
|
454
447
|
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
455
448
|
for (const key in globalMutationMap) {
|
|
456
449
|
onMutation(globalMutationMap[key]);
|
|
457
450
|
}
|
|
458
451
|
});
|
|
459
|
-
/**
|
|
460
|
-
* fetch the profile picture of a user/group
|
|
461
|
-
* type = "preview" for a low res picture
|
|
462
|
-
* type = "image for the high res picture"
|
|
463
|
-
*/
|
|
464
452
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
453
|
+
var _a;
|
|
465
454
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
455
|
+
try {
|
|
456
|
+
const result = await query({
|
|
457
|
+
tag: 'iq',
|
|
458
|
+
attrs: {
|
|
459
|
+
target: jid,
|
|
460
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
461
|
+
type: 'get',
|
|
462
|
+
xmlns: 'w:profile:picture'
|
|
463
|
+
},
|
|
464
|
+
content: [
|
|
465
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
466
|
+
]
|
|
467
|
+
}, timeoutMs);
|
|
468
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
469
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
470
|
+
} catch (error) {
|
|
471
|
+
if (error.message?.includes('item-not-found') ||
|
|
472
|
+
error.output?.payload?.statusCode === 404 ||
|
|
473
|
+
error.statusCode === 404) {
|
|
474
|
+
logger.info(chalk.gray(`[INFO] Profile pic not found for ${jid}, using fallback`));
|
|
475
|
+
return {
|
|
476
|
+
eurl: undefined,
|
|
477
|
+
id: jid.split('@')[0],
|
|
478
|
+
status: null,
|
|
479
|
+
img: null
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
throw error;
|
|
483
|
+
}
|
|
478
484
|
};
|
|
479
485
|
const createCallLink = async (type, event, timeoutMs) => {
|
|
480
486
|
const result = await query({
|
|
@@ -517,7 +523,7 @@ const makeChatsSocket = (config) => {
|
|
|
517
523
|
tag: 'chatstate',
|
|
518
524
|
attrs: {
|
|
519
525
|
from: isLid ? me.lid : me.id,
|
|
520
|
-
to: toJid
|
|
526
|
+
to: toJid,
|
|
521
527
|
},
|
|
522
528
|
content: [
|
|
523
529
|
{
|
|
@@ -528,11 +534,7 @@ const makeChatsSocket = (config) => {
|
|
|
528
534
|
});
|
|
529
535
|
}
|
|
530
536
|
};
|
|
531
|
-
|
|
532
|
-
* @param toJid the jid to subscribe to
|
|
533
|
-
* @param tcToken token for subscription, use if present
|
|
534
|
-
*/
|
|
535
|
-
const presenceSubscribe = (toJid, tcToken) => sendNode({
|
|
537
|
+
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
536
538
|
tag: 'presence',
|
|
537
539
|
attrs: {
|
|
538
540
|
to: toJid,
|
|
@@ -548,12 +550,13 @@ const makeChatsSocket = (config) => {
|
|
|
548
550
|
}
|
|
549
551
|
]
|
|
550
552
|
: undefined
|
|
551
|
-
});
|
|
553
|
+
}));
|
|
552
554
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
555
|
+
var _a;
|
|
553
556
|
let presence;
|
|
554
557
|
const jid = attrs.from;
|
|
555
558
|
const participant = attrs.participant || attrs.from;
|
|
556
|
-
if (shouldIgnoreJid(jid) && jid
|
|
559
|
+
if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
|
|
557
560
|
return;
|
|
558
561
|
}
|
|
559
562
|
if (tag === 'presence') {
|
|
@@ -568,7 +571,7 @@ const makeChatsSocket = (config) => {
|
|
|
568
571
|
if (type === 'paused') {
|
|
569
572
|
type = 'available';
|
|
570
573
|
}
|
|
571
|
-
if (firstChild.attrs
|
|
574
|
+
if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
|
|
572
575
|
type = 'recording';
|
|
573
576
|
}
|
|
574
577
|
presence = { lastKnownPresence: type };
|
|
@@ -613,13 +616,13 @@ const makeChatsSocket = (config) => {
|
|
|
613
616
|
attrs: {
|
|
614
617
|
name,
|
|
615
618
|
version: (state.version - 1).toString(),
|
|
616
|
-
return_snapshot: 'false'
|
|
619
|
+
'return_snapshot': 'false'
|
|
617
620
|
},
|
|
618
621
|
content: [
|
|
619
622
|
{
|
|
620
623
|
tag: 'patch',
|
|
621
624
|
attrs: {},
|
|
622
|
-
content:
|
|
625
|
+
content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
|
|
623
626
|
}
|
|
624
627
|
]
|
|
625
628
|
}
|
|
@@ -629,41 +632,37 @@ const makeChatsSocket = (config) => {
|
|
|
629
632
|
};
|
|
630
633
|
await query(node);
|
|
631
634
|
await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
|
|
632
|
-
}
|
|
635
|
+
});
|
|
633
636
|
});
|
|
634
637
|
if (config.emitOwnEvents) {
|
|
635
638
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
636
|
-
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
639
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
637
640
|
for (const key in mutationMap) {
|
|
638
641
|
onMutation(mutationMap[key]);
|
|
639
642
|
}
|
|
640
643
|
}
|
|
641
644
|
};
|
|
642
|
-
/** sending non-abt props may fix QR scan fail if server expects */
|
|
643
645
|
const fetchProps = async () => {
|
|
646
|
+
var _a, _b, _c;
|
|
644
647
|
const resultNode = await query({
|
|
645
648
|
tag: 'iq',
|
|
646
649
|
attrs: {
|
|
647
650
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
648
651
|
xmlns: 'w',
|
|
649
|
-
type: 'get'
|
|
652
|
+
type: 'get',
|
|
650
653
|
},
|
|
651
654
|
content: [
|
|
652
|
-
{
|
|
653
|
-
tag: 'props',
|
|
654
|
-
attrs: {
|
|
655
|
+
{ tag: 'props', attrs: {
|
|
655
656
|
protocol: '2',
|
|
656
|
-
hash: authState
|
|
657
|
-
}
|
|
658
|
-
}
|
|
657
|
+
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
658
|
+
} }
|
|
659
659
|
]
|
|
660
660
|
});
|
|
661
661
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
662
662
|
let props = {};
|
|
663
663
|
if (propsNode) {
|
|
664
|
-
if (propsNode.attrs
|
|
665
|
-
|
|
666
|
-
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
664
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
665
|
+
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
667
666
|
ev.emit('creds.update', authState.creds);
|
|
668
667
|
}
|
|
669
668
|
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
@@ -671,26 +670,10 @@ const makeChatsSocket = (config) => {
|
|
|
671
670
|
logger.debug('fetched props');
|
|
672
671
|
return props;
|
|
673
672
|
};
|
|
674
|
-
/**
|
|
675
|
-
* modify a chat -- mark unread, read etc.
|
|
676
|
-
* lastMessages must be sorted in reverse chronologically
|
|
677
|
-
* requires the last messages till the last message received; required for archive & unread
|
|
678
|
-
*/
|
|
679
673
|
const chatModify = (mod, jid) => {
|
|
680
674
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
681
675
|
return appPatch(patch);
|
|
682
676
|
};
|
|
683
|
-
/**
|
|
684
|
-
* Enable/Disable link preview privacy, not related to baileys link preview generation
|
|
685
|
-
*/
|
|
686
|
-
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
687
|
-
return chatModify({
|
|
688
|
-
disableLinkPreviews: { isPreviewsDisabled }
|
|
689
|
-
}, '');
|
|
690
|
-
};
|
|
691
|
-
/**
|
|
692
|
-
* Star or Unstar a message
|
|
693
|
-
*/
|
|
694
677
|
const star = (jid, messages, star) => {
|
|
695
678
|
return chatModify({
|
|
696
679
|
star: {
|
|
@@ -699,35 +682,15 @@ const makeChatsSocket = (config) => {
|
|
|
699
682
|
}
|
|
700
683
|
}, jid);
|
|
701
684
|
};
|
|
702
|
-
/**
|
|
703
|
-
* Add or Edit Contact
|
|
704
|
-
*/
|
|
705
685
|
const addOrEditContact = (jid, contact) => {
|
|
706
|
-
return chatModify({
|
|
707
|
-
contact
|
|
708
|
-
}, jid);
|
|
686
|
+
return chatModify({ contact }, jid);
|
|
709
687
|
};
|
|
710
|
-
/**
|
|
711
|
-
* Remove Contact
|
|
712
|
-
*/
|
|
713
688
|
const removeContact = (jid) => {
|
|
714
|
-
return chatModify({
|
|
715
|
-
contact: null
|
|
716
|
-
}, jid);
|
|
689
|
+
return chatModify({ contact: null }, jid);
|
|
717
690
|
};
|
|
718
|
-
/**
|
|
719
|
-
* Adds label
|
|
720
|
-
*/
|
|
721
691
|
const addLabel = (jid, labels) => {
|
|
722
|
-
return chatModify({
|
|
723
|
-
addLabel: {
|
|
724
|
-
...labels
|
|
725
|
-
}
|
|
726
|
-
}, jid);
|
|
692
|
+
return chatModify({ addLabel: { ...labels } }, jid);
|
|
727
693
|
};
|
|
728
|
-
/**
|
|
729
|
-
* Adds label for the chats
|
|
730
|
-
*/
|
|
731
694
|
const addChatLabel = (jid, labelId) => {
|
|
732
695
|
return chatModify({
|
|
733
696
|
addChatLabel: {
|
|
@@ -735,9 +698,6 @@ const makeChatsSocket = (config) => {
|
|
|
735
698
|
}
|
|
736
699
|
}, jid);
|
|
737
700
|
};
|
|
738
|
-
/**
|
|
739
|
-
* Removes label for the chat
|
|
740
|
-
*/
|
|
741
701
|
const removeChatLabel = (jid, labelId) => {
|
|
742
702
|
return chatModify({
|
|
743
703
|
removeChatLabel: {
|
|
@@ -745,9 +705,6 @@ const makeChatsSocket = (config) => {
|
|
|
745
705
|
}
|
|
746
706
|
}, jid);
|
|
747
707
|
};
|
|
748
|
-
/**
|
|
749
|
-
* Adds label for the message
|
|
750
|
-
*/
|
|
751
708
|
const addMessageLabel = (jid, messageId, labelId) => {
|
|
752
709
|
return chatModify({
|
|
753
710
|
addMessageLabel: {
|
|
@@ -756,9 +713,6 @@ const makeChatsSocket = (config) => {
|
|
|
756
713
|
}
|
|
757
714
|
}, jid);
|
|
758
715
|
};
|
|
759
|
-
/**
|
|
760
|
-
* Removes label for the message
|
|
761
|
-
*/
|
|
762
716
|
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
763
717
|
return chatModify({
|
|
764
718
|
removeMessageLabel: {
|
|
@@ -767,78 +721,65 @@ const makeChatsSocket = (config) => {
|
|
|
767
721
|
}
|
|
768
722
|
}, jid);
|
|
769
723
|
};
|
|
770
|
-
/**
|
|
771
|
-
* Add or Edit Quick Reply
|
|
772
|
-
*/
|
|
773
|
-
const addOrEditQuickReply = (quickReply) => {
|
|
774
|
-
return chatModify({
|
|
775
|
-
quickReply
|
|
776
|
-
}, '');
|
|
777
|
-
};
|
|
778
|
-
/**
|
|
779
|
-
* Remove Quick Reply
|
|
780
|
-
*/
|
|
781
|
-
const removeQuickReply = (timestamp) => {
|
|
782
|
-
return chatModify({
|
|
783
|
-
quickReply: { timestamp, deleted: true }
|
|
784
|
-
}, '');
|
|
785
|
-
};
|
|
786
|
-
/**
|
|
787
|
-
* queries need to be fired on connection open
|
|
788
|
-
* help ensure parity with WA Web
|
|
789
|
-
* */
|
|
790
724
|
const executeInitQueries = async () => {
|
|
791
|
-
await Promise.all([
|
|
725
|
+
await Promise.all([
|
|
726
|
+
fetchProps(),
|
|
727
|
+
fetchBlocklist(),
|
|
728
|
+
fetchPrivacySettings(),
|
|
729
|
+
]);
|
|
792
730
|
};
|
|
793
731
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
732
|
+
var _a, _b, _c;
|
|
794
733
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
795
734
|
if (!!msg.pushName) {
|
|
796
|
-
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
735
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
|
|
797
736
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
798
737
|
if (!msg.key.fromMe) {
|
|
799
738
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
800
739
|
}
|
|
801
|
-
|
|
802
|
-
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
740
|
+
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
803
741
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
804
742
|
}
|
|
805
743
|
}
|
|
806
744
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
807
745
|
const shouldProcessHistoryMsg = historyMsg
|
|
808
|
-
? shouldSyncHistoryMessage(historyMsg)
|
|
746
|
+
? (shouldSyncHistoryMessage(historyMsg)
|
|
747
|
+
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
809
748
|
: false;
|
|
810
|
-
|
|
811
|
-
if (historyMsg && syncState === State_1.SyncState.AwaitingInitialSync) {
|
|
749
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
812
750
|
if (awaitingSyncTimeout) {
|
|
813
751
|
clearTimeout(awaitingSyncTimeout);
|
|
814
752
|
awaitingSyncTimeout = undefined;
|
|
815
753
|
}
|
|
816
754
|
if (shouldProcessHistoryMsg) {
|
|
817
|
-
syncState =
|
|
755
|
+
syncState = SyncState.Syncing;
|
|
818
756
|
logger.info('Transitioned to Syncing state');
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
else {
|
|
822
|
-
syncState = State_1.SyncState.Online;
|
|
757
|
+
} else {
|
|
758
|
+
syncState = SyncState.Online;
|
|
823
759
|
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
824
760
|
ev.flush();
|
|
825
761
|
}
|
|
826
762
|
}
|
|
827
763
|
const doAppStateSync = async () => {
|
|
828
|
-
if (syncState ===
|
|
764
|
+
if (syncState === SyncState.Syncing) {
|
|
829
765
|
logger.info('Doing app state sync');
|
|
830
766
|
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
831
|
-
|
|
832
|
-
syncState = State_1.SyncState.Online;
|
|
767
|
+
syncState = SyncState.Online;
|
|
833
768
|
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
834
769
|
ev.flush();
|
|
835
770
|
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
836
771
|
ev.emit('creds.update', { accountSyncCounter });
|
|
837
772
|
}
|
|
838
773
|
};
|
|
774
|
+
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
775
|
+
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
776
|
+
pendingAppStateSync = true;
|
|
777
|
+
}
|
|
839
778
|
await Promise.all([
|
|
840
779
|
(async () => {
|
|
841
|
-
if (
|
|
780
|
+
if (historyMsg
|
|
781
|
+
&& authState.creds.myAppStateKeyId) {
|
|
782
|
+
pendingAppStateSync = false;
|
|
842
783
|
await doAppStateSync();
|
|
843
784
|
}
|
|
844
785
|
})(),
|
|
@@ -850,13 +791,14 @@ const makeChatsSocket = (config) => {
|
|
|
850
791
|
creds: authState.creds,
|
|
851
792
|
keyStore: authState.keys,
|
|
852
793
|
logger,
|
|
853
|
-
options: config.options
|
|
794
|
+
options: config.options,
|
|
795
|
+
getMessage: config.getMessage,
|
|
854
796
|
})
|
|
855
797
|
]);
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
logger.info('App state sync key arrived, triggering app state sync');
|
|
798
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
799
|
+
&& pendingAppStateSync) {
|
|
859
800
|
await doAppStateSync();
|
|
801
|
+
pendingAppStateSync = false;
|
|
860
802
|
}
|
|
861
803
|
});
|
|
862
804
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
@@ -876,7 +818,6 @@ const makeChatsSocket = (config) => {
|
|
|
876
818
|
}
|
|
877
819
|
break;
|
|
878
820
|
case 'groups':
|
|
879
|
-
// handled in groups.ts
|
|
880
821
|
break;
|
|
881
822
|
default:
|
|
882
823
|
logger.info({ node }, 'received unknown sync');
|
|
@@ -884,24 +825,34 @@ const makeChatsSocket = (config) => {
|
|
|
884
825
|
}
|
|
885
826
|
});
|
|
886
827
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
828
|
+
var _a;
|
|
887
829
|
if (connection === 'open') {
|
|
888
830
|
if (fireInitQueries) {
|
|
889
|
-
executeInitQueries()
|
|
831
|
+
executeInitQueries()
|
|
832
|
+
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
890
833
|
}
|
|
891
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
834
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
835
|
+
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
836
|
+
}
|
|
837
|
+
if (receivedPendingNotifications &&
|
|
838
|
+
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
839
|
+
ev.buffer();
|
|
840
|
+
needToFlushWithAppStateSync = true;
|
|
892
841
|
}
|
|
893
|
-
if (!receivedPendingNotifications || syncState !==
|
|
842
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
894
843
|
return;
|
|
895
844
|
}
|
|
896
|
-
syncState =
|
|
845
|
+
syncState = SyncState.AwaitingInitialSync;
|
|
897
846
|
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
898
847
|
ev.buffer();
|
|
899
|
-
const willSyncHistory = shouldSyncHistoryMessage(
|
|
900
|
-
|
|
901
|
-
|
|
848
|
+
const willSyncHistory = shouldSyncHistoryMessage(
|
|
849
|
+
WAProto_1.proto.Message.HistorySyncNotification.create({
|
|
850
|
+
syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
|
|
851
|
+
})
|
|
852
|
+
);
|
|
902
853
|
if (!willSyncHistory) {
|
|
903
854
|
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
904
|
-
syncState =
|
|
855
|
+
syncState = SyncState.Online;
|
|
905
856
|
setTimeout(() => ev.flush(), 0);
|
|
906
857
|
return;
|
|
907
858
|
}
|
|
@@ -910,9 +861,9 @@ const makeChatsSocket = (config) => {
|
|
|
910
861
|
clearTimeout(awaitingSyncTimeout);
|
|
911
862
|
}
|
|
912
863
|
awaitingSyncTimeout = setTimeout(() => {
|
|
913
|
-
if (syncState ===
|
|
864
|
+
if (syncState === SyncState.AwaitingInitialSync) {
|
|
914
865
|
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
915
|
-
syncState =
|
|
866
|
+
syncState = SyncState.Online;
|
|
916
867
|
ev.flush();
|
|
917
868
|
}
|
|
918
869
|
}, 20000);
|
|
@@ -928,9 +879,10 @@ const makeChatsSocket = (config) => {
|
|
|
928
879
|
sendPresenceUpdate,
|
|
929
880
|
presenceSubscribe,
|
|
930
881
|
profilePictureUrl,
|
|
882
|
+
onWhatsApp,
|
|
931
883
|
fetchBlocklist,
|
|
932
|
-
fetchStatus,
|
|
933
884
|
fetchDisappearingDuration,
|
|
885
|
+
fetchStatus,
|
|
934
886
|
updateProfilePicture,
|
|
935
887
|
removeProfilePicture,
|
|
936
888
|
updateProfileStatus,
|
|
@@ -957,9 +909,7 @@ const makeChatsSocket = (config) => {
|
|
|
957
909
|
removeChatLabel,
|
|
958
910
|
addMessageLabel,
|
|
959
911
|
removeMessageLabel,
|
|
960
|
-
star
|
|
961
|
-
addOrEditQuickReply,
|
|
962
|
-
removeQuickReply
|
|
912
|
+
star
|
|
963
913
|
};
|
|
964
914
|
};
|
|
965
|
-
exports.makeChatsSocket = makeChatsSocket;
|
|
915
|
+
exports.makeChatsSocket = makeChatsSocket;
|