kage-baileys 3.0.6 → 3.2.4

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.
Files changed (217) hide show
  1. package/Example/connection.cjs +4 -0
  2. package/README.MD +4726 -48
  3. package/README.md +5941 -0
  4. package/WAProto/WAProto.proto +3395 -415
  5. package/WAProto/compat.cjs +12 -0
  6. package/WAProto/index.d.ts +47104 -19888
  7. package/WAProto/index.js +131979 -57361
  8. package/lib/Addon/http-error.js +43 -0
  9. package/lib/Addon/index.js +32 -0
  10. package/lib/Addon/keyed-db.js +250 -0
  11. package/lib/Addon/link-preview.js +82 -0
  12. package/lib/Defaults/baileys-version.json +3 -0
  13. package/lib/Defaults/connection.js +110 -0
  14. package/lib/Defaults/constants.js +156 -0
  15. package/lib/Defaults/history.js +46 -0
  16. package/lib/Defaults/index.js +230 -0
  17. package/lib/Defaults/media.js +104 -0
  18. package/lib/Defaults/phonenumber-mcc.json +223 -0
  19. package/lib/Defaults/prefix.js +44 -0
  20. package/lib/Extensions/business-advanced.js +382 -0
  21. package/lib/Extensions/business.js +159 -0
  22. package/lib/Extensions/chats-advanced.js +1106 -0
  23. package/lib/Extensions/chats.js +349 -0
  24. package/lib/Extensions/communities-advanced.js +430 -0
  25. package/lib/Extensions/community.js +94 -0
  26. package/lib/Extensions/groups-advanced.js +343 -0
  27. package/lib/Extensions/index.js +30 -0
  28. package/lib/Extensions/messages-recv-advanced.js +1690 -0
  29. package/lib/Extensions/messages-send-advanced.js +622 -0
  30. package/lib/Extensions/messages-send.js +1380 -0
  31. package/lib/Extensions/newsletter-advanced.js +228 -0
  32. package/lib/Extensions/newsletter.js +72 -0
  33. package/lib/Extensions/socket.js +389 -0
  34. package/lib/Modded/message_builder.js +2084 -4
  35. package/lib/Signal/Group/ciphertext-message.js +54 -0
  36. package/lib/Signal/Group/group-session-builder.js +124 -0
  37. package/lib/Signal/Group/group_cipher.js +216 -0
  38. package/lib/Signal/Group/index.js +124 -0
  39. package/lib/Signal/Group/keyhelper.js +108 -0
  40. package/lib/Signal/Group/sender-chain-key.js +83 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
  42. package/lib/Signal/Group/sender-key-message.js +166 -0
  43. package/lib/Signal/Group/sender-key-name.js +130 -0
  44. package/lib/Signal/Group/sender-key-record.js +113 -0
  45. package/lib/Signal/Group/sender-key-state.js +208 -0
  46. package/lib/Signal/Group/sender-message-key.js +82 -0
  47. package/lib/Signal/libsignal.js +935 -0
  48. package/lib/Signal/lid-mapping.js +545 -1
  49. package/lib/Socket/Client/index.js +60 -0
  50. package/lib/Socket/Client/types.js +51 -0
  51. package/lib/Socket/Client/websocket.js +152 -0
  52. package/lib/Socket/business.js +831 -0
  53. package/lib/Socket/chats.js +2535 -49
  54. package/lib/Socket/communities.js +450 -1
  55. package/lib/Socket/community.js +1022 -0
  56. package/lib/Socket/dugong.js +1 -1
  57. package/lib/Socket/groups.js +747 -0
  58. package/lib/Socket/index.js +60 -2
  59. package/lib/Socket/messages-recv.js +3450 -5
  60. package/lib/Socket/messages-send.js +3123 -0
  61. package/lib/Socket/mex.js +126 -1
  62. package/lib/Socket/newsletter.js +465 -0
  63. package/lib/Socket/socket.js +2217 -1
  64. package/lib/Store/index.js +79 -0
  65. package/lib/Store/make-cache-manager-store.js +186 -0
  66. package/lib/Store/make-in-memory-store.js +878 -0
  67. package/lib/Store/make-ordered-dictionary.js +187 -0
  68. package/lib/Store/object-repository.js +78 -0
  69. package/lib/Types/Auth.js +25 -0
  70. package/lib/Types/Bussines.js +25 -1
  71. package/lib/Types/Call.js +25 -0
  72. package/lib/Types/Chat.js +39 -0
  73. package/lib/Types/Contact.js +25 -0
  74. package/lib/Types/Events.js +25 -0
  75. package/lib/Types/GroupMetadata.js +25 -0
  76. package/lib/Types/Label.js +76 -0
  77. package/lib/Types/LabelAssociation.js +40 -0
  78. package/lib/Types/Message.js +57 -0
  79. package/lib/Types/Mex.js +56 -1
  80. package/lib/Types/MexUpdates.js +46 -0
  81. package/lib/Types/Newsletter.js +56 -0
  82. package/lib/Types/Product.js +25 -0
  83. package/lib/Types/RichType.js +23 -0
  84. package/lib/Types/Signal.js +25 -0
  85. package/lib/Types/Socket.js +25 -0
  86. package/lib/Types/State.js +92 -0
  87. package/lib/Types/USync.js +25 -0
  88. package/lib/Types/index.js +133 -0
  89. package/lib/Utils/auth-utils.js +703 -0
  90. package/lib/Utils/automation-tools.js +51 -16
  91. package/lib/Utils/baileys-event-stream.js +146 -0
  92. package/lib/Utils/browser-utils.js +95 -0
  93. package/lib/Utils/business.js +525 -0
  94. package/lib/Utils/chat-utils.js +1861 -0
  95. package/lib/Utils/companion-reg-client-utils.js +55 -1
  96. package/lib/Utils/crypto.js +355 -0
  97. package/lib/Utils/decode-wa-message.js +709 -0
  98. package/lib/Utils/event-buffer.js +1323 -8
  99. package/lib/Utils/generics.js +945 -1
  100. package/lib/Utils/history.js +266 -0
  101. package/lib/Utils/identity-change-handler.js +62 -1
  102. package/lib/Utils/index.js +114 -0
  103. package/lib/Utils/link-preview.js +179 -0
  104. package/lib/Utils/logger.js +42 -0
  105. package/lib/Utils/lt-hash.js +73 -0
  106. package/lib/Utils/make-mutex.js +104 -0
  107. package/lib/Utils/message-inspector.js +110 -0
  108. package/lib/Utils/message-retry-manager.js +507 -2
  109. package/lib/Utils/messages-media.js +1931 -1
  110. package/lib/Utils/messages.js +3748 -0
  111. package/lib/Utils/noise-handler.js +423 -0
  112. package/lib/Utils/offline-node-processor.js +53 -1
  113. package/lib/Utils/pre-key-manager.js +255 -1
  114. package/lib/Utils/process-message.js +1592 -0
  115. package/lib/Utils/reporting-utils.js +272 -1
  116. package/lib/Utils/rich-message-utils.js +377 -0
  117. package/lib/Utils/rich-messages.js +1 -1
  118. package/lib/Utils/signal.js +437 -0
  119. package/lib/Utils/stanza-ack.js +51 -1
  120. package/lib/Utils/status-refresh.js +37 -0
  121. package/lib/Utils/status-tools.js +4 -2
  122. package/lib/Utils/sync-action-utils.js +63 -1
  123. package/lib/Utils/tc-token-utils.js +185 -1
  124. package/lib/Utils/terminal-banner.js +31 -0
  125. package/lib/Utils/use-multi-file-auth-state.js +271 -0
  126. package/lib/Utils/use-single-file-auth-state.js +108 -0
  127. package/lib/Utils/use-sqlite-auth-state.js +142 -0
  128. package/lib/Utils/validate-connection.js +497 -1
  129. package/lib/Utils/view-once-compat.js +13 -5
  130. package/lib/VoIP/audio-feeder.js +150 -0
  131. package/lib/VoIP/index.js +289 -0
  132. package/lib/VoIP/relay-transport.js +608 -0
  133. package/lib/VoIP/signaling.js +583 -0
  134. package/lib/VoIP/types.js +30 -0
  135. package/lib/VoIP/wasm-engine.js +1261 -2
  136. package/lib/VoIP/worker-bootstrap.js +1090 -2
  137. package/lib/WABinary/constants.js +2805 -0
  138. package/lib/WABinary/decode.js +649 -2
  139. package/lib/WABinary/encode.js +564 -2
  140. package/lib/WABinary/generic-utils.js +401 -0
  141. package/lib/WABinary/index.js +82 -0
  142. package/lib/WABinary/jid-utils.js +290 -0
  143. package/lib/WABinary/types.js +25 -0
  144. package/lib/WAM/BinaryInfo.js +50 -0
  145. package/lib/WAM/constants.js +45747 -0
  146. package/lib/WAM/encode.js +393 -0
  147. package/lib/WAM/index.js +78 -0
  148. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
  149. package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
  150. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
  151. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
  152. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
  153. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
  154. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
  155. package/lib/WAUSync/Protocols/index.js +83 -0
  156. package/lib/WAUSync/USyncQuery.js +241 -2
  157. package/lib/WAUSync/USyncUser.js +86 -0
  158. package/lib/WAUSync/index.js +78 -0
  159. package/lib/assets/wasm/loader.js +1875 -1
  160. package/lib/assets/wasm/worker-modules.js +11047 -1
  161. package/lib/index.d.ts +126 -0
  162. package/lib/index.js +53 -21
  163. package/lib/index.mjs +437 -0
  164. package/licenses/upstream-MIT.txt +22 -0
  165. package/maintenance/api-coverage.json +1642 -0
  166. package/maintenance/archivos-sha256.json +207 -0
  167. package/maintenance/consumer-validation.log +3 -0
  168. package/maintenance/dependency-audit.json +4 -4
  169. package/maintenance/extension-inventory.json +57 -0
  170. package/maintenance/protocol-update.json +1101 -0
  171. package/maintenance/protocol-wire-audit.json +4 -0
  172. package/maintenance/reference-socket-surface.json +209 -0
  173. package/maintenance/resumen-validacion.json +50 -0
  174. package/maintenance/validation.log +2725 -0
  175. package/maintenance/verification.json +566 -0
  176. package/package.json +107 -9
  177. package/scripts/check-imports.cjs +10 -0
  178. package/scripts/check-package.cjs +40 -0
  179. package/scripts/check-syntax.cjs +1 -1
  180. package/scripts/generate-protobuf.cjs +6 -1
  181. package/scripts/generate-public-types.cjs +9 -0
  182. package/scripts/kage-base64-fix.cjs +45 -0
  183. package/scripts/maintenance.cjs +10 -0
  184. package/test/advanced.test.cjs +24 -0
  185. package/test/base64-fix.test.cjs +49 -0
  186. package/test/maintenance.test.cjs +1 -1
  187. package/test/npm-publication.test.cjs +141 -0
  188. package/test/recepcion-reparada.test.cjs +98 -0
  189. package/test/resilience-binary.test.cjs +69 -0
  190. package/test/resilience-transport.test.cjs +34 -0
  191. package/test/types.test.ts +5 -0
  192. package/test/upgrade.test.cjs +104 -0
  193. package/tsconfig.json +20 -0
  194. package/WAProto/p.html +0 -1
  195. package/lib/KageExtra/Modded/message_builder.js +0 -2330
  196. package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
  197. package/lib/KageExtra/VoIP/index.js +0 -282
  198. package/lib/KageExtra/VoIP/relay-transport.js +0 -559
  199. package/lib/KageExtra/VoIP/signaling.js +0 -603
  200. package/lib/KageExtra/VoIP/types.js +0 -17
  201. package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
  202. package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
  203. package/lib/KageExtra/assets/wasm/loader.js +0 -5
  204. package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
  205. package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
  206. package/lib/KageExtra/index.js +0 -3
  207. package/lib/KageExtra/package.json +0 -1
  208. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  209. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  210. package/maintenance/revision-full-check.txt +0 -1097
  211. package/maintenance/revision-library-tests.tap +0 -1088
  212. package/maintenance/revision-protobuf.txt +0 -5
  213. package/maintenance/revision-syntax.txt +0 -5
  214. package/maintenance/schema-coverage.json +0 -23
  215. package/maintenance/schema-merge.json +0 -30
  216. package/maintenance/validation-node20.txt +0 -191
  217. package/maintenance/validation-node22.txt +0 -237
@@ -0,0 +1,349 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const { default: NodeCache } = require("@cacheable/node-cache")
4
+ const { Boom } = require("@hapi/boom")
5
+ const { proto } = require("../../WAProto")
6
+ const {
7
+ CALL_VIDEO_PREFIX,
8
+ CALL_AUDIO_PREFIX
9
+ } = require("../Defaults/prefix")
10
+ const { DEFAULT_CACHE_TTLS } = require("../Defaults/constants")
11
+ const { PROCESSABLE_HISTORY_TYPES } = require("../Defaults/history")
12
+ const {
13
+ SyncState,
14
+ ALL_WA_PATCH_NAMES
15
+ } = require("../Types")
16
+ const {
17
+ newLTHashState,
18
+ processSyncAction,
19
+ extractSyncdPatches,
20
+ generateProfilePicture,
21
+ decodeSyncdSnapshot,
22
+ decodePatches,
23
+ encodeSyncdPatch,
24
+ chatModificationToAppPatch,
25
+ getHistoryMsg,
26
+ processMessage
27
+ } = require("../Utils")
28
+ const { makeMutex } = require("../Utils/make-mutex")
29
+ const {
30
+ isPnUser,
31
+ getBinaryNodeChild,
32
+ getBinaryNodeChildren,
33
+ jidDecode,
34
+ jidNormalizedUser,
35
+ reduceBinaryNodeToDictionary,
36
+ S_WHATSAPP_NET
37
+ } = require("../WABinary")
38
+ const {
39
+ USyncUser,
40
+ USyncQuery
41
+ } = require("../WAUSync")
42
+ const { makeSocket } = require("../Socket/socket")
43
+ const MAX_SYNC_ATTEMPTS = 2
44
+
45
+ exports.attach = function(base, config) {
46
+ const {
47
+ logger,
48
+ markOnlineOnConnect,
49
+ fireInitQueries,
50
+ appStateMacVerification,
51
+ shouldIgnoreJid,
52
+ shouldSyncHistoryMessage,
53
+ getMessage
54
+ } = config
55
+ const suki = base
56
+ const {
57
+ ev,
58
+ ws,
59
+ authState,
60
+ generateMessageTag,
61
+ sendNode,
62
+ query,
63
+ signalRepository,
64
+ onUnexpectedError
65
+ } = suki
66
+ const messageMutex = (base["messageMutex"] !== undefined ? base["messageMutex"] : (makeMutex()))
67
+ const receiptMutex = (base["receiptMutex"] !== undefined ? base["receiptMutex"] : (makeMutex()))
68
+ const appStatePatchMutex = (base["appStatePatchMutex"] !== undefined ? base["appStatePatchMutex"] : (makeMutex()))
69
+ const notificationMutex = (base["notificationMutex"] !== undefined ? base["notificationMutex"] : (makeMutex()))
70
+ const getAppStateSyncKey = (base["getAppStateSyncKey"] !== undefined ? base["getAppStateSyncKey"] : (async (keyId) => {
71
+ const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId])
72
+ return key
73
+ }))
74
+ const getLidUser = (base["getLidUser"] !== undefined ? base["getLidUser"] : (async (jid) => {
75
+ if (!jid) {
76
+ throw new Boom('Please input a jid user')
77
+ }
78
+
79
+ if (!isPnUser(jid)) {
80
+ throw new Boom('Invalid JID: Not a user JID!')
81
+ }
82
+
83
+ const targetJid = jidNormalizedUser(jid)
84
+
85
+ const usyncQuery = new USyncQuery()
86
+ usyncQuery.protocols.push({
87
+ name: 'lid',
88
+ getQueryElement: () => ({
89
+ tag: 'lid',
90
+ attrs: {},
91
+ content: undefined
92
+ }),
93
+ getUserElement: () => null,
94
+ parser: (node) => node.attrs.val
95
+ })
96
+ usyncQuery.users.push({
97
+ id: targetJid
98
+ })
99
+
100
+ const result = await suki.executeUSyncQuery(usyncQuery)
101
+
102
+ if (result) {
103
+ return result.list
104
+ }
105
+ }))
106
+ const newAppStateChunkHandler = (base["newAppStateChunkHandler"] !== undefined ? base["newAppStateChunkHandler"] : ((isInitialSync) => {
107
+ return {
108
+ onMutation(mutation) {
109
+ processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger)
110
+ }
111
+ }
112
+ }))
113
+ const resyncAppState = (base["resyncAppState"] !== undefined ? base["resyncAppState"] : (ev.createBufferedFunction(async (collections, isInitialSync) => {
114
+ // we use this to determine which events to fire
115
+ // otherwise when we resync from scratch -- all notifications will fire
116
+ const initialVersionMap = {}
117
+ const globalMutationMap = {}
118
+
119
+ await authState.keys.transaction(async () => {
120
+ const collectionsToHandle = new Set(collections)
121
+
122
+ // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
123
+ const attemptsMap = {}
124
+
125
+ // keep executing till all collections are done
126
+ // sometimes a single patch request will not return all the patches (God knows why)
127
+ // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
128
+ while (collectionsToHandle.size) {
129
+ const states = {}
130
+ const nodes = []
131
+
132
+ for (const name of collectionsToHandle) {
133
+ const result = await authState.keys.get('app-state-sync-version', [name])
134
+
135
+ let state = result[name]
136
+
137
+ if (state) {
138
+ if (typeof initialVersionMap[name] === 'undefined') {
139
+ initialVersionMap[name] = state.version
140
+ }
141
+ }
142
+
143
+ else {
144
+ state = newLTHashState()
145
+ }
146
+
147
+ states[name] = state
148
+ logger.info(`resyncing ${name} from v${state.version}`)
149
+ nodes.push({
150
+ tag: 'collection',
151
+ attrs: {
152
+ name,
153
+ version: state.version.toString(),
154
+ // return snapshot if being synced from scratch
155
+ return_snapshot: (!state.version).toString()
156
+ }
157
+ })
158
+ }
159
+
160
+ const result = await query({
161
+ tag: 'iq',
162
+ attrs: {
163
+ to: S_WHATSAPP_NET,
164
+ xmlns: 'w:sync:app:state',
165
+ type: 'set'
166
+ },
167
+ content: [
168
+ {
169
+ tag: 'sync',
170
+ attrs: {},
171
+ content: nodes
172
+ }
173
+ ]
174
+ })
175
+
176
+ // extract from binary node
177
+ const decoded = await extractSyncdPatches(result, config?.options)
178
+
179
+ for (const key in decoded) {
180
+ const name = key
181
+ const { patches, hasMorePatches, snapshot } = decoded[name]
182
+
183
+ try {
184
+ if (snapshot) {
185
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
186
+
187
+ states[name] = newState
188
+
189
+ Object.assign(globalMutationMap, mutationMap)
190
+
191
+ logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`)
192
+
193
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
194
+ }
195
+
196
+ // only process if there are syncd patches
197
+ if (patches.length) {
198
+ const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch)
199
+
200
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
201
+
202
+ logger.info(`synced ${name} to v${newState.version}`)
203
+
204
+ initialVersionMap[name] = newState.version
205
+
206
+ Object.assign(globalMutationMap, mutationMap)
207
+ }
208
+
209
+ if (hasMorePatches) {
210
+ logger.info(`${name} has more patches...`)
211
+ }
212
+
213
+ else {
214
+ // collection is done with sync
215
+ collectionsToHandle.delete(name)
216
+ }
217
+ }
218
+
219
+ catch (error) {
220
+ // if retry attempts overshoot
221
+ // or key not found
222
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
223
+ error.output?.statusCode === 404 ||
224
+ error.name === 'TypeError'
225
+
226
+ logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`)
227
+
228
+ await authState.keys.set({ 'app-state-sync-version': { [name]: null } })
229
+
230
+ // increment number of retries
231
+ attemptsMap[name] = (attemptsMap[name] || 0) + 1
232
+
233
+ if (isIrrecoverableError) {
234
+ // stop retrying
235
+ collectionsToHandle.delete(name);
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }, authState?.creds?.me?.id || 'resync-app-state')
241
+ const { onMutation } = newAppStateChunkHandler(isInitialSync)
242
+
243
+ for (const key in globalMutationMap) {
244
+ onMutation(globalMutationMap[key])
245
+ }
246
+ })))
247
+ const appPatch = (base["appPatch"] !== undefined ? base["appPatch"] : (async (patchCreate) => {
248
+ const name = patchCreate.type
249
+ const myAppStateKeyId = authState.creds.myAppStateKeyId
250
+
251
+ if (!myAppStateKeyId) {
252
+ throw new Boom('App state key not present!', { statusCode: 400 })
253
+ }
254
+
255
+ let initial
256
+ let encodeResult
257
+
258
+ await appStatePatchMutex.mutex(async () => {
259
+ await authState.keys.transaction(async () => {
260
+ logger.debug({ patch: patchCreate }, 'applying app patch')
261
+
262
+ await resyncAppState([name], false)
263
+
264
+ const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name])
265
+
266
+ initial = currentSyncVersion || newLTHashState()
267
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey)
268
+
269
+ const { patch, state } = encodeResult
270
+ const node = {
271
+ tag: 'iq',
272
+ attrs: {
273
+ to: S_WHATSAPP_NET,
274
+ type: 'set',
275
+ xmlns: 'w:sync:app:state'
276
+ },
277
+ content: [
278
+ {
279
+ tag: 'sync',
280
+ attrs: {},
281
+ content: [
282
+ {
283
+ tag: 'collection',
284
+ attrs: {
285
+ name,
286
+ version: (state.version - 1).toString(),
287
+ return_snapshot: 'false'
288
+ },
289
+ content: [
290
+ {
291
+ tag: 'patch',
292
+ attrs: {},
293
+ content: proto.SyncdPatch.encode(patch).finish()
294
+ }
295
+ ]
296
+ }
297
+ ]
298
+ }
299
+ ]
300
+ }
301
+
302
+ await query(node)
303
+ await authState.keys.set({ 'app-state-sync-version': { [name]: state } })
304
+ }, authState?.creds?.me?.id || 'app-patch')
305
+ })
306
+
307
+ if (config.emitOwnEvents) {
308
+ const { onMutation } = newAppStateChunkHandler(false)
309
+ const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger)
310
+
311
+ for (const key in mutationMap) {
312
+ onMutation(mutationMap[key])
313
+ }
314
+ }
315
+ }))
316
+ const chatModify = ((mod, jid) => {
317
+ const patch = chatModificationToAppPatch(mod, jid)
318
+ return appPatch(patch)
319
+ })
320
+ const clearMessage = (base["clearMessage"] !== undefined ? base["clearMessage"] : ((jid, key, timeStamp) => {
321
+ return chatModify({
322
+ delete: true,
323
+ lastMessages: [{
324
+ key: key,
325
+ messageTimestamp: timeStamp
326
+ }],
327
+ }, jid)
328
+ }))
329
+ const addOrEditQuickReply = (base["addOrEditQuickReply"] !== undefined ? base["addOrEditQuickReply"] : ((quickReply) => {
330
+ return chatModify({
331
+ quickReply
332
+ }, '')
333
+ }))
334
+ const removeQuickReply = (base["removeQuickReply"] !== undefined ? base["removeQuickReply"] : ((timestamp) => {
335
+ return chatModify({
336
+ quickReply: { timestamp, deleted: true }
337
+ }, '')
338
+ }))
339
+ return {
340
+ messageMutex,
341
+ receiptMutex,
342
+ appStatePatchMutex,
343
+ notificationMutex,
344
+ getLidUser,
345
+ clearMessage,
346
+ addOrEditQuickReply,
347
+ removeQuickReply
348
+ };
349
+ };