@systemzero/baileys 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +629 -658
- package/lib/Defaults/index.js +2 -2
- package/lib/Socket/chats.js +12 -1
- package/lib/Socket/groups.js +13 -4
- package/lib/Socket/messages-recv.js +45 -6
- package/lib/Socket/messages-recv.js.bak +1273 -0
- package/lib/Socket/messages-send.js +1 -0
- package/lib/Socket/socket.js +4 -4
- package/lib/Utils/bad-mac-handler.js +158 -0
- package/lib/Utils/generics.js +2 -1
- package/lib/Utils/get-best-version.js +41 -0
- package/lib/Utils/get-name.d.ts +1 -0
- package/lib/Utils/get-name.js +54 -0
- package/lib/Utils/group-status-detection.js +113 -0
- package/lib/Utils/index.js +8 -0
- package/lib/Utils/logger.js +4 -1
- package/lib/Utils/messages-media.js +38 -0
- package/lib/Utils/messages.js +113 -7
- package/lib/Utils/payment-detection.js +212 -0
- package/lib/Utils/payment-guard.d.ts +15 -0
- package/lib/Utils/payment-guard.js +142 -0
- package/lib/Utils/resolve-lid-phone.js +30 -0
- package/lib/Utils/scheduling.js +138 -0
- package/lib/Utils/validate-connection.js +11 -5
- package/lib/WABinary/jid-utils.js +245 -1
- package/package.json +1 -1
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Signal/lid-mapping.d.ts.map +0 -1
- package/lib/Signal/lid-mapping.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Bussines.d.ts.map +0 -1
- package/lib/Types/Bussines.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/browser-utils.d.ts.map +0 -1
- package/lib/Utils/browser-utils.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/pre-key-manager.d.ts.map +0 -1
- package/lib/Utils/pre-key-manager.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/Defaults/index.js
CHANGED
|
@@ -108,8 +108,8 @@ export const MEDIA_HKDF_KEY_MAPPING = {
|
|
|
108
108
|
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
109
109
|
export const MIN_PREKEY_COUNT = 5;
|
|
110
110
|
export const INITIAL_PREKEY_COUNT = 812;
|
|
111
|
-
export const UPLOAD_TIMEOUT =
|
|
112
|
-
export const MIN_UPLOAD_INTERVAL =
|
|
111
|
+
export const UPLOAD_TIMEOUT = 45000; // 45 segundos (era 30, uploads podem demorar mais em conexões lentas)
|
|
112
|
+
export const MIN_UPLOAD_INTERVAL = 30000; // 30 segundos entre uploads normais (era 5s, muito agressivo)
|
|
113
113
|
export const DEFAULT_CACHE_TTLS = {
|
|
114
114
|
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
115
115
|
MSG_RETRY: 60 * 60, // 1 hour
|
package/lib/Socket/chats.js
CHANGED
|
@@ -2,7 +2,7 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
4
|
import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
|
|
5
|
-
import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
|
|
5
|
+
import { ALL_WA_PATCH_NAMES, WAMessageStubType } from '../Types/index.js';
|
|
6
6
|
import { SyncState } from '../Types/State.js';
|
|
7
7
|
import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
|
|
8
8
|
import { makeMutex } from '../Utils/make-mutex.js';
|
|
@@ -787,6 +787,17 @@ export const makeChatsSocket = (config) => {
|
|
|
787
787
|
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
788
788
|
};
|
|
789
789
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
790
|
+
// isSystemNotification — flag para filtrar notificações do sistema (E2E notices, etc)
|
|
791
|
+
const SYSTEM_STUB_TYPES = new Set([
|
|
792
|
+
WAMessageStubType.E2E_ENCRYPTED,
|
|
793
|
+
WAMessageStubType.E2E_DEVICE_CHANGED,
|
|
794
|
+
WAMessageStubType.E2E_IDENTITY_CHANGED,
|
|
795
|
+
WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP,
|
|
796
|
+
WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
797
|
+
]);
|
|
798
|
+
if (msg.messageStubType && SYSTEM_STUB_TYPES.has(msg.messageStubType)) {
|
|
799
|
+
msg.isSystemNotification = true;
|
|
800
|
+
}
|
|
790
801
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
791
802
|
if (!!msg.pushName) {
|
|
792
803
|
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
package/lib/Socket/groups.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { proto } from '../../WAProto/index.js';
|
|
2
2
|
import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
|
|
3
3
|
import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
4
|
-
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
4
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser, sharedLidPhoneCache } from '../WABinary/index.js';
|
|
5
5
|
import { makeChatsSocket } from './chats.js';
|
|
6
6
|
export const makeGroupsSocket = (config) => {
|
|
7
7
|
const sock = makeChatsSocket(config);
|
|
@@ -312,11 +312,20 @@ export const extractGroupMetadata = (result) => {
|
|
|
312
312
|
joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
313
313
|
memberAddMode,
|
|
314
314
|
participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
315
|
-
|
|
315
|
+
const phoneNumber = isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined;
|
|
316
|
+
const lid = isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined;
|
|
317
|
+
|
|
318
|
+
// alimenta o cache compartilhado LID<->telefone com o que o
|
|
319
|
+
// WhatsApp já entrega pronto na lista de participantes do grupo —
|
|
320
|
+
// sem isso, sharedLidPhoneCache.getPhoneForLid() nunca resolve
|
|
321
|
+
// pra membros que só apareceram em grupo (nunca tiveram DM direta)
|
|
322
|
+
if (phoneNumber) sharedLidPhoneCache.set(attrs.jid, phoneNumber);
|
|
323
|
+
if (lid) sharedLidPhoneCache.set(lid, attrs.jid);
|
|
324
|
+
|
|
316
325
|
return {
|
|
317
326
|
id: attrs.jid,
|
|
318
|
-
phoneNumber
|
|
319
|
-
lid
|
|
327
|
+
phoneNumber,
|
|
328
|
+
lid,
|
|
320
329
|
admin: (attrs.type || null)
|
|
321
330
|
};
|
|
322
331
|
}),
|
|
@@ -7,7 +7,7 @@ import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT } from '../Defaul
|
|
|
7
7
|
import { WAMessageStatus, WAMessageStubType } from '../Types/index.js';
|
|
8
8
|
import { aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, extractAddressingContext, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
|
|
9
9
|
import { makeMutex } from '../Utils/make-mutex.js';
|
|
10
|
-
import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
10
|
+
import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET, sharedLidPhoneCache } from '../WABinary/index.js';
|
|
11
11
|
import { extractGroupMetadata } from './groups.js';
|
|
12
12
|
import { makeMessagesSocket } from './messages-send.js';
|
|
13
13
|
export const makeMessagesRecvSocket = (config) => {
|
|
@@ -433,6 +433,13 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
433
433
|
const actingParticipantPn = fullNode.attrs.participant_pn;
|
|
434
434
|
const affectedParticipantLid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || actingParticipantLid;
|
|
435
435
|
const affectedParticipantPn = getBinaryNodeChild(child, 'participant')?.attrs?.phone_number || actingParticipantPn;
|
|
436
|
+
// alimenta cache síncrono com os pares LID↔JID do autor da notificação
|
|
437
|
+
if (isLidUser(actingParticipantLid) && isPnUser(actingParticipantPn)) {
|
|
438
|
+
sharedLidPhoneCache.set(actingParticipantLid, actingParticipantPn);
|
|
439
|
+
}
|
|
440
|
+
if (isLidUser(affectedParticipantLid) && isPnUser(affectedParticipantPn)) {
|
|
441
|
+
sharedLidPhoneCache.set(affectedParticipantLid, affectedParticipantPn);
|
|
442
|
+
}
|
|
436
443
|
switch (child?.tag) {
|
|
437
444
|
case 'create':
|
|
438
445
|
const metadata = extractGroupMetadata(child);
|
|
@@ -476,7 +483,12 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
476
483
|
const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
|
|
477
484
|
msg.messageStubType = WAMessageStubType[stubType];
|
|
478
485
|
const participants = getBinaryNodeChildren(child, 'participant').map(({ attrs }) => {
|
|
479
|
-
//
|
|
486
|
+
// alimenta cache síncrono LID↔JID a partir de participant_pn / phone_number
|
|
487
|
+
if (isLidUser(attrs.jid) && isPnUser(attrs.phone_number)) {
|
|
488
|
+
sharedLidPhoneCache.set(attrs.jid, attrs.phone_number);
|
|
489
|
+
} else if (isPnUser(attrs.jid) && isLidUser(attrs.lid)) {
|
|
490
|
+
sharedLidPhoneCache.set(attrs.lid, attrs.jid);
|
|
491
|
+
}
|
|
480
492
|
return {
|
|
481
493
|
id: attrs.jid,
|
|
482
494
|
phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
@@ -970,11 +982,21 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
970
982
|
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }]);
|
|
971
983
|
await signalRepository.migrateSession(primaryJid, alt);
|
|
972
984
|
}
|
|
985
|
+
// alimenta cache síncrono LID→JID
|
|
986
|
+
if (isPnUser(primaryJid)) sharedLidPhoneCache.set(alt, primaryJid);
|
|
973
987
|
}
|
|
974
988
|
else {
|
|
975
989
|
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }]);
|
|
976
990
|
await signalRepository.migrateSession(alt, primaryJid);
|
|
991
|
+
// alimenta cache síncrono LID→JID
|
|
992
|
+
if (isLidUser(primaryJid) && isPnUser(alt)) sharedLidPhoneCache.set(primaryJid, alt);
|
|
977
993
|
}
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
978
1000
|
}
|
|
979
1001
|
if (msg.key?.remoteJid && msg.key?.id && messageRetryManager) {
|
|
980
1002
|
messageRetryManager.addRecentMessage(msg.key.remoteJid, msg.key.id, msg.message);
|
|
@@ -994,6 +1016,18 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
994
1016
|
}
|
|
995
1017
|
const errorMessage = msg?.messageStubParameters?.[0] || '';
|
|
996
1018
|
const isPreKeyError = errorMessage.includes('PreKey');
|
|
1019
|
+
// A mensagem nunca foi decifrada — não dá pra saber o conteúdo,
|
|
1020
|
+
// mas o evento é emitido mesmo assim para que sistemas de
|
|
1021
|
+
// anti-fraude tratem como suspeita/indecifrável em vez de ignorar.
|
|
1022
|
+
ev.emit('messages.decrypt-failed', {
|
|
1023
|
+
key: msg.key,
|
|
1024
|
+
remoteJid: msg.key?.remoteJid,
|
|
1025
|
+
participant: msg.key?.participant,
|
|
1026
|
+
messageId: msg.key?.id,
|
|
1027
|
+
isPreKeyError,
|
|
1028
|
+
errorMessage,
|
|
1029
|
+
timestamp: msg.messageTimestamp
|
|
1030
|
+
});
|
|
997
1031
|
logger.debug(`[handleMessage] Attempting retry request for failed decryption`);
|
|
998
1032
|
// Handle both pre-key and normal retries in single mutex
|
|
999
1033
|
await retryMutex.mutex(async () => {
|
|
@@ -1002,14 +1036,20 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1002
1036
|
logger.debug({ node }, 'Connection closed, skipping retry');
|
|
1003
1037
|
return;
|
|
1004
1038
|
}
|
|
1005
|
-
// Handle pre-key errors with upload and delay
|
|
1006
1039
|
if (isPreKeyError) {
|
|
1007
1040
|
logger.info({ error: errorMessage }, 'PreKey error detected, uploading and retrying');
|
|
1008
1041
|
try {
|
|
1009
1042
|
logger.debug('Uploading pre-keys for error recovery');
|
|
1010
|
-
|
|
1043
|
+
// Sobe mais chaves de uma vez (30 em vez de 5) — o WhatsApp
|
|
1044
|
+
// às vezes precisa de um conjunto maior pra resolver conflitos
|
|
1045
|
+
// de ID quando a sessão local ficou dessincronizada do servidor.
|
|
1046
|
+
await uploadPreKeys(30, 0, true);
|
|
1047
|
+
// Aumentado de 1000ms pra 2500ms — o servidor do WhatsApp
|
|
1048
|
+
// precisa de mais tempo pra processar e distribuir as novas
|
|
1049
|
+
// chaves antes de a gente tentar o retry, especialmente em
|
|
1050
|
+
// casos de dessincronização severa.
|
|
1011
1051
|
logger.debug('Waiting for server to process new pre-keys');
|
|
1012
|
-
await delay(
|
|
1052
|
+
await delay(2500);
|
|
1013
1053
|
}
|
|
1014
1054
|
catch (uploadErr) {
|
|
1015
1055
|
logger.error({ uploadErr }, 'Pre-key upload failed, proceeding with retry anyway');
|
|
@@ -1023,7 +1063,6 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1023
1063
|
}
|
|
1024
1064
|
catch (err) {
|
|
1025
1065
|
logger.error({ err, isPreKeyError }, 'Failed to handle retry, attempting basic retry');
|
|
1026
|
-
// Still attempt retry even if pre-key upload failed
|
|
1027
1066
|
try {
|
|
1028
1067
|
const encNode = getBinaryNodeChild(node, 'enc');
|
|
1029
1068
|
await sendRetryRequest(node, !encNode);
|