sanka-baileyss 2.5.1 → 2.5.3
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/lib/Socket/chats.js +72 -82
- package/lib/Socket/messages-recv.js +0 -15
- package/lib/Socket/messages-send.js +1 -1
- package/lib/Store/make-in-memory-store.js +1 -3
- package/lib/Types/Events.d.ts +0 -8
- package/lib/Types/Message.js +0 -2
- package/lib/Utils/chat-utils.js +0 -2
- package/lib/Utils/decode-wa-message.js +0 -1
- package/lib/Utils/event-buffer.js +0 -21
- package/lib/Utils/history.js +0 -2
- package/lib/Utils/link-preview.js +0 -1
- package/lib/Utils/make-mutex.js +0 -5
- package/lib/Utils/messages-media.js +0 -6
- package/lib/Utils/messages.js +0 -10
- package/lib/Utils/noise-handler.js +0 -5
- package/lib/Utils/process-message.js +8 -58
- package/lib/Utils/signal.js +0 -5
- package/lib/WABinary/decode.js +1 -2
- package/lib/WABinary/encode.js +0 -1
- package/lib/WABinary/generic-utils.js +1 -1
- package/package.json +1 -1
package/lib/Socket/chats.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
4
|
+
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeChatsSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
@@ -57,15 +57,15 @@ const makeChatsSocket = (config) => {
|
|
|
57
57
|
type: 'set'
|
|
58
58
|
},
|
|
59
59
|
content: [{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
tag: 'privacy',
|
|
61
|
+
attrs: {},
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
tag: 'category',
|
|
65
|
+
attrs: { name, value }
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}]
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
71
|
const updateLastSeenPrivacy = async (value) => {
|
|
@@ -91,35 +91,35 @@ const makeChatsSocket = (config) => {
|
|
|
91
91
|
if (!phoneNumber) {
|
|
92
92
|
throw new Error('enter number');
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
let resultData = {
|
|
96
96
|
isBanned: false,
|
|
97
97
|
isNeedOfficialWa: false,
|
|
98
98
|
number: phoneNumber
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
let formattedNumber = phoneNumber;
|
|
102
102
|
if (!formattedNumber.startsWith('+')) {
|
|
103
103
|
formattedNumber = '+' + formattedNumber;
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
const { parsePhoneNumber } = require('libphonenumber-js');
|
|
107
107
|
const parsedNumber = parsePhoneNumber(formattedNumber);
|
|
108
108
|
const countryCode = parsedNumber.countryCallingCode;
|
|
109
109
|
const nationalNumber = parsedNumber.nationalNumber;
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
try {
|
|
112
112
|
const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
|
|
113
113
|
const { state } = await useMultiFileAuthState(".npm");
|
|
114
114
|
const { version } = await fetchLatestBaileysVersion();
|
|
115
115
|
const { makeWASocket } = require('../Socket');
|
|
116
116
|
const pino = require("pino");
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
const sock = makeWASocket({
|
|
119
119
|
version,
|
|
120
120
|
auth: state,
|
|
121
121
|
browser: Browsers.ubuntu("Chrome"),
|
|
122
|
-
logger: pino({
|
|
122
|
+
logger: pino({
|
|
123
123
|
level: "silent"
|
|
124
124
|
}),
|
|
125
125
|
printQRInTerminal: false,
|
|
@@ -137,7 +137,7 @@ const makeChatsSocket = (config) => {
|
|
|
137
137
|
if (sock.ws) {
|
|
138
138
|
sock.ws.close();
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
return JSON.stringify(resultData, null, 2);
|
|
142
142
|
} catch (err) {
|
|
143
143
|
if (err?.appeal_token) {
|
|
@@ -163,11 +163,11 @@ const makeChatsSocket = (config) => {
|
|
|
163
163
|
type: 'set'
|
|
164
164
|
},
|
|
165
165
|
content: [{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
tag: 'disappearing_mode',
|
|
167
|
+
attrs: {
|
|
168
|
+
duration: duration.toString()
|
|
169
|
+
}
|
|
170
|
+
}]
|
|
171
171
|
});
|
|
172
172
|
};
|
|
173
173
|
/** helper function to run a generic IQ query */
|
|
@@ -219,13 +219,13 @@ const makeChatsSocket = (config) => {
|
|
|
219
219
|
type: 'get'
|
|
220
220
|
},
|
|
221
221
|
content: [{
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
tag: 'business_profile',
|
|
223
|
+
attrs: { v: '244' },
|
|
224
|
+
content: [{
|
|
225
|
+
tag: 'profile',
|
|
226
|
+
attrs: { jid }
|
|
227
|
+
}]
|
|
227
228
|
}]
|
|
228
|
-
}]
|
|
229
229
|
});
|
|
230
230
|
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
231
231
|
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
@@ -256,50 +256,50 @@ const makeChatsSocket = (config) => {
|
|
|
256
256
|
};
|
|
257
257
|
const onWhatsApp = async (...jids) => {
|
|
258
258
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
.withContactProtocol()
|
|
260
|
+
.withLIDProtocol();
|
|
261
|
+
|
|
262
262
|
for (const jid of jids) {
|
|
263
263
|
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
264
264
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
265
265
|
}
|
|
266
|
-
|
|
266
|
+
|
|
267
267
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
268
268
|
if (results) {
|
|
269
269
|
const verifiedResults = await Promise.all(
|
|
270
270
|
results.list
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return {
|
|
280
|
-
jid: id,
|
|
281
|
-
exists: true,
|
|
282
|
-
lid: lid,
|
|
283
|
-
status: 'business',
|
|
284
|
-
businessInfo: businessInfo
|
|
285
|
-
};
|
|
286
|
-
} else {
|
|
287
|
-
return {
|
|
288
|
-
jid: id,
|
|
289
|
-
exists: true,
|
|
290
|
-
lid: lid,
|
|
291
|
-
status: 'regular'
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
} catch (error) {
|
|
271
|
+
.filter((a) => !!a.contact)
|
|
272
|
+
.map(async ({ contact, id, lid }) => {
|
|
273
|
+
try {
|
|
274
|
+
const businessProfile = await getBusinessProfile(id);
|
|
275
|
+
const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
|
|
276
|
+
if (isBusiness) {
|
|
277
|
+
const { wid, ...businessInfo } = businessProfile;
|
|
278
|
+
|
|
295
279
|
return {
|
|
296
280
|
jid: id,
|
|
297
281
|
exists: true,
|
|
298
282
|
lid: lid,
|
|
299
|
-
status:
|
|
283
|
+
status: 'business',
|
|
284
|
+
businessInfo: businessInfo
|
|
285
|
+
};
|
|
286
|
+
} else {
|
|
287
|
+
return {
|
|
288
|
+
jid: id,
|
|
289
|
+
exists: true,
|
|
290
|
+
lid: lid,
|
|
291
|
+
status: 'regular'
|
|
300
292
|
};
|
|
301
293
|
}
|
|
302
|
-
})
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return {
|
|
296
|
+
jid: id,
|
|
297
|
+
exists: true,
|
|
298
|
+
lid: lid,
|
|
299
|
+
status: error
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
303
|
);
|
|
304
304
|
return verifiedResults;
|
|
305
305
|
}
|
|
@@ -321,7 +321,7 @@ const makeChatsSocket = (config) => {
|
|
|
321
321
|
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');
|
|
322
322
|
}
|
|
323
323
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
324
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
324
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
325
325
|
}
|
|
326
326
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
327
327
|
await query({
|
|
@@ -348,7 +348,7 @@ const makeChatsSocket = (config) => {
|
|
|
348
348
|
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');
|
|
349
349
|
}
|
|
350
350
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
351
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
351
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
352
352
|
}
|
|
353
353
|
await query({
|
|
354
354
|
tag: 'iq',
|
|
@@ -499,20 +499,16 @@ const makeChatsSocket = (config) => {
|
|
|
499
499
|
states[name] = newState;
|
|
500
500
|
Object.assign(globalMutationMap, mutationMap);
|
|
501
501
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
502
|
-
await authState.keys.set({
|
|
503
|
-
'app-state-sync-version': {
|
|
502
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
504
503
|
[name]: newState
|
|
505
|
-
}
|
|
506
|
-
});
|
|
504
|
+
} });
|
|
507
505
|
}
|
|
508
506
|
|
|
509
507
|
if (patches.length) {
|
|
510
508
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
511
|
-
await authState.keys.set({
|
|
512
|
-
'app-state-sync-version': {
|
|
509
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
513
510
|
[name]: newState
|
|
514
|
-
}
|
|
515
|
-
});
|
|
511
|
+
} });
|
|
516
512
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
517
513
|
initialVersionMap[name] = newState.version;
|
|
518
514
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -520,7 +516,7 @@ const makeChatsSocket = (config) => {
|
|
|
520
516
|
if (hasMorePatches) {
|
|
521
517
|
logger.info(`${name} has more patches...`);
|
|
522
518
|
}
|
|
523
|
-
else {
|
|
519
|
+
else {
|
|
524
520
|
collectionsToHandle.delete(name);
|
|
525
521
|
}
|
|
526
522
|
}
|
|
@@ -529,11 +525,9 @@ const makeChatsSocket = (config) => {
|
|
|
529
525
|
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
530
526
|
error.name === 'TypeError';
|
|
531
527
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
532
|
-
await authState.keys.set({
|
|
533
|
-
'app-state-sync-version': {
|
|
528
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
534
529
|
[name]: null
|
|
535
|
-
}
|
|
536
|
-
});
|
|
530
|
+
} });
|
|
537
531
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
538
532
|
if (isIrrecoverableError) {
|
|
539
533
|
collectionsToHandle.delete(name);
|
|
@@ -654,11 +648,9 @@ const makeChatsSocket = (config) => {
|
|
|
654
648
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
655
649
|
}
|
|
656
650
|
if (presence) {
|
|
657
|
-
ev.emit('presence.update', {
|
|
658
|
-
id: jid, presences: {
|
|
651
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
659
652
|
[participant]: presence
|
|
660
|
-
}
|
|
661
|
-
});
|
|
653
|
+
} });
|
|
662
654
|
}
|
|
663
655
|
};
|
|
664
656
|
const appPatch = async (patchCreate) => {
|
|
@@ -709,11 +701,9 @@ const makeChatsSocket = (config) => {
|
|
|
709
701
|
]
|
|
710
702
|
};
|
|
711
703
|
await query(node);
|
|
712
|
-
await authState.keys.set({
|
|
713
|
-
'app-state-sync-version': {
|
|
704
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
714
705
|
[name]: state
|
|
715
|
-
}
|
|
716
|
-
});
|
|
706
|
+
} });
|
|
717
707
|
});
|
|
718
708
|
});
|
|
719
709
|
if (config.emitOwnEvents) {
|
|
@@ -863,7 +853,7 @@ const makeChatsSocket = (config) => {
|
|
|
863
853
|
creds: authState.creds,
|
|
864
854
|
keyStore: authState.keys,
|
|
865
855
|
logger,
|
|
866
|
-
options:
|
|
856
|
+
options: config.options,
|
|
867
857
|
getMessage: config.getMessage,
|
|
868
858
|
})
|
|
869
859
|
]);
|
|
@@ -620,12 +620,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
620
620
|
const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
|
|
621
621
|
await assertSessions([participant], true);
|
|
622
622
|
if ((0, WABinary_1.isJidGroup)(remoteJid)) {
|
|
623
|
-
// Instead of clearing entire group sender-key-memory, only clear specific participant's key
|
|
624
623
|
const senderKeyName = `${remoteJid}::${participant}`;
|
|
625
624
|
logger.debug({ remoteJid, participant, senderKeyName }, 'clearing sender key for specific participant on retry');
|
|
626
625
|
await authState.keys.set({ 'sender-key': { [senderKeyName]: null } });
|
|
627
626
|
|
|
628
|
-
// Also update sender-key-memory to remove this specific participant
|
|
629
627
|
const result = await authState.keys.get('sender-key-memory', [remoteJid]);
|
|
630
628
|
const senderKeyMap = result[remoteJid] || {};
|
|
631
629
|
if (senderKeyMap[participant]) {
|
|
@@ -805,7 +803,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
805
803
|
processingMutex.mutex(async () => {
|
|
806
804
|
var _a, _b, _c, _d, _e, _f;
|
|
807
805
|
await decrypt();
|
|
808
|
-
// message failed to decrypt
|
|
809
806
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
810
807
|
if (((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.MISSING_KEYS_ERROR_TEXT) {
|
|
811
808
|
return sendMessageAck(node, Utils_1.NACK_REASONS.ParsingError);
|
|
@@ -827,7 +824,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
827
824
|
});
|
|
828
825
|
}
|
|
829
826
|
else {
|
|
830
|
-
// no type in the receipt => message delivered
|
|
831
827
|
let type = undefined;
|
|
832
828
|
if ((_b = msg.key.participant) === null || _b === void 0 ? void 0 : _b.endsWith('@lid')) {
|
|
833
829
|
msg.key.participant = node.attrs.participant_pn || authState.creds.me.id;
|
|
@@ -942,12 +938,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
942
938
|
callOfferCache.set(call.id, call);
|
|
943
939
|
}
|
|
944
940
|
const existingCall = callOfferCache.get(call.id);
|
|
945
|
-
// use existing call info to populate this event
|
|
946
941
|
if (existingCall) {
|
|
947
942
|
call.isVideo = existingCall.isVideo;
|
|
948
943
|
call.isGroup = existingCall.isGroup;
|
|
949
944
|
}
|
|
950
|
-
// delete data once call has ended
|
|
951
945
|
if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
|
|
952
946
|
callOfferCache.del(call.id);
|
|
953
947
|
}
|
|
@@ -956,9 +950,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
956
950
|
};
|
|
957
951
|
const handleBadAck = async ({ attrs }) => {
|
|
958
952
|
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
|
|
959
|
-
// current hypothesis is that if pash is sent in the ack
|
|
960
|
-
// it means -- the message hasn't reached all devices yet
|
|
961
|
-
// we'll retry sending the message here
|
|
962
953
|
if (attrs.phash) {
|
|
963
954
|
logger.info({ attrs }, 'received phash in ack, resending message...');
|
|
964
955
|
const cacheKey = `${key.remoteJid}:${key.id}`;
|
|
@@ -977,8 +968,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
977
968
|
logger.warn({ attrs }, 'could not send message again, as it was not found');
|
|
978
969
|
}
|
|
979
970
|
}
|
|
980
|
-
// error in acknowledgement,
|
|
981
|
-
// device could not display the message
|
|
982
971
|
if (attrs.error) {
|
|
983
972
|
logger.warn({ attrs }, 'received error in ack');
|
|
984
973
|
ev.emit('messages.update', [
|
|
@@ -994,8 +983,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
994
983
|
]);
|
|
995
984
|
}
|
|
996
985
|
};
|
|
997
|
-
/// processes a node with the given function
|
|
998
|
-
/// and adds the task to the existing buffer if we're buffering events
|
|
999
986
|
const processNodeWithBuffer = async (node, identifier, exec) => {
|
|
1000
987
|
ev.buffer();
|
|
1001
988
|
await execTask();
|
|
@@ -1046,7 +1033,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1046
1033
|
processNodeWithBuffer(node, identifier, exec);
|
|
1047
1034
|
}
|
|
1048
1035
|
};
|
|
1049
|
-
// recv a message
|
|
1050
1036
|
ws.on('CB:message', (node) => {
|
|
1051
1037
|
processNode('message', node, 'processing message', handleMessage);
|
|
1052
1038
|
});
|
|
@@ -1064,7 +1050,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1064
1050
|
.catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
1065
1051
|
});
|
|
1066
1052
|
ev.on('call', ([call]) => {
|
|
1067
|
-
// missed call + group call notification message generation
|
|
1068
1053
|
if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
|
|
1069
1054
|
const msg = {
|
|
1070
1055
|
key: {
|
|
@@ -288,7 +288,7 @@ const makeMessagesSocket = (config) => {
|
|
|
288
288
|
return node;
|
|
289
289
|
}));
|
|
290
290
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
291
|
-
};
|
|
291
|
+
};
|
|
292
292
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
293
293
|
const meId = authState.creds.me.id;
|
|
294
294
|
let shouldIncludeDeviceIdentity = false;
|
|
@@ -330,7 +330,7 @@ exports.default = (config) => {
|
|
|
330
330
|
}
|
|
331
331
|
const diff = count - messages.length;
|
|
332
332
|
if (diff < 0) {
|
|
333
|
-
messages = messages.slice(-count);
|
|
333
|
+
messages = messages.slice(-count);
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
else {
|
|
@@ -408,12 +408,10 @@ exports.default = (config) => {
|
|
|
408
408
|
toJSON,
|
|
409
409
|
fromJSON,
|
|
410
410
|
writeToFile: (path) => {
|
|
411
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
412
411
|
const { writeFileSync } = require('fs');
|
|
413
412
|
writeFileSync(path, JSON.stringify(toJSON()));
|
|
414
413
|
},
|
|
415
414
|
readFromFile: (path) => {
|
|
416
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
417
415
|
const { readFileSync, existsSync } = require('fs');
|
|
418
416
|
if (existsSync(path)) {
|
|
419
417
|
logger.debug({ path }, 'reading from file');
|
package/lib/Types/Events.d.ts
CHANGED
|
@@ -75,15 +75,7 @@ export type BaileysEventMap = {
|
|
|
75
75
|
'group-participants.update': {
|
|
76
76
|
id: string;
|
|
77
77
|
author: string;
|
|
78
|
-
pushName?: string;
|
|
79
78
|
participants: string[];
|
|
80
|
-
participantsData?: Array<{
|
|
81
|
-
jid: string;
|
|
82
|
-
pushName?: string;
|
|
83
|
-
notify?: string;
|
|
84
|
-
name?: string;
|
|
85
|
-
verifiedName?: string;
|
|
86
|
-
}>;
|
|
87
79
|
action: ParticipantAction;
|
|
88
80
|
};
|
|
89
81
|
'blocklist.set': {
|
package/lib/Types/Message.js
CHANGED
|
@@ -3,7 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WAMessageStatus = exports.WAMessageStubType = exports.WAProto = void 0;
|
|
4
4
|
const WAProto_1 = require("../../WAProto");
|
|
5
5
|
Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () { return WAProto_1.proto; } });
|
|
6
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
7
6
|
exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
|
|
8
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
9
7
|
exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -577,8 +577,6 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
577
577
|
const isArchived = archiveAction
|
|
578
578
|
? archiveAction.archived
|
|
579
579
|
: type === 'archive';
|
|
580
|
-
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
581
|
-
// // this only applies for the initial sync
|
|
582
580
|
// if(isInitialSync && !isArchived) {
|
|
583
581
|
// isArchived = false
|
|
584
582
|
// }
|
|
@@ -187,7 +187,6 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
// if nothing was found to decrypt
|
|
191
190
|
if (!decryptables) {
|
|
192
191
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
193
192
|
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
@@ -34,7 +34,6 @@ const makeEventBuffer = (logger) => {
|
|
|
34
34
|
const historyCache = new Set();
|
|
35
35
|
let data = makeBufferData();
|
|
36
36
|
let buffersInProgress = 0;
|
|
37
|
-
// take the generic event and fire it as a baileys event
|
|
38
37
|
ev.on('event', (map) => {
|
|
39
38
|
for (const event in map) {
|
|
40
39
|
ev.emit(event, map[event]);
|
|
@@ -44,22 +43,17 @@ const makeEventBuffer = (logger) => {
|
|
|
44
43
|
buffersInProgress += 1;
|
|
45
44
|
}
|
|
46
45
|
function flush(force = false) {
|
|
47
|
-
// no buffer going on
|
|
48
46
|
if (!buffersInProgress) {
|
|
49
47
|
return false;
|
|
50
48
|
}
|
|
51
49
|
if (!force) {
|
|
52
|
-
// reduce the number of buffers in progress
|
|
53
50
|
buffersInProgress -= 1;
|
|
54
|
-
// if there are still some buffers going on
|
|
55
|
-
// then we don't flush now
|
|
56
51
|
if (buffersInProgress) {
|
|
57
52
|
return false;
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
55
|
const newData = makeBufferData();
|
|
61
56
|
const chatUpdates = Object.values(data.chatUpdates);
|
|
62
|
-
// gather the remaining conditional events so we re-queue them
|
|
63
57
|
let conditionalChatUpdatesLeft = 0;
|
|
64
58
|
for (const update of chatUpdates) {
|
|
65
59
|
if (update.conditional) {
|
|
@@ -206,24 +200,18 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
206
200
|
const conditionMatches = update.conditional ? update.conditional(data) : true;
|
|
207
201
|
if (conditionMatches) {
|
|
208
202
|
delete update.conditional;
|
|
209
|
-
// if there is an existing upsert, merge the update into it
|
|
210
203
|
const upsert = data.historySets.chats[chatId] || data.chatUpserts[chatId];
|
|
211
204
|
if (upsert) {
|
|
212
205
|
concatChats(upsert, update);
|
|
213
206
|
}
|
|
214
207
|
else {
|
|
215
|
-
// merge the update into the existing update
|
|
216
208
|
const chatUpdate = data.chatUpdates[chatId] || {};
|
|
217
209
|
data.chatUpdates[chatId] = concatChats(chatUpdate, update);
|
|
218
210
|
}
|
|
219
211
|
}
|
|
220
212
|
else if (conditionMatches === undefined) {
|
|
221
|
-
// condition yet to be fulfilled
|
|
222
213
|
data.chatUpdates[chatId] = update;
|
|
223
214
|
}
|
|
224
|
-
// otherwise -- condition not met, update is invalid
|
|
225
|
-
// if the chat has been updated
|
|
226
|
-
// ignore any existing chat delete
|
|
227
215
|
if (data.chatDeletes.has(chatId)) {
|
|
228
216
|
data.chatDeletes.delete(chatId);
|
|
229
217
|
}
|
|
@@ -234,7 +222,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
234
222
|
if (!data.chatDeletes.has(chatId)) {
|
|
235
223
|
data.chatDeletes.add(chatId);
|
|
236
224
|
}
|
|
237
|
-
// remove any prior updates & upserts
|
|
238
225
|
if (data.chatUpdates[chatId]) {
|
|
239
226
|
delete data.chatUpdates[chatId];
|
|
240
227
|
}
|
|
@@ -272,13 +259,11 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
272
259
|
const contactUpdates = eventData;
|
|
273
260
|
for (const update of contactUpdates) {
|
|
274
261
|
const id = update.id;
|
|
275
|
-
// merge into prior upsert
|
|
276
262
|
const upsert = data.historySets.contacts[id] || data.contactUpserts[id];
|
|
277
263
|
if (upsert) {
|
|
278
264
|
Object.assign(upsert, update);
|
|
279
265
|
}
|
|
280
266
|
else {
|
|
281
|
-
// merge into prior update
|
|
282
267
|
const contactUpdate = data.contactUpdates[id] || {};
|
|
283
268
|
data.contactUpdates[id] = Object.assign(contactUpdate, update);
|
|
284
269
|
}
|
|
@@ -323,9 +308,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
323
308
|
const existing = data.historySets.messages[keyStr] || ((_c = data.messageUpserts[keyStr]) === null || _c === void 0 ? void 0 : _c.message);
|
|
324
309
|
if (existing) {
|
|
325
310
|
Object.assign(existing, update);
|
|
326
|
-
// if the message was received & read by us
|
|
327
|
-
// the chat counter must have been incremented
|
|
328
|
-
// so we need to decrement it
|
|
329
311
|
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
330
312
|
decrementChatReadCounterIfMsgDidUnread(existing);
|
|
331
313
|
}
|
|
@@ -419,8 +401,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
419
401
|
}
|
|
420
402
|
}
|
|
421
403
|
function decrementChatReadCounterIfMsgDidUnread(message) {
|
|
422
|
-
// decrement chat unread counter
|
|
423
|
-
// if the message has already been marked read by us
|
|
424
404
|
const chatId = message.key.remoteJid;
|
|
425
405
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
426
406
|
if ((0, process_message_1.isRealMessage)(message, '')
|
|
@@ -497,7 +477,6 @@ function consolidateEvents(data) {
|
|
|
497
477
|
}
|
|
498
478
|
function concatChats(a, b) {
|
|
499
479
|
if (b.unreadCount === null) {
|
|
500
|
-
// neutralize unread counter
|
|
501
480
|
if (a.unreadCount < 0) {
|
|
502
481
|
a.unreadCount = undefined;
|
|
503
482
|
b.unreadCount = undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -17,7 +17,6 @@ const downloadHistory = async (msg, options) => {
|
|
|
17
17
|
bufferArray.push(chunk);
|
|
18
18
|
}
|
|
19
19
|
let buffer = Buffer.concat(bufferArray);
|
|
20
|
-
// decompress buffer
|
|
21
20
|
buffer = await inflatePromise(buffer);
|
|
22
21
|
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
23
22
|
return syncData;
|
|
@@ -48,7 +47,6 @@ const processHistoryMessage = (item) => {
|
|
|
48
47
|
const message = item.message;
|
|
49
48
|
messages.push(message);
|
|
50
49
|
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
51
|
-
// keep only the most recent message in the chat array
|
|
52
50
|
chat.messages = [{ message }];
|
|
53
51
|
}
|
|
54
52
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -7,14 +7,11 @@ const makeMutex = () => {
|
|
|
7
7
|
return {
|
|
8
8
|
mutex(code) {
|
|
9
9
|
task = (async () => {
|
|
10
|
-
// wait for the previous task to complete
|
|
11
|
-
// if there is an error, we swallow so as to not block the queue
|
|
12
10
|
try {
|
|
13
11
|
await task;
|
|
14
12
|
}
|
|
15
13
|
catch (_a) { }
|
|
16
14
|
try {
|
|
17
|
-
// execute the current task
|
|
18
15
|
const result = await code();
|
|
19
16
|
return result;
|
|
20
17
|
}
|
|
@@ -22,8 +19,6 @@ const makeMutex = () => {
|
|
|
22
19
|
clearTimeout(taskTimeout);
|
|
23
20
|
}
|
|
24
21
|
})();
|
|
25
|
-
// we replace the existing task, appending the new piece of execution to it
|
|
26
|
-
// so the next task will have to wait for this one to finish
|
|
27
22
|
return task;
|
|
28
23
|
},
|
|
29
24
|
};
|
|
@@ -578,7 +578,6 @@ const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startB
|
|
|
578
578
|
headers.Range += endChunk;
|
|
579
579
|
}
|
|
580
580
|
}
|
|
581
|
-
// download the message
|
|
582
581
|
const fetched = await (0, exports.getHttpStream)(downloadUrl, {
|
|
583
582
|
...options || {},
|
|
584
583
|
headers,
|
|
@@ -611,8 +610,6 @@ const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startB
|
|
|
611
610
|
data = data.slice(AES_CHUNK_SIZE);
|
|
612
611
|
}
|
|
613
612
|
aes = Crypto.createDecipheriv('aes-256-cbc', cipherKey, ivValue);
|
|
614
|
-
// if an end byte that is not EOF is specified
|
|
615
|
-
// stop auto padding (PKCS7) -- otherwise throws an error for decryption
|
|
616
613
|
if (endByte) {
|
|
617
614
|
aes.setAutoPadding(false);
|
|
618
615
|
}
|
|
@@ -745,9 +742,6 @@ const encryptMediaRetryRequest = (key, mediaKey, meId) => {
|
|
|
745
742
|
type: 'server-error'
|
|
746
743
|
},
|
|
747
744
|
content: [
|
|
748
|
-
// this encrypt node is actually pretty useless
|
|
749
|
-
// the media is returned even without this node
|
|
750
|
-
// keeping it here to maintain parity with WA Web
|
|
751
745
|
{
|
|
752
746
|
tag: 'encrypt',
|
|
753
747
|
attrs: {},
|
package/lib/Utils/messages.js
CHANGED
|
@@ -407,7 +407,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
407
407
|
throw new boom_1.Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, { statusCode: 400 });
|
|
408
408
|
}
|
|
409
409
|
m.messageContextInfo = {
|
|
410
|
-
// encKey
|
|
411
410
|
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
412
411
|
};
|
|
413
412
|
m.pollCreationMessage = {
|
|
@@ -509,8 +508,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
509
508
|
};
|
|
510
509
|
exports.generateWAMessageContent = generateWAMessageContent;
|
|
511
510
|
const generateWAMessageFromContent = (jid, message, options) => {
|
|
512
|
-
// set timestamp to now
|
|
513
|
-
// if not specified
|
|
514
511
|
if (!options.timestamp) {
|
|
515
512
|
options.timestamp = new Date();
|
|
516
513
|
}
|
|
@@ -522,7 +519,6 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
522
519
|
const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
|
|
523
520
|
let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
|
|
524
521
|
const msgType = (0, exports.getContentType)(quotedMsg);
|
|
525
|
-
// strip any redundant properties
|
|
526
522
|
quotedMsg = WAProto_1.proto.Message.fromObject({ [msgType]: quotedMsg[msgType] });
|
|
527
523
|
const quotedContent = quotedMsg[msgType];
|
|
528
524
|
if (typeof quotedContent === 'object' && quotedContent && 'contextInfo' in quotedContent) {
|
|
@@ -532,21 +528,15 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
532
528
|
contextInfo.participant = (0, WABinary_1.jidNormalizedUser)(participant);
|
|
533
529
|
contextInfo.stanzaId = quoted.key.id;
|
|
534
530
|
contextInfo.quotedMessage = quotedMsg;
|
|
535
|
-
// if a participant is quoted, then it must be a group
|
|
536
|
-
// hence, remoteJid of group must also be entered
|
|
537
531
|
if (jid !== quoted.key.remoteJid) {
|
|
538
532
|
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
539
533
|
}
|
|
540
534
|
innerMessage[key].contextInfo = contextInfo;
|
|
541
535
|
}
|
|
542
536
|
if (
|
|
543
|
-
// if we want to send a disappearing message
|
|
544
537
|
!!(options === null || options === void 0 ? void 0 : options.ephemeralExpiration) &&
|
|
545
|
-
// and it's not a protocol message -- delete, toggle disappear message
|
|
546
538
|
key !== 'protocolMessage' &&
|
|
547
|
-
// already not converted to disappearing message
|
|
548
539
|
key !== 'ephemeralMessage' &&
|
|
549
|
-
// newsletter not accept disappearing messages
|
|
550
540
|
!(0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
551
541
|
innerMessage[key].contextInfo = {
|
|
552
542
|
...(innerMessage[key].contextInfo || {}),
|
|
@@ -25,8 +25,6 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
const decrypt = (ciphertext) => {
|
|
28
|
-
// before the handshake is finished, we use the same counter
|
|
29
|
-
// after handshake, the counters are different
|
|
30
28
|
const iv = generateIV(isFinished ? readCounter : writeCounter);
|
|
31
29
|
const result = (0, crypto_1.aesDecryptGCM)(ciphertext, decKey, iv, hash);
|
|
32
30
|
if (isFinished) {
|
|
@@ -127,9 +125,6 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
127
125
|
},
|
|
128
126
|
decodeFrame: (newData, onFrame) => {
|
|
129
127
|
var _a;
|
|
130
|
-
// the binary protocol uses its own framing mechanism
|
|
131
|
-
// on top of the WS frames
|
|
132
|
-
// so we get this data and separate out the frames
|
|
133
128
|
const getBytesSize = () => {
|
|
134
129
|
if (inBytes.length >= 3) {
|
|
135
130
|
return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1);
|
|
@@ -19,11 +19,9 @@ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
|
|
|
19
19
|
]);
|
|
20
20
|
/** Cleans a received message to further processing */
|
|
21
21
|
const cleanMessage = (message, meId) => {
|
|
22
|
-
// ensure remoteJid and participant doesn't have device or agent in it
|
|
23
22
|
message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
|
|
24
23
|
message.key.participant = message.key.participant ? (0, WABinary_1.jidNormalizedUser)(message.key.participant) : undefined;
|
|
25
24
|
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
26
|
-
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
|
27
25
|
if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
28
26
|
normaliseKey(content.reactionMessage.key);
|
|
29
27
|
}
|
|
@@ -31,19 +29,11 @@ const cleanMessage = (message, meId) => {
|
|
|
31
29
|
normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
|
|
32
30
|
}
|
|
33
31
|
function normaliseKey(msgKey) {
|
|
34
|
-
// if the reaction is from another user
|
|
35
|
-
// we've to correctly map the key to this user's perspective
|
|
36
32
|
if (!message.key.fromMe) {
|
|
37
|
-
// if the sender believed the message being reacted to is not from them
|
|
38
|
-
// we've to correct the key to be from them, or some other participant
|
|
39
33
|
msgKey.fromMe = !msgKey.fromMe
|
|
40
34
|
? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
|
|
41
|
-
// if the message being reacted to, was from them
|
|
42
|
-
// fromMe automatically becomes false
|
|
43
35
|
: false;
|
|
44
|
-
// set the remoteJid to being the same as the chat the message came from
|
|
45
36
|
msgKey.remoteJid = message.key.remoteJid;
|
|
46
|
-
// set participant of the message
|
|
47
37
|
msgKey.participant = msgKey.participant || message.key.participant;
|
|
48
38
|
}
|
|
49
39
|
}
|
|
@@ -110,14 +100,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
110
100
|
const isRealMsg = (0, exports.isRealMessage)(message, meId);
|
|
111
101
|
if (isRealMsg) {
|
|
112
102
|
chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
113
|
-
// only increment unread count if not CIPHERTEXT and from another person
|
|
114
103
|
if ((0, exports.shouldIncrementChatUnread)(message)) {
|
|
115
104
|
chat.unreadCount = (chat.unreadCount || 0) + 1;
|
|
116
105
|
}
|
|
117
106
|
}
|
|
118
107
|
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
119
|
-
// unarchive chat if it's a real message, or someone reacted to our message
|
|
120
|
-
// and we've the unarchive chats setting on
|
|
121
108
|
if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
|
|
122
109
|
&& (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
|
|
123
110
|
chat.archived = false;
|
|
@@ -207,50 +194,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
207
194
|
key: message.key,
|
|
208
195
|
};
|
|
209
196
|
ev.emit('messages.reaction', [{
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
197
|
+
reaction,
|
|
198
|
+
key: content.reactionMessage.key,
|
|
199
|
+
}]);
|
|
213
200
|
}
|
|
214
201
|
else if (message.messageStubType) {
|
|
215
202
|
const jid = message.key.remoteJid;
|
|
216
203
|
//let actor = whatsappID (message.participant)
|
|
217
204
|
let participants;
|
|
218
|
-
const emitParticipantsUpdate =
|
|
219
|
-
let participantsData = participants.map(jid => ({ jid }));
|
|
220
|
-
// Try to fetch group metadata and get participant names
|
|
221
|
-
if (options?.socket?.groupMetadata) {
|
|
222
|
-
try {
|
|
223
|
-
const metadata = await options.socket.groupMetadata(jid);
|
|
224
|
-
participantsData = participants.map(participantJid => {
|
|
225
|
-
var _a;
|
|
226
|
-
const participant = (_a = metadata.participants) === null || _a === void 0 ? void 0 : _a.find(p => p.id === participantJid);
|
|
227
|
-
return {
|
|
228
|
-
jid: participantJid,
|
|
229
|
-
pushName: participant === null || participant === void 0 ? void 0 : participant.notify,
|
|
230
|
-
notify: participant === null || participant === void 0 ? void 0 : participant.notify,
|
|
231
|
-
name: participant === null || participant === void 0 ? void 0 : participant.name,
|
|
232
|
-
verifiedName: participant === null || participant === void 0 ? void 0 : participant.verifiedName
|
|
233
|
-
};
|
|
234
|
-
});
|
|
235
|
-
// Auto-update contacts store so getName() works with participant names
|
|
236
|
-
const contactUpdates = participantsData
|
|
237
|
-
.filter(p => p.notify || p.name || p.verifiedName)
|
|
238
|
-
.map(p => ({
|
|
239
|
-
id: p.jid,
|
|
240
|
-
notify: p.notify,
|
|
241
|
-
name: p.name,
|
|
242
|
-
verifiedName: p.verifiedName
|
|
243
|
-
}));
|
|
244
|
-
if (contactUpdates.length > 0) {
|
|
245
|
-
ev.emit('contacts.update', contactUpdates);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ error, groupJid: jid }, 'failed to fetch participant names');
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
ev.emit('group-participants.update', { id: jid, author: message.participant, pushName: message.pushName, participants, participantsData, action });
|
|
253
|
-
};
|
|
205
|
+
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
254
206
|
const emitGroupUpdate = (update) => {
|
|
255
207
|
var _a;
|
|
256
208
|
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
@@ -260,8 +212,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
260
212
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
261
213
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
262
214
|
participants = message.messageStubParameters || [];
|
|
263
|
-
|
|
264
|
-
// mark the chat read only if you left the group
|
|
215
|
+
emitParticipantsUpdate('remove');
|
|
265
216
|
if (participantsIncludesMe()) {
|
|
266
217
|
chat.readOnly = true;
|
|
267
218
|
}
|
|
@@ -273,15 +224,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
273
224
|
if (participantsIncludesMe()) {
|
|
274
225
|
chat.readOnly = false;
|
|
275
226
|
}
|
|
276
|
-
|
|
227
|
+
emitParticipantsUpdate('add');
|
|
277
228
|
break;
|
|
278
229
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
|
|
279
230
|
participants = message.messageStubParameters || [];
|
|
280
|
-
|
|
231
|
+
emitParticipantsUpdate('demote');
|
|
281
232
|
break;
|
|
282
233
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
|
|
283
234
|
participants = message.messageStubParameters || [];
|
|
284
|
-
|
|
235
|
+
emitParticipantsUpdate('promote');
|
|
285
236
|
break;
|
|
286
237
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
287
238
|
const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
|
|
@@ -312,7 +263,6 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
312
263
|
}
|
|
313
264
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
314
265
|
const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
|
|
315
|
-
// we need to fetch the poll creation message to get the poll enc key
|
|
316
266
|
const pollMsg = await getMessage(creationMsgKey);
|
|
317
267
|
if (pollMsg) {
|
|
318
268
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
package/lib/Utils/signal.js
CHANGED
|
@@ -67,11 +67,6 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
67
67
|
for (const node of nodes) {
|
|
68
68
|
WABinary_1.assertNodeErrorFree(node)
|
|
69
69
|
}
|
|
70
|
-
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
|
-
// So Promise.all doesn't really help here,
|
|
72
|
-
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
|
-
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
|
-
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
75
70
|
const chunkSize = 100
|
|
76
71
|
const chunks = lodash_1.chunk(nodes, chunkSize)
|
|
77
72
|
for (const nodesChunk of chunks) {
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -31,7 +31,7 @@ const decompressingIfRequired = (buffer) => {
|
|
|
31
31
|
if (2 & buffer.readUInt8()) {
|
|
32
32
|
buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
|
|
33
33
|
}
|
|
34
|
-
else {
|
|
34
|
+
else {
|
|
35
35
|
buffer = buffer.slice(1);
|
|
36
36
|
}
|
|
37
37
|
return buffer;
|
|
@@ -207,7 +207,6 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
207
207
|
if (listSize === 0 || !header) {
|
|
208
208
|
throw new Error('invalid node');
|
|
209
209
|
}
|
|
210
|
-
// read the attributes in
|
|
211
210
|
const attributesLength = (listSize - 1) >> 1;
|
|
212
211
|
for (let i = 0; i < attributesLength; i++) {
|
|
213
212
|
const key = readString(readByte());
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -252,7 +252,6 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
else if (typeof content === 'undefined') {
|
|
255
|
-
// do nothing
|
|
256
255
|
}
|
|
257
256
|
else {
|
|
258
257
|
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
@@ -4,7 +4,7 @@ exports.getAdditionalNode = exports.getBinaryNodeFilter = exports.binaryNodeToSt
|
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
|
6
6
|
const Utils_1 = require("../Utils")
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
const getBinaryNodeChildren = (node, childTag) => {
|
|
9
9
|
if (Array.isArray(node?.content)) {
|
|
10
10
|
return node.content.filter(item => item.tag === childTag)
|