@badzz88/baileys 8.5.5 → 8.5.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/README.md +2 -2
- package/WAProto/WAProto.proto +1256 -75
- package/WAProto/fix-imports.js +69 -79
- package/WAProto/index.d.ts +15254 -71491
- package/WAProto/index.js +19816 -126438
- package/engine-requirements.js +3 -4
- package/package.json +4 -4
- package/src/Defaults/index.js +186 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +86 -0
- package/src/Signal/Group/group_cipher.js +82 -0
- package/src/Signal/Group/index.js +140 -0
- package/src/Signal/Group/keyhelper.js +77 -0
- package/src/Signal/Group/sender-chain-key.js +29 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +51 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +87 -0
- package/src/Signal/Group/sender-message-key.js +29 -0
- package/src/Signal/libsignal.js +455 -0
- package/src/Signal/lid-mapping.js +273 -0
- package/src/Socket/Client/index.js +31 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +61 -0
- package/src/Socket/aigroups.js +221 -0
- package/src/Socket/business.js +411 -0
- package/src/Socket/chats.js +1449 -0
- package/src/Socket/communities.js +463 -0
- package/src/Socket/graphql.js +523 -0
- package/src/Socket/groups.js +516 -0
- package/src/Socket/index.js +31 -0
- package/src/Socket/interactive-handler.js +527 -0
- package/src/Socket/interop.js +339 -0
- package/{lib → src}/Socket/luxu.js +82 -120
- package/src/Socket/managed-account.js +98 -0
- package/src/Socket/messages-recv.js +2685 -0
- package/src/Socket/messages-send.js +2047 -0
- package/src/Socket/mex.js +57 -0
- package/src/Socket/newsletter.js +455 -0
- package/src/Socket/privacy.js +125 -0
- package/src/Socket/registration.js +236 -0
- package/src/Socket/socket.js +983 -0
- package/src/Socket/text-router.js +65 -0
- package/src/Socket/username.js +130 -0
- package/src/Store/index.js +33 -0
- package/{lib → src}/Store/keyed-db.js +21 -11
- package/src/Store/make-cache-manager-store.js +84 -0
- package/src/Store/make-in-memory-store.js +551 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +26 -0
- package/src/Types/Auth.js +31 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +26 -0
- package/src/Types/LabelAssociation.js +8 -0
- package/src/Types/Message.js +93 -0
- package/src/Types/Mex.js +112 -0
- package/src/Types/Newsletter.js +109 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +62 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +56 -0
- package/src/Utils/auth-utils.js +254 -0
- package/src/Utils/browser-utils.js +112 -0
- package/src/Utils/business.js +240 -0
- package/src/Utils/chat-utils.js +1230 -0
- package/src/Utils/command-loader.d.ts +27 -0
- package/src/Utils/command-loader.js +89 -0
- package/src/Utils/companion-reg-client-utils.js +40 -0
- package/src/Utils/consumer-application.js +105 -0
- package/src/Utils/crypto.js +118 -0
- package/src/Utils/curve25519-js.js +242 -0
- package/src/Utils/decode-wa-message.js +529 -0
- package/src/Utils/event-buffer.js +580 -0
- package/src/Utils/generics.js +483 -0
- package/src/Utils/group-history.js +44 -0
- package/src/Utils/history.js +232 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +58 -0
- package/src/Utils/jid-display-normalization.js +195 -0
- package/src/Utils/link-preview.js +135 -0
- package/src/Utils/logger.js +8 -0
- package/src/Utils/lt-hash.js +25 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +471 -0
- package/src/Utils/message-retry-manager.js +217 -0
- package/src/Utils/messages-media.js +843 -0
- package/src/Utils/messages.js +2817 -0
- package/src/Utils/meta-ai-msmsg.js +222 -0
- package/src/Utils/native-bridge.js +68 -0
- package/src/Utils/noise-handler.js +169 -0
- package/src/Utils/offline-node-processor.js +34 -0
- package/src/Utils/pre-key-manager.js +90 -0
- package/src/Utils/process-message.js +950 -0
- package/src/Utils/reporting-utils.js +261 -0
- package/src/Utils/session-pool.d.ts +14 -0
- package/src/Utils/session-pool.js +70 -0
- package/src/Utils/signal.js +217 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/sticker.d.ts +13 -0
- package/src/Utils/sticker.js +123 -0
- package/src/Utils/sync-action-utils.js +45 -0
- package/src/Utils/tc-token-utils.js +158 -0
- package/src/Utils/use-multi-file-auth-state.js +111 -0
- package/src/Utils/validate-connection.js +209 -0
- package/src/Utils/view-once-cache.d.ts +12 -0
- package/src/Utils/view-once-cache.js +63 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +342 -0
- package/{lib → src}/WABinary/encode.js +9 -12
- package/src/WABinary/generic-utils.js +238 -0
- package/src/WABinary/index.js +34 -0
- package/src/WABinary/jid-utils.js +351 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39484 -0
- package/src/WAM/encode.js +149 -0
- package/src/WAM/index.js +32 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncQuery.js +126 -0
- package/src/WAUSync/USyncUser.js +50 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4152 -0
- package/{lib → src}/index.js +51 -49
- package/lib/Defaults/index.js +0 -187
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.js +0 -92
- package/lib/Signal/Group/group_cipher.js +0 -89
- package/lib/Signal/Group/index.js +0 -136
- package/lib/Signal/Group/keyhelper.js +0 -73
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.js +0 -50
- package/lib/Signal/Group/sender-key-record.js +0 -44
- package/lib/Signal/Group/sender-key-state.js +0 -97
- package/lib/Signal/Group/sender-message-key.js +0 -30
- package/lib/Signal/libsignal.js +0 -459
- package/lib/Signal/lid-mapping.js +0 -260
- package/lib/Socket/Client/index.js +0 -30
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/business.js +0 -422
- package/lib/Socket/chats.js +0 -1816
- package/lib/Socket/communities.js +0 -549
- package/lib/Socket/graphql.js +0 -656
- package/lib/Socket/groups.js +0 -764
- package/lib/Socket/index.js +0 -39
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/interop.js +0 -549
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/messages-recv.js +0 -2442
- package/lib/Socket/messages-send.js +0 -1853
- package/lib/Socket/mex.js +0 -60
- package/lib/Socket/newsletter.js +0 -818
- package/lib/Socket/privacy.js +0 -449
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/socket.js +0 -1092
- package/lib/Socket/text-router.js +0 -83
- package/lib/Socket/username.js +0 -243
- package/lib/Store/index.js +0 -36
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.js +0 -604
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.js +0 -29
- package/lib/Types/Auth.js +0 -38
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.js +0 -4
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.js +0 -27
- package/lib/Types/LabelAssociation.js +0 -9
- package/lib/Types/Message.js +0 -95
- package/lib/Types/Mex.js +0 -112
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.js +0 -2
- package/lib/Types/State.js +0 -70
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.js +0 -55
- package/lib/Utils/auth-utils.js +0 -306
- package/lib/Utils/browser-utils.js +0 -114
- package/lib/Utils/business.js +0 -247
- package/lib/Utils/chat-utils.js +0 -1208
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/companion-reg-client-utils.js +0 -42
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/crypto.js +0 -155
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/decode-wa-message.js +0 -560
- package/lib/Utils/event-buffer.js +0 -607
- package/lib/Utils/generics.js +0 -563
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/history.js +0 -244
- package/lib/Utils/identity-change-handler.js +0 -52
- package/lib/Utils/index.js +0 -57
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/link-preview.js +0 -143
- package/lib/Utils/logger.js +0 -9
- package/lib/Utils/lt-hash.js +0 -39
- package/lib/Utils/make-mutex.js +0 -36
- package/lib/Utils/message-composer.js +0 -479
- package/lib/Utils/message-inspect.js +0 -393
- package/lib/Utils/message-retry-manager.js +0 -270
- package/lib/Utils/messages-media.js +0 -896
- package/lib/Utils/messages.js +0 -2904
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/noise-handler.js +0 -196
- package/lib/Utils/offline-node-processor.js +0 -42
- package/lib/Utils/pre-key-manager.js +0 -107
- package/lib/Utils/process-message.js +0 -1048
- package/lib/Utils/reporting-utils.js +0 -262
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/signal.js +0 -224
- package/lib/Utils/stanza-ack.js +0 -40
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/sticker.js +0 -145
- package/lib/Utils/sync-action-utils.js +0 -54
- package/lib/Utils/tc-token-utils.js +0 -161
- package/lib/Utils/use-multi-file-auth-state.js +0 -121
- package/lib/Utils/validate-connection.js +0 -219
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/WABinary/constants.js +0 -1304
- package/lib/WABinary/decode.js +0 -343
- package/lib/WABinary/generic-utils.js +0 -240
- package/lib/WABinary/index.js +0 -33
- package/lib/WABinary/jid-utils.js +0 -361
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.js +0 -13
- package/lib/WAM/constants.js +0 -39486
- package/lib/WAM/encode.js +0 -142
- package/lib/WAM/index.js +0 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -43
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -54
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -59
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -39
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -27
- package/lib/WAUSync/Protocols/index.js +0 -39
- package/lib/WAUSync/USyncBackoff.js +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -133
- package/lib/WAUSync/USyncUser.js +0 -50
- package/lib/WAUSync/index.js +0 -31
- package/lib/antiban.js +0 -4637
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
|
|
4
|
-
const boom_1 = require('@hapi/boom')
|
|
5
|
-
const { proto } = require('../../WAProto/index.js')
|
|
6
|
-
const WABinary_1 = require('../WABinary')
|
|
7
|
-
const crypto_2 = require('./crypto')
|
|
8
|
-
const generics_1 = require('./generics')
|
|
9
|
-
const messages_media_1 = require('./messages-media')
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const getContentType = content => {
|
|
13
|
-
if (content) {
|
|
14
|
-
const keys = Object.keys(content)
|
|
15
|
-
const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage')
|
|
16
|
-
return key
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.getContentType = getContentType
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const normalizeMessageContent = content => {
|
|
23
|
-
if (!content) {
|
|
24
|
-
return undefined
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < 5; i++) {
|
|
28
|
-
const inner = getFutureProofMessage(content)
|
|
29
|
-
if (!inner) {
|
|
30
|
-
break
|
|
31
|
-
}
|
|
32
|
-
content = inner.message
|
|
33
|
-
}
|
|
34
|
-
return content
|
|
35
|
-
function getFutureProofMessage(message) {
|
|
36
|
-
return (
|
|
37
|
-
message.ephemeralMessage ||
|
|
38
|
-
message.viewOnceMessage ||
|
|
39
|
-
message.documentWithCaptionMessage ||
|
|
40
|
-
message.viewOnceMessageV2 ||
|
|
41
|
-
message.viewOnceMessageV2Extension ||
|
|
42
|
-
message.editedMessage ||
|
|
43
|
-
message.groupMentionedMessage ||
|
|
44
|
-
message.botInvokeMessage ||
|
|
45
|
-
message.lottieStickerMessage ||
|
|
46
|
-
message.eventCoverImage ||
|
|
47
|
-
message.statusMentionMessage ||
|
|
48
|
-
message.pollCreationOptionImageMessage ||
|
|
49
|
-
message.associatedChildMessage ||
|
|
50
|
-
message.groupStatusMentionMessage ||
|
|
51
|
-
message.pollCreationMessageV4 ||
|
|
52
|
-
message.pollCreationMessageV5 ||
|
|
53
|
-
message.statusAddYours ||
|
|
54
|
-
message.groupStatusMessage ||
|
|
55
|
-
message.limitSharingMessage ||
|
|
56
|
-
message.botTaskMessage ||
|
|
57
|
-
message.questionMessage ||
|
|
58
|
-
message.groupStatusMessageV2 ||
|
|
59
|
-
message.botForwardedMessage ||
|
|
60
|
-
message.questionReplyMessage ||
|
|
61
|
-
message.newsletterAdminProfileMessage ||
|
|
62
|
-
message.newsletterAdminProfileMessageV2 ||
|
|
63
|
-
message.newsletterAdminProfileStatusMessage ||
|
|
64
|
-
message.spoilerMessage ||
|
|
65
|
-
message.groupStatusV3Message ||
|
|
66
|
-
message.pollCreationMessageV6
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.normalizeMessageContent = normalizeMessageContent
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const extractMessageContent = content => {
|
|
74
|
-
const extractFromTemplateMessage = msg => {
|
|
75
|
-
if (msg.imageMessage) {
|
|
76
|
-
return { imageMessage: msg.imageMessage }
|
|
77
|
-
} else if (msg.documentMessage) {
|
|
78
|
-
return { documentMessage: msg.documentMessage }
|
|
79
|
-
} else if (msg.videoMessage) {
|
|
80
|
-
return { videoMessage: msg.videoMessage }
|
|
81
|
-
} else if (msg.locationMessage) {
|
|
82
|
-
return { locationMessage: msg.locationMessage }
|
|
83
|
-
} else {
|
|
84
|
-
return {
|
|
85
|
-
conversation:
|
|
86
|
-
'contentText' in msg ? msg.contentText : 'hydratedContentText' in msg ? msg.hydratedContentText : ''
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
content = normalizeMessageContent(content)
|
|
91
|
-
if (content?.buttonsMessage) {
|
|
92
|
-
return extractFromTemplateMessage(content.buttonsMessage)
|
|
93
|
-
}
|
|
94
|
-
if (content?.templateMessage?.hydratedFourRowTemplate) {
|
|
95
|
-
return extractFromTemplateMessage(content?.templateMessage?.hydratedFourRowTemplate)
|
|
96
|
-
}
|
|
97
|
-
if (content?.templateMessage?.hydratedTemplate) {
|
|
98
|
-
return extractFromTemplateMessage(content?.templateMessage?.hydratedTemplate)
|
|
99
|
-
}
|
|
100
|
-
if (content?.templateMessage?.fourRowTemplate) {
|
|
101
|
-
return extractFromTemplateMessage(content?.templateMessage?.fourRowTemplate)
|
|
102
|
-
}
|
|
103
|
-
return content
|
|
104
|
-
}
|
|
105
|
-
exports.extractMessageContent = extractMessageContent
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const getDevice = id =>
|
|
109
|
-
/^3A.{18}$/.test(id)
|
|
110
|
-
? 'ios'
|
|
111
|
-
: /^3E.{20}$/.test(id)
|
|
112
|
-
? 'web'
|
|
113
|
-
: /^(.{21}|.{32})$/.test(id)
|
|
114
|
-
? 'android'
|
|
115
|
-
: /^(3F|.{18}$)/.test(id)
|
|
116
|
-
? 'desktop'
|
|
117
|
-
: 'api/baileys'
|
|
118
|
-
exports.getDevice = getDevice
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const updateMessageWithReceipt = (msg, receipt) => {
|
|
122
|
-
msg.userReceipt = msg.userReceipt || []
|
|
123
|
-
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid)
|
|
124
|
-
if (recp) {
|
|
125
|
-
Object.assign(recp, receipt)
|
|
126
|
-
} else {
|
|
127
|
-
msg.userReceipt.push(receipt)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.updateMessageWithReceipt = updateMessageWithReceipt
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const updateMessageWithReaction = (msg, reaction) => {
|
|
134
|
-
const authorID = (0, generics_1.getKeyAuthor)(reaction.key)
|
|
135
|
-
const reactions = (msg.reactions || []).filter(r => (0, generics_1.getKeyAuthor)(r.key) !== authorID)
|
|
136
|
-
reaction.text = reaction.text || ''
|
|
137
|
-
reactions.push(reaction)
|
|
138
|
-
msg.reactions = reactions
|
|
139
|
-
}
|
|
140
|
-
exports.updateMessageWithReaction = updateMessageWithReaction
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const updateMessageWithPollUpdate = (msg, update) => {
|
|
144
|
-
const authorID = (0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey)
|
|
145
|
-
const reactions = (msg.pollUpdates || []).filter(
|
|
146
|
-
r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID
|
|
147
|
-
)
|
|
148
|
-
if (update.vote?.selectedOptions?.length) {
|
|
149
|
-
reactions.push(update)
|
|
150
|
-
}
|
|
151
|
-
msg.pollUpdates = reactions
|
|
152
|
-
}
|
|
153
|
-
exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const updateMessageWithEventResponse = (msg, update) => {
|
|
157
|
-
const authorID = (0, generics_1.getKeyAuthor)(update.eventResponseMessageKey)
|
|
158
|
-
const responses = (msg.eventResponses || []).filter(
|
|
159
|
-
r => (0, generics_1.getKeyAuthor)(r.eventResponseMessageKey) !== authorID
|
|
160
|
-
)
|
|
161
|
-
responses.push(update)
|
|
162
|
-
msg.eventResponses = responses
|
|
163
|
-
}
|
|
164
|
-
exports.updateMessageWithEventResponse = updateMessageWithEventResponse
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
168
|
-
const opts =
|
|
169
|
-
message?.pollCreationMessage?.options ||
|
|
170
|
-
message?.pollCreationMessageV2?.options ||
|
|
171
|
-
message?.pollCreationMessageV3?.options ||
|
|
172
|
-
message?.pollCreationMessageV5?.options ||
|
|
173
|
-
message?.pollCreationMessageV6?.options ||
|
|
174
|
-
message?.pollCreationMessageV4?.message?.pollCreationMessage?.options ||
|
|
175
|
-
message?.pollCreationMessageV4?.message?.pollCreationMessageV3?.options ||
|
|
176
|
-
[]
|
|
177
|
-
const voteHashMap = opts.reduce((acc, opt) => {
|
|
178
|
-
const hash = (0, crypto_2.sha256)(Buffer.from(opt.optionName || '')).toString()
|
|
179
|
-
acc[hash] = {
|
|
180
|
-
name: opt.optionName || '',
|
|
181
|
-
voters: []
|
|
182
|
-
}
|
|
183
|
-
return acc
|
|
184
|
-
}, {})
|
|
185
|
-
for (const update of pollUpdates || []) {
|
|
186
|
-
const { vote } = update
|
|
187
|
-
if (!vote) {
|
|
188
|
-
continue
|
|
189
|
-
}
|
|
190
|
-
for (const option of vote.selectedOptions || []) {
|
|
191
|
-
const hash = option.toString()
|
|
192
|
-
let data = voteHashMap[hash]
|
|
193
|
-
if (!data) {
|
|
194
|
-
voteHashMap[hash] = {
|
|
195
|
-
name: 'Unknown',
|
|
196
|
-
voters: []
|
|
197
|
-
}
|
|
198
|
-
data = voteHashMap[hash]
|
|
199
|
-
}
|
|
200
|
-
voteHashMap[hash].voters.push((0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey, meId))
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return Object.values(voteHashMap)
|
|
204
|
-
}
|
|
205
|
-
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const aggregateMessageKeysNotFromMe = keys => {
|
|
209
|
-
const keyMap = {}
|
|
210
|
-
for (const { remoteJid, id, participant, fromMe, sts } of keys) {
|
|
211
|
-
if (!fromMe) {
|
|
212
|
-
const uqKey = `${remoteJid}:${participant || ''}`
|
|
213
|
-
if (!keyMap[uqKey]) {
|
|
214
|
-
keyMap[uqKey] = {
|
|
215
|
-
jid: remoteJid,
|
|
216
|
-
participant: participant,
|
|
217
|
-
messageIds: [],
|
|
218
|
-
|
|
219
|
-
sts: sts
|
|
220
|
-
}
|
|
221
|
-
} else if (keyMap[uqKey].sts !== sts) {
|
|
222
|
-
|
|
223
|
-
keyMap[uqKey].sts = undefined
|
|
224
|
-
}
|
|
225
|
-
keyMap[uqKey].messageIds.push(id)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return Object.values(keyMap)
|
|
229
|
-
}
|
|
230
|
-
exports.aggregateMessageKeysNotFromMe = aggregateMessageKeysNotFromMe
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const isScheduledMessage = msg => !!msg?.scheduledMessageMetadata?.scheduledTime
|
|
234
|
-
exports.isScheduledMessage = isScheduledMessage
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const getScheduledMessageTime = msg => {
|
|
238
|
-
const t = msg?.scheduledMessageMetadata?.scheduledTime
|
|
239
|
-
if (!t) return null
|
|
240
|
-
return new Date(Number(t) * 1000)
|
|
241
|
-
}
|
|
242
|
-
exports.getScheduledMessageTime = getScheduledMessageTime
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const getMessagePaymentInfo = msg => msg?.paymentInfo || msg?.quotedPaymentInfo || null
|
|
246
|
-
exports.getMessagePaymentInfo = getMessagePaymentInfo
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const getMessageCommentMetadata = msg => msg?.commentMetadata || null
|
|
250
|
-
exports.getMessageCommentMetadata = getMessageCommentMetadata
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const getMessageAddOns = msg => msg?.messageAddOns || []
|
|
254
|
-
exports.getMessageAddOns = getMessageAddOns
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const getPollCorrectAnswer = pollMsg => {
|
|
258
|
-
const poll =
|
|
259
|
-
pollMsg?.pollCreationMessage ||
|
|
260
|
-
pollMsg?.pollCreationMessageV2 ||
|
|
261
|
-
pollMsg?.pollCreationMessageV3 ||
|
|
262
|
-
pollMsg?.pollCreationMessageV5 ||
|
|
263
|
-
pollMsg?.pollCreationMessageV6
|
|
264
|
-
if (!poll) return null
|
|
265
|
-
const isQuiz = poll.pollType === proto.Message.PollType?.QUIZ || poll.pollType === 1
|
|
266
|
-
return isQuiz ? poll.correctAnswer?.optionName || null : null
|
|
267
|
-
}
|
|
268
|
-
exports.getPollCorrectAnswer = getPollCorrectAnswer
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
function getAggregateResponsesInEventMessage({ eventResponses }, meLid) {
|
|
272
|
-
const responseTypes = ['GOING', 'NOT_GOING', 'MAYBE']
|
|
273
|
-
const responseMap = {}
|
|
274
|
-
|
|
275
|
-
for (const type of responseTypes) {
|
|
276
|
-
responseMap[type] = {
|
|
277
|
-
response: type,
|
|
278
|
-
responders: []
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
for (const update of eventResponses) {
|
|
282
|
-
const { response } = update.response || {}
|
|
283
|
-
const responseType = proto.Message.EventResponseMessage.EventResponseType[response]
|
|
284
|
-
if (responseType !== 'UNKNOWN' && responseMap[responseType]) {
|
|
285
|
-
responseMap[responseType].responders.push(generics_1.getKeyAuthor(update.eventResponseMessageKey, meLid))
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return Object.values(responseMap)
|
|
290
|
-
}
|
|
291
|
-
exports.getAggregateResponsesInEventMessage = getAggregateResponsesInEventMessage
|
|
292
|
-
|
|
293
|
-
const REUPLOAD_REQUIRED_STATUS = [410, 404]
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
297
|
-
const result = await downloadMsg().catch(async error => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const errorStatus =
|
|
302
|
-
typeof error?.status === 'number'
|
|
303
|
-
? error.status
|
|
304
|
-
: typeof error?.output?.statusCode === 'number'
|
|
305
|
-
? error.output.statusCode
|
|
306
|
-
: undefined
|
|
307
|
-
if (ctx && typeof errorStatus === 'number' && REUPLOAD_REQUIRED_STATUS.includes(errorStatus)) {
|
|
308
|
-
ctx.logger.info({ key: message.key }, 'sending reupload media request...')
|
|
309
|
-
message = await ctx.reuploadRequest(message)
|
|
310
|
-
const result = await downloadMsg()
|
|
311
|
-
return result
|
|
312
|
-
}
|
|
313
|
-
throw error
|
|
314
|
-
})
|
|
315
|
-
return result
|
|
316
|
-
async function downloadMsg() {
|
|
317
|
-
const mContent = extractMessageContent(message.message)
|
|
318
|
-
if (!mContent) {
|
|
319
|
-
throw new boom_1.Boom('No message present', { statusCode: 400, data: message })
|
|
320
|
-
}
|
|
321
|
-
const contentType = getContentType(mContent)
|
|
322
|
-
let mediaType = contentType?.replace('Message', '')
|
|
323
|
-
const media = mContent[contentType]
|
|
324
|
-
if (!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media))) {
|
|
325
|
-
throw new boom_1.Boom(`"${contentType}" message is not a media message`)
|
|
326
|
-
}
|
|
327
|
-
let download
|
|
328
|
-
if ('thumbnailDirectPath' in media && !('url' in media)) {
|
|
329
|
-
download = {
|
|
330
|
-
directPath: media.thumbnailDirectPath,
|
|
331
|
-
mediaKey: media.mediaKey
|
|
332
|
-
}
|
|
333
|
-
mediaType = 'thumbnail-link'
|
|
334
|
-
} else {
|
|
335
|
-
download = media
|
|
336
|
-
}
|
|
337
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(download, mediaType, options)
|
|
338
|
-
if (type === 'buffer') {
|
|
339
|
-
const bufferArray = []
|
|
340
|
-
for await (const chunk of stream) {
|
|
341
|
-
bufferArray.push(chunk)
|
|
342
|
-
}
|
|
343
|
-
return Buffer.concat(bufferArray)
|
|
344
|
-
}
|
|
345
|
-
return stream
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
exports.downloadMediaMessage = downloadMediaMessage
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const assertMediaContent = content => {
|
|
352
|
-
content = extractMessageContent(content)
|
|
353
|
-
const mediaContent =
|
|
354
|
-
content?.documentMessage ||
|
|
355
|
-
content?.imageMessage ||
|
|
356
|
-
content?.videoMessage ||
|
|
357
|
-
content?.audioMessage ||
|
|
358
|
-
content?.stickerMessage
|
|
359
|
-
if (!mediaContent) {
|
|
360
|
-
throw new boom_1.Boom('given message is not a media message', { statusCode: 400, data: content })
|
|
361
|
-
}
|
|
362
|
-
return mediaContent
|
|
363
|
-
}
|
|
364
|
-
exports.assertMediaContent = assertMediaContent
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const toJid = id => {
|
|
368
|
-
if (!id) return ''
|
|
369
|
-
if (id.includes('@')) return id
|
|
370
|
-
return `${id}@s.whatsapp.net`
|
|
371
|
-
}
|
|
372
|
-
exports.toJid = toJid
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const getSenderLid = message => {
|
|
376
|
-
const k = message.key
|
|
377
|
-
if (!k) {
|
|
378
|
-
return { jid: '', lid: '' }
|
|
379
|
-
}
|
|
380
|
-
const jid = k.participant || k.remoteJid || ''
|
|
381
|
-
if (jid.endsWith('@lid') || jid.endsWith('@hosted.lid')) {
|
|
382
|
-
return { jid, lid: jid }
|
|
383
|
-
}
|
|
384
|
-
if (k.lid && typeof k.lid === 'string') {
|
|
385
|
-
const lid = k.lid.includes('@') ? k.lid : (0, WABinary_1.jidEncode)(k.lid, 'lid')
|
|
386
|
-
return { jid, lid }
|
|
387
|
-
}
|
|
388
|
-
if (k.participantLid && (0, WABinary_1.isLidUser)(k.participantLid)) {
|
|
389
|
-
return { jid, lid: k.participantLid }
|
|
390
|
-
}
|
|
391
|
-
return { jid, lid: '' }
|
|
392
|
-
}
|
|
393
|
-
exports.getSenderLid = getSenderLid
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.MessageRetryManager = exports.RetryReason = void 0
|
|
4
|
-
const lru_cache_1 = require('lru-cache')
|
|
5
|
-
/** Number of sent messages to cache in memory for handling retry receipts */
|
|
6
|
-
const RECENT_MESSAGES_SIZE = 512
|
|
7
|
-
const MESSAGE_KEY_SEPARATOR = '\u0000'
|
|
8
|
-
/** Timeout for session recreation - 1 hour */
|
|
9
|
-
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000 // 1 hour in milliseconds
|
|
10
|
-
const PHONE_REQUEST_DELAY = 3000
|
|
11
|
-
// Retry reason codes matching WhatsApp Web's Signal error codes.
|
|
12
|
-
var RetryReason
|
|
13
|
-
;(function (RetryReason) {
|
|
14
|
-
RetryReason[(RetryReason['UnknownError'] = 0)] = 'UnknownError'
|
|
15
|
-
RetryReason[(RetryReason['SignalErrorNoSession'] = 1)] = 'SignalErrorNoSession'
|
|
16
|
-
RetryReason[(RetryReason['SignalErrorInvalidKey'] = 2)] = 'SignalErrorInvalidKey'
|
|
17
|
-
RetryReason[(RetryReason['SignalErrorInvalidKeyId'] = 3)] = 'SignalErrorInvalidKeyId'
|
|
18
|
-
/** MAC verification failed - most common cause of decryption failures */
|
|
19
|
-
RetryReason[(RetryReason['SignalErrorInvalidMessage'] = 4)] = 'SignalErrorInvalidMessage'
|
|
20
|
-
RetryReason[(RetryReason['SignalErrorInvalidSignature'] = 5)] = 'SignalErrorInvalidSignature'
|
|
21
|
-
RetryReason[(RetryReason['SignalErrorFutureMessage'] = 6)] = 'SignalErrorFutureMessage'
|
|
22
|
-
/** Explicit MAC failure - session is definitely out of sync */
|
|
23
|
-
RetryReason[(RetryReason['SignalErrorBadMac'] = 7)] = 'SignalErrorBadMac'
|
|
24
|
-
RetryReason[(RetryReason['SignalErrorInvalidSession'] = 8)] = 'SignalErrorInvalidSession'
|
|
25
|
-
RetryReason[(RetryReason['SignalErrorInvalidMsgKey'] = 9)] = 'SignalErrorInvalidMsgKey'
|
|
26
|
-
RetryReason[(RetryReason['BadBroadcastEphemeralSetting'] = 10)] = 'BadBroadcastEphemeralSetting'
|
|
27
|
-
RetryReason[(RetryReason['UnknownCompanionNoPrekey'] = 11)] = 'UnknownCompanionNoPrekey'
|
|
28
|
-
RetryReason[(RetryReason['AdvFailure'] = 12)] = 'AdvFailure'
|
|
29
|
-
RetryReason[(RetryReason['StatusRevokeDelay'] = 13)] = 'StatusRevokeDelay'
|
|
30
|
-
})(RetryReason || (exports.RetryReason = RetryReason = {}))
|
|
31
|
-
/** Error codes that indicate a MAC failure and require immediate session recreation */
|
|
32
|
-
const MAC_ERROR_CODES = new Set([RetryReason.SignalErrorInvalidMessage, RetryReason.SignalErrorBadMac])
|
|
33
|
-
class MessageRetryManager {
|
|
34
|
-
constructor(logger, maxMsgRetryCount) {
|
|
35
|
-
this.logger = logger
|
|
36
|
-
this.recentMessagesMap = new lru_cache_1.LRUCache({
|
|
37
|
-
max: RECENT_MESSAGES_SIZE,
|
|
38
|
-
ttl: 5 * 60 * 1000,
|
|
39
|
-
ttlAutopurge: true,
|
|
40
|
-
dispose: (_value, key) => {
|
|
41
|
-
const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR)
|
|
42
|
-
if (separatorIndex > -1) {
|
|
43
|
-
const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length)
|
|
44
|
-
this.messageKeyIndex.delete(messageId)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
this.messageKeyIndex = new Map()
|
|
49
|
-
this.sessionRecreateHistory = new lru_cache_1.LRUCache({
|
|
50
|
-
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
51
|
-
ttlAutopurge: true
|
|
52
|
-
})
|
|
53
|
-
this.retryCounters = new lru_cache_1.LRUCache({
|
|
54
|
-
ttl: 15 * 60 * 1000,
|
|
55
|
-
ttlAutopurge: true,
|
|
56
|
-
updateAgeOnGet: true
|
|
57
|
-
}) // 15 minutes TTL
|
|
58
|
-
this.baseKeys = new lru_cache_1.LRUCache({
|
|
59
|
-
max: 1024,
|
|
60
|
-
ttl: 15 * 60 * 1000,
|
|
61
|
-
ttlAutopurge: true
|
|
62
|
-
})
|
|
63
|
-
this.pendingPhoneRequests = {}
|
|
64
|
-
this.maxMsgRetryCount = 5
|
|
65
|
-
this.statistics = {
|
|
66
|
-
totalRetries: 0,
|
|
67
|
-
successfulRetries: 0,
|
|
68
|
-
failedRetries: 0,
|
|
69
|
-
mediaRetries: 0,
|
|
70
|
-
sessionRecreations: 0,
|
|
71
|
-
phoneRequests: 0
|
|
72
|
-
}
|
|
73
|
-
this.maxMsgRetryCount = maxMsgRetryCount
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Add a recent message to the cache for retry handling
|
|
77
|
-
*/
|
|
78
|
-
addRecentMessage(to, id, message) {
|
|
79
|
-
const key = { to, id }
|
|
80
|
-
const keyStr = this.keyToString(key)
|
|
81
|
-
// Add new message
|
|
82
|
-
this.recentMessagesMap.set(keyStr, {
|
|
83
|
-
message,
|
|
84
|
-
timestamp: Date.now()
|
|
85
|
-
})
|
|
86
|
-
this.messageKeyIndex.set(id, keyStr)
|
|
87
|
-
this.logger.debug(`Added message to retry cache: ${to}/${id}`)
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get a recent message from the cache
|
|
91
|
-
*/
|
|
92
|
-
getRecentMessage(to, id) {
|
|
93
|
-
const key = { to, id }
|
|
94
|
-
const keyStr = this.keyToString(key)
|
|
95
|
-
return this.recentMessagesMap.get(keyStr)
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if a session should be recreated based on retry count, history, and error code.
|
|
99
|
-
* MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
|
|
100
|
-
*/
|
|
101
|
-
shouldRecreateSession(jid, hasSession, errorCode) {
|
|
102
|
-
// If we don't have a session, always recreate
|
|
103
|
-
if (!hasSession) {
|
|
104
|
-
this.sessionRecreateHistory.set(jid, Date.now())
|
|
105
|
-
this.statistics.sessionRecreations++
|
|
106
|
-
return {
|
|
107
|
-
reason: "we don't have a Signal session with them",
|
|
108
|
-
recreate: true
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// IMMEDIATE recreation for MAC errors - session is definitely out of sync
|
|
112
|
-
if (errorCode !== undefined && MAC_ERROR_CODES.has(errorCode)) {
|
|
113
|
-
this.sessionRecreateHistory.set(jid, Date.now())
|
|
114
|
-
this.statistics.sessionRecreations++
|
|
115
|
-
this.logger.warn(
|
|
116
|
-
{ jid, errorCode: RetryReason[errorCode] },
|
|
117
|
-
'MAC error detected, forcing immediate session recreation'
|
|
118
|
-
)
|
|
119
|
-
return {
|
|
120
|
-
reason: `MAC error (code ${errorCode}: ${RetryReason[errorCode]}), immediate session recreation`,
|
|
121
|
-
recreate: true
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const now = Date.now()
|
|
125
|
-
const prevTime = this.sessionRecreateHistory.get(jid)
|
|
126
|
-
// If no previous recreation or it's been more than an hour
|
|
127
|
-
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
128
|
-
this.sessionRecreateHistory.set(jid, now)
|
|
129
|
-
this.statistics.sessionRecreations++
|
|
130
|
-
return {
|
|
131
|
-
reason: 'retry count > 1 and over an hour since last recreation',
|
|
132
|
-
recreate: true
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return { reason: '', recreate: false }
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Parse error code from retry receipt's retry node.
|
|
139
|
-
* Returns undefined if no error code is present.
|
|
140
|
-
*/
|
|
141
|
-
parseRetryErrorCode(errorAttr) {
|
|
142
|
-
if (errorAttr === undefined || errorAttr === '') {
|
|
143
|
-
return undefined
|
|
144
|
-
}
|
|
145
|
-
const code = parseInt(errorAttr, 10)
|
|
146
|
-
if (Number.isNaN(code)) {
|
|
147
|
-
return undefined
|
|
148
|
-
}
|
|
149
|
-
// Validate it's a known RetryReason
|
|
150
|
-
if (code >= RetryReason.UnknownError && code <= RetryReason.StatusRevokeDelay) {
|
|
151
|
-
return code
|
|
152
|
-
}
|
|
153
|
-
return RetryReason.UnknownError
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Check if an error code indicates a MAC failure
|
|
157
|
-
*/
|
|
158
|
-
isMacError(errorCode) {
|
|
159
|
-
return errorCode !== undefined && MAC_ERROR_CODES.has(errorCode)
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Increment retry counter for a message
|
|
163
|
-
*/
|
|
164
|
-
incrementRetryCount(messageId) {
|
|
165
|
-
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1)
|
|
166
|
-
this.statistics.totalRetries++
|
|
167
|
-
return this.retryCounters.get(messageId)
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Get retry count for a message
|
|
171
|
-
*/
|
|
172
|
-
getRetryCount(messageId) {
|
|
173
|
-
return this.retryCounters.get(messageId) || 0
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Check if message has exceeded maximum retry attempts
|
|
177
|
-
*/
|
|
178
|
-
hasExceededMaxRetries(messageId) {
|
|
179
|
-
return this.getRetryCount(messageId) >= this.maxMsgRetryCount
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Mark retry as successful
|
|
183
|
-
*/
|
|
184
|
-
markRetrySuccess(messageId) {
|
|
185
|
-
this.statistics.successfulRetries++
|
|
186
|
-
// Clean up retry counter for successful message
|
|
187
|
-
this.retryCounters.delete(messageId)
|
|
188
|
-
this.cancelPendingPhoneRequest(messageId)
|
|
189
|
-
this.removeRecentMessage(messageId)
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Mark retry as failed
|
|
193
|
-
*/
|
|
194
|
-
markRetryFailed(messageId) {
|
|
195
|
-
this.statistics.failedRetries++
|
|
196
|
-
this.retryCounters.delete(messageId)
|
|
197
|
-
this.cancelPendingPhoneRequest(messageId)
|
|
198
|
-
this.removeRecentMessage(messageId)
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Schedule a phone request with delay
|
|
202
|
-
*/
|
|
203
|
-
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
204
|
-
// Cancel any existing request for this message
|
|
205
|
-
this.cancelPendingPhoneRequest(messageId)
|
|
206
|
-
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
207
|
-
delete this.pendingPhoneRequests[messageId]
|
|
208
|
-
this.statistics.phoneRequests++
|
|
209
|
-
callback()
|
|
210
|
-
}, delay)
|
|
211
|
-
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`)
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Cancel pending phone request
|
|
215
|
-
*/
|
|
216
|
-
cancelPendingPhoneRequest(messageId) {
|
|
217
|
-
const timeout = this.pendingPhoneRequests[messageId]
|
|
218
|
-
if (timeout) {
|
|
219
|
-
clearTimeout(timeout)
|
|
220
|
-
delete this.pendingPhoneRequests[messageId]
|
|
221
|
-
this.logger.debug(`Cancelled pending phone request for message ${messageId}`)
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
clear() {
|
|
225
|
-
this.recentMessagesMap.clear()
|
|
226
|
-
this.messageKeyIndex.clear()
|
|
227
|
-
this.sessionRecreateHistory.clear()
|
|
228
|
-
this.retryCounters.clear()
|
|
229
|
-
this.baseKeys.clear()
|
|
230
|
-
for (const messageId of Object.keys(this.pendingPhoneRequests)) {
|
|
231
|
-
this.cancelPendingPhoneRequest(messageId)
|
|
232
|
-
}
|
|
233
|
-
this.statistics = {
|
|
234
|
-
totalRetries: 0,
|
|
235
|
-
successfulRetries: 0,
|
|
236
|
-
failedRetries: 0,
|
|
237
|
-
mediaRetries: 0,
|
|
238
|
-
sessionRecreations: 0,
|
|
239
|
-
phoneRequests: 0
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
saveBaseKey(addr, msgId, baseKey) {
|
|
243
|
-
this.baseKeys.set(`${addr}:${msgId}`, baseKey)
|
|
244
|
-
}
|
|
245
|
-
hasSameBaseKey(addr, msgId, baseKey) {
|
|
246
|
-
const stored = this.baseKeys.get(`${addr}:${msgId}`)
|
|
247
|
-
if (!stored || stored.length !== baseKey.length) {
|
|
248
|
-
return false
|
|
249
|
-
}
|
|
250
|
-
for (let i = 0; i < stored.length; i++) {
|
|
251
|
-
if (stored[i] !== baseKey[i]) return false
|
|
252
|
-
}
|
|
253
|
-
return true
|
|
254
|
-
}
|
|
255
|
-
deleteBaseKey(addr, msgId) {
|
|
256
|
-
this.baseKeys.delete(`${addr}:${msgId}`)
|
|
257
|
-
}
|
|
258
|
-
keyToString(key) {
|
|
259
|
-
return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`
|
|
260
|
-
}
|
|
261
|
-
removeRecentMessage(messageId) {
|
|
262
|
-
const keyStr = this.messageKeyIndex.get(messageId)
|
|
263
|
-
if (!keyStr) {
|
|
264
|
-
return
|
|
265
|
-
}
|
|
266
|
-
this.recentMessagesMap.delete(keyStr)
|
|
267
|
-
this.messageKeyIndex.delete(messageId)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
exports.MessageRetryManager = MessageRetryManager
|