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