@ubedsockets/baileys 1.6.9 → 1.7.0

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 (399) hide show
  1. package/WAProto/GenerateStatics.sh +26 -3
  2. package/WAProto/WAProto.proto +432 -180
  3. package/WAProto/add-missing-proto-deps.js +134 -0
  4. package/WAProto/imports-elaina.js +48 -0
  5. package/WAProto/index.js +78044 -140686
  6. package/WAProto/merge-elaina-ai-proto.js +187 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/elaina-version.json +3 -0
  9. package/lib/Defaults/index.js +57 -55
  10. package/lib/Signal/Group/group_cipher.js +1 -1
  11. package/lib/Signal/Group/keyhelper.js +1 -1
  12. package/lib/Signal/Group/sender-chain-key.js +1 -1
  13. package/lib/Signal/Group/sender-key-message.js +1 -1
  14. package/lib/Signal/Group/sender-message-key.js +1 -1
  15. package/lib/Signal/libsignal.js +1 -1
  16. package/lib/Signal/libsignalnode/LICENSE +621 -0
  17. package/lib/Signal/libsignalnode/README.md +11 -0
  18. package/lib/Signal/libsignalnode/generate-proto.sh +1 -0
  19. package/lib/Signal/libsignalnode/index.js +10 -0
  20. package/lib/Signal/libsignalnode/protos/WhisperTextProtocol.proto +28 -0
  21. package/lib/Signal/libsignalnode/src/.eslintrc.json +31 -0
  22. package/lib/Signal/libsignalnode/src/WhisperTextProtocol.js +948 -0
  23. package/lib/Signal/libsignalnode/src/base_key_type.js +6 -0
  24. package/lib/Signal/libsignalnode/src/chain_type.js +6 -0
  25. package/lib/Signal/libsignalnode/src/crypto.js +98 -0
  26. package/lib/Signal/libsignalnode/src/curve.js +142 -0
  27. package/lib/Signal/libsignalnode/src/errors.js +33 -0
  28. package/lib/Signal/libsignalnode/src/keyhelper.js +45 -0
  29. package/lib/Signal/libsignalnode/src/numeric_fingerprint.js +70 -0
  30. package/lib/Signal/libsignalnode/src/protobufs.js +10 -0
  31. package/lib/Signal/libsignalnode/src/protocol_address.js +40 -0
  32. package/lib/Signal/libsignalnode/src/queue_job.js +70 -0
  33. package/lib/Signal/libsignalnode/src/session_builder.js +164 -0
  34. package/lib/Signal/libsignalnode/src/session_cipher.js +332 -0
  35. package/lib/Signal/libsignalnode/src/session_record.js +325 -0
  36. package/lib/Socket/Client/websocket.js +2 -41
  37. package/lib/Socket/Rhandler.js +533 -0
  38. package/lib/Socket/chats.js +249 -123
  39. package/lib/Socket/index.js +1 -1
  40. package/lib/Socket/messages-recv.js +57 -5
  41. package/lib/Socket/messages-send.js +47 -280
  42. package/lib/Socket/newsletter.js +100 -132
  43. package/lib/Socket/socket.js +79 -87
  44. package/lib/Socket/usync.js +0 -2
  45. package/lib/Store/make-in-memory-store.js +1 -1
  46. package/lib/Utils/browser-utils.js +30 -23
  47. package/lib/Utils/crypto.js +22 -18
  48. package/lib/Utils/decode-wa-message.js +12 -2
  49. package/lib/Utils/{baileys-event-stream.js → elaina-event-stream.js} +1 -1
  50. package/lib/Utils/event-buffer.js +2 -2
  51. package/lib/Utils/generics.js +36 -10
  52. package/lib/Utils/index.js +3 -1
  53. package/lib/Utils/message-retry-manager.js +48 -185
  54. package/lib/Utils/messages-media.js +127 -236
  55. package/lib/Utils/messages.js +746 -232
  56. package/lib/Utils/noise-handler.js +1 -2
  57. package/lib/Utils/process-message.js +108 -25
  58. package/lib/Utils/signal.js +1 -10
  59. package/lib/Utils/use-multi-file-auth-state.js +1 -1
  60. package/lib/Utils/validate-connection.js +3 -7
  61. package/lib/Voip/audio-feeder.js +166 -0
  62. package/lib/Voip/index.js +639 -0
  63. package/lib/Voip/relay-transport.js +829 -0
  64. package/lib/Voip/signaling.js +1102 -0
  65. package/lib/Voip/types.js +23 -0
  66. package/lib/Voip/wasm-engine.js +1255 -0
  67. package/lib/Voip/worker-bootstrap.js +1078 -0
  68. package/lib/WABinary/jid-utils.js +17 -1
  69. package/lib/assets/wasm/loader.js +5 -0
  70. package/lib/assets/wasm/whatsapp.wasm +0 -0
  71. package/lib/assets/wasm/worker-modules.js +273 -0
  72. package/lib/index.js +21 -18
  73. package/package.json +32 -18
  74. package/WAProto/AICommon.js +0 -27981
  75. package/WAProto/AICommon.proto +0 -713
  76. package/WAProto/Ephemeral.js +0 -295
  77. package/WAProto/Ephemeral.proto +0 -7
  78. package/WAProto/fix-imports.js +0 -85
  79. package/WAProto/index.d.ts +0 -14017
  80. package/WAProto/vyzen.js +0 -7
  81. package/lib/Defaults/baileys-version.json +0 -3
  82. package/lib/Defaults/index.d.ts +0 -75
  83. package/lib/Defaults/index.d.ts.map +0 -1
  84. package/lib/Defaults/index.js.map +0 -1
  85. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  86. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  87. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  88. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  89. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  90. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  91. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  92. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  93. package/lib/Signal/Group/group_cipher.js.map +0 -1
  94. package/lib/Signal/Group/index.d.ts +0 -12
  95. package/lib/Signal/Group/index.d.ts.map +0 -1
  96. package/lib/Signal/Group/index.js.map +0 -1
  97. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  98. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  99. package/lib/Signal/Group/keyhelper.js.map +0 -1
  100. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  101. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  102. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  103. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  104. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  105. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  106. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  107. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  108. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  109. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  110. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  111. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  112. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  113. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  114. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  115. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  116. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  117. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  118. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  119. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  120. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  121. package/lib/Signal/libsignal.d.ts +0 -5
  122. package/lib/Signal/libsignal.d.ts.map +0 -1
  123. package/lib/Signal/libsignal.js.map +0 -1
  124. package/lib/Signal/lid-mapping.d.ts +0 -23
  125. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  126. package/lib/Signal/lid-mapping.js +0 -277
  127. package/lib/Signal/lid-mapping.js.map +0 -1
  128. package/lib/Socket/Client/index.d.ts +0 -3
  129. package/lib/Socket/Client/index.d.ts.map +0 -1
  130. package/lib/Socket/Client/index.js.map +0 -1
  131. package/lib/Socket/Client/types.d.ts +0 -16
  132. package/lib/Socket/Client/types.d.ts.map +0 -1
  133. package/lib/Socket/Client/types.js.map +0 -1
  134. package/lib/Socket/Client/websocket.d.ts +0 -13
  135. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  136. package/lib/Socket/Client/websocket.js.map +0 -1
  137. package/lib/Socket/business.d.ts +0 -217
  138. package/lib/Socket/business.d.ts.map +0 -1
  139. package/lib/Socket/business.js.map +0 -1
  140. package/lib/Socket/chats.d.ts +0 -124
  141. package/lib/Socket/chats.d.ts.map +0 -1
  142. package/lib/Socket/chats.js.map +0 -1
  143. package/lib/Socket/communities.d.ts +0 -273
  144. package/lib/Socket/communities.d.ts.map +0 -1
  145. package/lib/Socket/communities.js +0 -431
  146. package/lib/Socket/communities.js.map +0 -1
  147. package/lib/Socket/groups.d.ts +0 -161
  148. package/lib/Socket/groups.d.ts.map +0 -1
  149. package/lib/Socket/groups.js.map +0 -1
  150. package/lib/Socket/index.d.ts +0 -260
  151. package/lib/Socket/index.d.ts.map +0 -1
  152. package/lib/Socket/index.js.map +0 -1
  153. package/lib/Socket/messages-recv.d.ts +0 -203
  154. package/lib/Socket/messages-recv.d.ts.map +0 -1
  155. package/lib/Socket/messages-recv.js.map +0 -1
  156. package/lib/Socket/messages-send.d.ts +0 -199
  157. package/lib/Socket/messages-send.d.ts.map +0 -1
  158. package/lib/Socket/messages-send.js.map +0 -1
  159. package/lib/Socket/mex.d.ts +0 -3
  160. package/lib/Socket/mex.d.ts.map +0 -1
  161. package/lib/Socket/mex.js +0 -42
  162. package/lib/Socket/mex.js.map +0 -1
  163. package/lib/Socket/newsletter.d.ts +0 -170
  164. package/lib/Socket/newsletter.d.ts.map +0 -1
  165. package/lib/Socket/newsletter.js.map +0 -1
  166. package/lib/Socket/setup.js +0 -433
  167. package/lib/Socket/socket.d.ts +0 -59
  168. package/lib/Socket/socket.d.ts.map +0 -1
  169. package/lib/Socket/socket.js.map +0 -1
  170. package/lib/Types/Auth.d.ts +0 -117
  171. package/lib/Types/Auth.d.ts.map +0 -1
  172. package/lib/Types/Auth.js.map +0 -1
  173. package/lib/Types/Bussines.d.ts +0 -25
  174. package/lib/Types/Bussines.d.ts.map +0 -1
  175. package/lib/Types/Bussines.js +0 -2
  176. package/lib/Types/Bussines.js.map +0 -1
  177. package/lib/Types/Call.d.ts +0 -15
  178. package/lib/Types/Call.d.ts.map +0 -1
  179. package/lib/Types/Call.js.map +0 -1
  180. package/lib/Types/Chat.d.ts +0 -124
  181. package/lib/Types/Chat.d.ts.map +0 -1
  182. package/lib/Types/Chat.js.map +0 -1
  183. package/lib/Types/Contact.d.ts +0 -26
  184. package/lib/Types/Contact.d.ts.map +0 -1
  185. package/lib/Types/Contact.js.map +0 -1
  186. package/lib/Types/Events.d.ts +0 -256
  187. package/lib/Types/Events.d.ts.map +0 -1
  188. package/lib/Types/Events.js.map +0 -1
  189. package/lib/Types/GroupMetadata.d.ts +0 -71
  190. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  191. package/lib/Types/GroupMetadata.js.map +0 -1
  192. package/lib/Types/Label.d.ts +0 -47
  193. package/lib/Types/Label.d.ts.map +0 -1
  194. package/lib/Types/Label.js.map +0 -1
  195. package/lib/Types/LabelAssociation.d.ts +0 -30
  196. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  197. package/lib/Types/LabelAssociation.js.map +0 -1
  198. package/lib/Types/Message.d.ts +0 -320
  199. package/lib/Types/Message.d.ts.map +0 -1
  200. package/lib/Types/Message.js.map +0 -1
  201. package/lib/Types/Mex.d.ts +0 -141
  202. package/lib/Types/Mex.d.ts.map +0 -1
  203. package/lib/Types/Mex.js +0 -37
  204. package/lib/Types/Mex.js.map +0 -1
  205. package/lib/Types/Product.d.ts +0 -79
  206. package/lib/Types/Product.d.ts.map +0 -1
  207. package/lib/Types/Product.js.map +0 -1
  208. package/lib/Types/RichType.d.ts +0 -3
  209. package/lib/Types/RichType.d.ts.map +0 -1
  210. package/lib/Types/RichType.js +0 -31
  211. package/lib/Types/Signal.d.ts +0 -87
  212. package/lib/Types/Signal.d.ts.map +0 -1
  213. package/lib/Types/Signal.js.map +0 -1
  214. package/lib/Types/Socket.d.ts +0 -136
  215. package/lib/Types/Socket.d.ts.map +0 -1
  216. package/lib/Types/Socket.js.map +0 -1
  217. package/lib/Types/State.d.ts +0 -97
  218. package/lib/Types/State.d.ts.map +0 -1
  219. package/lib/Types/State.js.map +0 -1
  220. package/lib/Types/USync.d.ts +0 -26
  221. package/lib/Types/USync.d.ts.map +0 -1
  222. package/lib/Types/USync.js.map +0 -1
  223. package/lib/Types/index.d.ts +0 -65
  224. package/lib/Types/index.d.ts.map +0 -1
  225. package/lib/Types/index.js.map +0 -1
  226. package/lib/Utils/Tiktok.js +0 -80
  227. package/lib/Utils/auth-utils.d.ts +0 -24
  228. package/lib/Utils/auth-utils.d.ts.map +0 -1
  229. package/lib/Utils/auth-utils.js.map +0 -1
  230. package/lib/Utils/browser-utils.d.ts +0 -4
  231. package/lib/Utils/browser-utils.d.ts.map +0 -1
  232. package/lib/Utils/browser-utils.js.map +0 -1
  233. package/lib/Utils/business.d.ts +0 -23
  234. package/lib/Utils/business.d.ts.map +0 -1
  235. package/lib/Utils/business.js.map +0 -1
  236. package/lib/Utils/chaanel/vyzen.js +0 -0
  237. package/lib/Utils/chat-utils.d.ts +0 -100
  238. package/lib/Utils/chat-utils.d.ts.map +0 -1
  239. package/lib/Utils/chat-utils.js.map +0 -1
  240. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  241. package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
  242. package/lib/Utils/companion-reg-client-utils.js +0 -35
  243. package/lib/Utils/companion-reg-client-utils.js.map +0 -1
  244. package/lib/Utils/crypto.d.ts +0 -37
  245. package/lib/Utils/crypto.d.ts.map +0 -1
  246. package/lib/Utils/crypto.js.map +0 -1
  247. package/lib/Utils/decode-wa-message.d.ts +0 -66
  248. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  249. package/lib/Utils/decode-wa-message.js.map +0 -1
  250. package/lib/Utils/event-buffer.d.ts +0 -36
  251. package/lib/Utils/event-buffer.d.ts.map +0 -1
  252. package/lib/Utils/event-buffer.js.map +0 -1
  253. package/lib/Utils/facebook.js +0 -48
  254. package/lib/Utils/generics.d.ts +0 -91
  255. package/lib/Utils/generics.d.ts.map +0 -1
  256. package/lib/Utils/generics.js.map +0 -1
  257. package/lib/Utils/history.d.ts +0 -24
  258. package/lib/Utils/history.d.ts.map +0 -1
  259. package/lib/Utils/history.js.map +0 -1
  260. package/lib/Utils/identity-change-handler.d.ts +0 -44
  261. package/lib/Utils/identity-change-handler.d.ts.map +0 -1
  262. package/lib/Utils/identity-change-handler.js +0 -50
  263. package/lib/Utils/identity-change-handler.js.map +0 -1
  264. package/lib/Utils/index.d.ts +0 -22
  265. package/lib/Utils/index.d.ts.map +0 -1
  266. package/lib/Utils/index.js.map +0 -1
  267. package/lib/Utils/instagram.js +0 -50
  268. package/lib/Utils/link-preview.d.ts +0 -21
  269. package/lib/Utils/link-preview.d.ts.map +0 -1
  270. package/lib/Utils/link-preview.js.map +0 -1
  271. package/lib/Utils/logger.d.ts +0 -12
  272. package/lib/Utils/logger.d.ts.map +0 -1
  273. package/lib/Utils/logger.js.map +0 -1
  274. package/lib/Utils/lt-hash.d.ts +0 -8
  275. package/lib/Utils/lt-hash.d.ts.map +0 -1
  276. package/lib/Utils/lt-hash.js.map +0 -1
  277. package/lib/Utils/make-mutex.d.ts +0 -9
  278. package/lib/Utils/make-mutex.d.ts.map +0 -1
  279. package/lib/Utils/make-mutex.js.map +0 -1
  280. package/lib/Utils/message-retry-manager.d.ts +0 -115
  281. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  282. package/lib/Utils/message-retry-manager.js.map +0 -1
  283. package/lib/Utils/messages-media.d.ts +0 -133
  284. package/lib/Utils/messages-media.d.ts.map +0 -1
  285. package/lib/Utils/messages-media.js.map +0 -1
  286. package/lib/Utils/messages.d.ts +0 -91
  287. package/lib/Utils/messages.d.ts.map +0 -1
  288. package/lib/Utils/messages.js.map +0 -1
  289. package/lib/Utils/noise-handler.d.ts +0 -20
  290. package/lib/Utils/noise-handler.d.ts.map +0 -1
  291. package/lib/Utils/noise-handler.js.map +0 -1
  292. package/lib/Utils/offline-node-processor.d.ts +0 -17
  293. package/lib/Utils/offline-node-processor.d.ts.map +0 -1
  294. package/lib/Utils/offline-node-processor.js +0 -40
  295. package/lib/Utils/offline-node-processor.js.map +0 -1
  296. package/lib/Utils/pre-key-manager.d.ts +0 -28
  297. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  298. package/lib/Utils/pre-key-manager.js +0 -106
  299. package/lib/Utils/pre-key-manager.js.map +0 -1
  300. package/lib/Utils/process-message.d.ts +0 -60
  301. package/lib/Utils/process-message.d.ts.map +0 -1
  302. package/lib/Utils/process-message.js.map +0 -1
  303. package/lib/Utils/reporting-utils.d.ts +0 -11
  304. package/lib/Utils/reporting-utils.d.ts.map +0 -1
  305. package/lib/Utils/reporting-utils.js +0 -258
  306. package/lib/Utils/reporting-utils.js.map +0 -1
  307. package/lib/Utils/rich-message-utils.js +0 -387
  308. package/lib/Utils/signal.d.ts +0 -47
  309. package/lib/Utils/signal.d.ts.map +0 -1
  310. package/lib/Utils/signal.js.map +0 -1
  311. package/lib/Utils/stanza-ack.d.ts +0 -11
  312. package/lib/Utils/stanza-ack.d.ts.map +0 -1
  313. package/lib/Utils/stanza-ack.js +0 -38
  314. package/lib/Utils/stanza-ack.js.map +0 -1
  315. package/lib/Utils/sync-action-utils.d.ts +0 -19
  316. package/lib/Utils/sync-action-utils.d.ts.map +0 -1
  317. package/lib/Utils/sync-action-utils.js +0 -49
  318. package/lib/Utils/sync-action-utils.js.map +0 -1
  319. package/lib/Utils/tc-token-utils.d.ts +0 -37
  320. package/lib/Utils/tc-token-utils.d.ts.map +0 -1
  321. package/lib/Utils/tc-token-utils.js +0 -163
  322. package/lib/Utils/tc-token-utils.js.map +0 -1
  323. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  324. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  325. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  326. package/lib/Utils/validate-connection.d.ts +0 -11
  327. package/lib/Utils/validate-connection.d.ts.map +0 -1
  328. package/lib/Utils/validate-connection.js.map +0 -1
  329. package/lib/Utils/youtube.js +0 -44
  330. package/lib/WABinary/constants.d.ts +0 -28
  331. package/lib/WABinary/constants.d.ts.map +0 -1
  332. package/lib/WABinary/constants.js.map +0 -1
  333. package/lib/WABinary/decode.d.ts +0 -7
  334. package/lib/WABinary/decode.d.ts.map +0 -1
  335. package/lib/WABinary/decode.js.map +0 -1
  336. package/lib/WABinary/encode.d.ts +0 -3
  337. package/lib/WABinary/encode.d.ts.map +0 -1
  338. package/lib/WABinary/encode.js.map +0 -1
  339. package/lib/WABinary/generic-utils.d.ts +0 -15
  340. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  341. package/lib/WABinary/generic-utils.js.map +0 -1
  342. package/lib/WABinary/index.d.ts +0 -6
  343. package/lib/WABinary/index.d.ts.map +0 -1
  344. package/lib/WABinary/index.js.map +0 -1
  345. package/lib/WABinary/jid-utils.d.ts +0 -48
  346. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  347. package/lib/WABinary/jid-utils.js.map +0 -1
  348. package/lib/WABinary/types.d.ts +0 -19
  349. package/lib/WABinary/types.d.ts.map +0 -1
  350. package/lib/WABinary/types.js.map +0 -1
  351. package/lib/WAM/BinaryInfo.d.ts +0 -9
  352. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  353. package/lib/WAM/BinaryInfo.js.map +0 -1
  354. package/lib/WAM/constants.d.ts +0 -40
  355. package/lib/WAM/constants.d.ts.map +0 -1
  356. package/lib/WAM/constants.js.map +0 -1
  357. package/lib/WAM/encode.d.ts +0 -3
  358. package/lib/WAM/encode.d.ts.map +0 -1
  359. package/lib/WAM/encode.js.map +0 -1
  360. package/lib/WAM/index.d.ts +0 -4
  361. package/lib/WAM/index.d.ts.map +0 -1
  362. package/lib/WAM/index.js.map +0 -1
  363. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  364. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  365. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  366. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  367. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  368. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  369. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  370. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  371. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  372. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  373. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  374. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  375. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  376. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
  377. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
  378. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
  379. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  380. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  381. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  382. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  383. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  384. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  385. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  386. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  387. package/lib/WAUSync/Protocols/index.js.map +0 -1
  388. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  389. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  390. package/lib/WAUSync/USyncQuery.js.map +0 -1
  391. package/lib/WAUSync/USyncUser.d.ts +0 -17
  392. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  393. package/lib/WAUSync/USyncUser.js.map +0 -1
  394. package/lib/WAUSync/index.d.ts +0 -4
  395. package/lib/WAUSync/index.d.ts.map +0 -1
  396. package/lib/WAUSync/index.js.map +0 -1
  397. package/lib/index.d.ts +0 -12
  398. package/lib/index.d.ts.map +0 -1
  399. package/lib/index.js.map +0 -1
@@ -15,24 +15,35 @@ const process_message_1 = __importDefault(require("../Utils/process-message"));
15
15
  const WABinary_1 = require("../WABinary");
16
16
  const WAUSync_1 = require("../WAUSync");
17
17
  const usync_1 = require("./usync");
18
+ const chalk = require('chalk');
18
19
  const MAX_SYNC_ATTEMPTS = 2;
20
+ const SyncState = {
21
+ Connecting: 'connecting',
22
+ AwaitingInitialSync: 'awaiting_initial_sync',
23
+ Syncing: 'syncing',
24
+ Online: 'online'
25
+ };
19
26
  const makeChatsSocket = (config) => {
20
27
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
21
28
  const sock = (0, usync_1.makeUSyncSocket)(config);
22
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
29
+ const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
23
30
  let privacySettings;
31
+ let syncState = SyncState.Connecting;
24
32
  let needToFlushWithAppStateSync = false;
25
33
  let pendingAppStateSync = false;
26
- /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
34
+ let awaitingSyncTimeout;
27
35
  const processingMutex = (0, make_mutex_1.makeMutex)();
28
36
  const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
37
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
38
+ useClones: false
39
+ });
40
+ const receivedMessageDedupCache = new node_cache_1.default({
41
+ stdTTL: 3 * 60,
30
42
  useClones: false
31
43
  });
32
44
  if (!config.placeholderResendCache) {
33
45
  config.placeholderResendCache = placeholderResendCache;
34
46
  }
35
- /** helper function to fetch the given app state sync key */
36
47
  const getAppStateSyncKey = async (keyId) => {
37
48
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
38
49
  return key;
@@ -54,7 +65,6 @@ const makeChatsSocket = (config) => {
54
65
  }
55
66
  return privacySettings;
56
67
  };
57
- /** helper function to run a privacy IQ query */
58
68
  const privacyQuery = async (name, value) => {
59
69
  await query({
60
70
  tag: 'iq',
@@ -99,6 +109,9 @@ const makeChatsSocket = (config) => {
99
109
  const updateGroupsAddPrivacy = async (value) => {
100
110
  await privacyQuery('groupadd', value);
101
111
  };
112
+ const updateDisableLinkPreviewsPrivacy = async (isPreviewsDisabled) => {
113
+ return chatModify({ disableLinkPreviews: { isPreviewsDisabled } }, '');
114
+ };
102
115
  const updateDefaultDisappearingMode = async (duration) => {
103
116
  await query({
104
117
  tag: 'iq',
@@ -179,16 +192,15 @@ const makeChatsSocket = (config) => {
179
192
  return result.list;
180
193
  }
181
194
  };
182
- /** update the profile picture for yourself or a group */
183
- const updateProfilePicture = async (jid, content) => {
195
+ const updateProfilePicture = async (jid, content, dimensions) => {
184
196
  let targetJid;
185
197
  if (!jid) {
186
198
  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');
187
199
  }
188
200
  if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
189
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
201
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
190
202
  }
191
- const { img } = await (0, Utils_1.generateProfilePicture)(content);
203
+ const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
192
204
  await query({
193
205
  tag: 'iq',
194
206
  attrs: {
@@ -206,14 +218,13 @@ const makeChatsSocket = (config) => {
206
218
  ]
207
219
  });
208
220
  };
209
- /** remove the profile picture for yourself or a group */
210
221
  const removeProfilePicture = async (jid) => {
211
222
  let targetJid;
212
223
  if (!jid) {
213
224
  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');
214
225
  }
215
226
  if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
216
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
227
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
217
228
  }
218
229
  await query({
219
230
  tag: 'iq',
@@ -225,7 +236,6 @@ const makeChatsSocket = (config) => {
225
236
  }
226
237
  });
227
238
  };
228
- /** update the profile status for yourself */
229
239
  const updateProfileStatus = async (status) => {
230
240
  await query({
231
241
  tag: 'iq',
@@ -352,18 +362,12 @@ const makeChatsSocket = (config) => {
352
362
  };
353
363
  };
354
364
  const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
355
- // we use this to determine which events to fire
356
- // otherwise when we resync from scratch -- all notifications will fire
357
365
  const initialVersionMap = {};
358
366
  const globalMutationMap = {};
359
367
  await authState.keys.transaction(async () => {
360
368
  var _a;
361
369
  const collectionsToHandle = new Set(collections);
362
- // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
363
370
  const attemptsMap = {};
364
- // keep executing till all collections are done
365
- // sometimes a single patch request will not return all the patches (God knows why)
366
- // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
367
371
  while (collectionsToHandle.size) {
368
372
  const states = {};
369
373
  const nodes = [];
@@ -385,7 +389,6 @@ const makeChatsSocket = (config) => {
385
389
  attrs: {
386
390
  name,
387
391
  version: state.version.toString(),
388
- // return snapshot if being synced from scratch
389
392
  'return_snapshot': (!state.version).toString()
390
393
  }
391
394
  });
@@ -405,7 +408,6 @@ const makeChatsSocket = (config) => {
405
408
  }
406
409
  ]
407
410
  });
408
- // extract from binary node
409
411
  const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
410
412
  for (const key in decoded) {
411
413
  const name = key;
@@ -418,7 +420,6 @@ const makeChatsSocket = (config) => {
418
420
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
419
421
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
420
422
  }
421
- // only process if there are syncd patches
422
423
  if (patches.length) {
423
424
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
424
425
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
@@ -429,22 +430,18 @@ const makeChatsSocket = (config) => {
429
430
  if (hasMorePatches) {
430
431
  logger.info(`${name} has more patches...`);
431
432
  }
432
- else { // collection is done with sync
433
+ else {
433
434
  collectionsToHandle.delete(name);
434
435
  }
435
436
  }
436
437
  catch (error) {
437
- // if retry attempts overshoot
438
- // or key not found
439
438
  const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
440
439
  || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
441
440
  || error.name === 'TypeError';
442
441
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
443
442
  await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
444
- // increment number of retries
445
443
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
446
444
  if (isIrrecoverableError) {
447
- // stop retrying
448
445
  collectionsToHandle.delete(name);
449
446
  }
450
447
  }
@@ -456,28 +453,56 @@ const makeChatsSocket = (config) => {
456
453
  onMutation(globalMutationMap[key]);
457
454
  }
458
455
  });
459
- /**
460
- * fetch the profile picture of a user/group
461
- * type = "preview" for a low res picture
462
- * type = "image for the high res picture"
463
- */
464
456
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
465
457
  var _a;
466
458
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
459
+ try {
460
+ const result = await query({
461
+ tag: 'iq',
462
+ attrs: {
463
+ target: jid,
464
+ to: WABinary_1.S_WHATSAPP_NET,
465
+ type: 'get',
466
+ xmlns: 'w:profile:picture'
467
+ },
468
+ content: [
469
+ { tag: 'picture', attrs: { type, query: 'url' } }
470
+ ]
471
+ }, timeoutMs);
472
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
473
+ return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
474
+ } catch (error) {
475
+ if (error.message?.includes('item-not-found') ||
476
+ error.output?.payload?.statusCode === 404 ||
477
+ error.statusCode === 404) {
478
+ logger.info(chalk.gray(`[INFO] Profile pic not found for ${jid}, using fallback`));
479
+ return {
480
+ eurl: undefined,
481
+ id: jid.split('@')[0],
482
+ status: null,
483
+ img: null
484
+ };
485
+ }
486
+ throw error;
487
+ }
488
+ };
489
+ const createCallLink = async (type, event, timeoutMs) => {
467
490
  const result = await query({
468
- tag: 'iq',
491
+ tag: 'call',
469
492
  attrs: {
470
- target: jid,
471
- to: WABinary_1.S_WHATSAPP_NET,
472
- type: 'get',
473
- xmlns: 'w:profile:picture'
493
+ id: generateMessageTag(),
494
+ to: '@call'
474
495
  },
475
496
  content: [
476
- { tag: 'picture', attrs: { type, query: 'url' } }
497
+ {
498
+ tag: 'link_create',
499
+ attrs: { media: type },
500
+ content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
501
+ }
477
502
  ]
478
503
  }, timeoutMs);
479
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
480
- return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
504
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
505
+ return child?.attrs?.token;
481
506
  };
482
507
  const sendPresenceUpdate = async (type, toJid) => {
483
508
  const me = authState.creds.me;
@@ -513,10 +538,6 @@ const makeChatsSocket = (config) => {
513
538
  });
514
539
  }
515
540
  };
516
- /**
517
- * @param toJid the jid to subscribe to
518
- * @param tcToken token for subscription, use if present
519
- */
520
541
  const presenceSubscribe = (toJid, tcToken) => (sendNode({
521
542
  tag: 'presence',
522
543
  attrs: {
@@ -625,7 +646,6 @@ const makeChatsSocket = (config) => {
625
646
  }
626
647
  }
627
648
  };
628
- /** sending non-abt props may fix QR scan fail if server expects */
629
649
  const fetchProps = async () => {
630
650
  var _a, _b, _c;
631
651
  const resultNode = await query({
@@ -645,7 +665,7 @@ const makeChatsSocket = (config) => {
645
665
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
646
666
  let props = {};
647
667
  if (propsNode) {
648
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
668
+ if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
649
669
  authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
650
670
  ev.emit('creds.update', authState.creds);
651
671
  }
@@ -654,18 +674,10 @@ const makeChatsSocket = (config) => {
654
674
  logger.debug('fetched props');
655
675
  return props;
656
676
  };
657
- /**
658
- * modify a chat -- mark unread, read etc.
659
- * lastMessages must be sorted in reverse chronologically
660
- * requires the last messages till the last message received; required for archive & unread
661
- */
662
677
  const chatModify = (mod, jid) => {
663
678
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
664
679
  return appPatch(patch);
665
680
  };
666
- /**
667
- * Star or Unstar a message
668
- */
669
681
  const star = (jid, messages, star) => {
670
682
  return chatModify({
671
683
  star: {
@@ -674,9 +686,15 @@ const makeChatsSocket = (config) => {
674
686
  }
675
687
  }, jid);
676
688
  };
677
- /**
678
- * Adds label for the chats
679
- */
689
+ const addOrEditContact = (jid, contact) => {
690
+ return chatModify({ contact }, jid);
691
+ };
692
+ const removeContact = (jid) => {
693
+ return chatModify({ contact: null }, jid);
694
+ };
695
+ const addLabel = (jid, labels) => {
696
+ return chatModify({ addLabel: { ...labels } }, jid);
697
+ };
680
698
  const addChatLabel = (jid, labelId) => {
681
699
  return chatModify({
682
700
  addChatLabel: {
@@ -684,9 +702,6 @@ const makeChatsSocket = (config) => {
684
702
  }
685
703
  }, jid);
686
704
  };
687
- /**
688
- * Removes label for the chat
689
- */
690
705
  const removeChatLabel = (jid, labelId) => {
691
706
  return chatModify({
692
707
  removeChatLabel: {
@@ -694,9 +709,6 @@ const makeChatsSocket = (config) => {
694
709
  }
695
710
  }, jid);
696
711
  };
697
- /**
698
- * Adds label for the message
699
- */
700
712
  const addMessageLabel = (jid, messageId, labelId) => {
701
713
  return chatModify({
702
714
  addMessageLabel: {
@@ -705,9 +717,6 @@ const makeChatsSocket = (config) => {
705
717
  }
706
718
  }, jid);
707
719
  };
708
- /**
709
- * Removes label for the message
710
- */
711
720
  const removeMessageLabel = (jid, messageId, labelId) => {
712
721
  return chatModify({
713
722
  removeMessageLabel: {
@@ -716,10 +725,6 @@ const makeChatsSocket = (config) => {
716
725
  }
717
726
  }, jid);
718
727
  };
719
- /**
720
- * queries need to be fired on connection open
721
- * help ensure parity with WA Web
722
- * */
723
728
  const executeInitQueries = async () => {
724
729
  await Promise.all([
725
730
  fetchProps(),
@@ -727,64 +732,155 @@ const makeChatsSocket = (config) => {
727
732
  fetchPrivacySettings(),
728
733
  ]);
729
734
  };
735
+ const canonicalizeUserJid = (jid) => {
736
+ if (!jid) {
737
+ return jid;
738
+ }
739
+ if ((0, WABinary_1.isLidUser)(jid)) {
740
+ return (0, WABinary_1.lidToJid)(jid);
741
+ }
742
+ return jid;
743
+ };
744
+ const extractStanzaId = (msg) => {
745
+ var _a, _b;
746
+ const topLevelStanzaId = (_a = msg.messageContextInfo) === null || _a === void 0 ? void 0 : _a.stanzaId;
747
+ if (topLevelStanzaId) {
748
+ return topLevelStanzaId;
749
+ }
750
+ const messageContextStanzaId = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.messageContextInfo;
751
+ if (messageContextStanzaId === null || messageContextStanzaId === void 0 ? void 0 : messageContextStanzaId.stanzaId) {
752
+ return messageContextStanzaId.stanzaId;
753
+ }
754
+ const normalizedContent = (0, Utils_1.normalizeMessageContent)(msg.message);
755
+ const contentType = normalizedContent ? (0, Utils_1.getContentType)(normalizedContent) : undefined;
756
+ const contentContextStanzaId = contentType
757
+ ? normalizedContent[contentType].contextInfo && normalizedContent[contentType].contextInfo.stanzaId
758
+ : undefined;
759
+ return contentContextStanzaId;
760
+ };
761
+ const buildMessageDedupKeys = (msg) => {
762
+ const remoteJid = canonicalizeUserJid(msg.key.remoteJid);
763
+ const participant = canonicalizeUserJid(msg.key.participant);
764
+ const stanzaId = extractStanzaId(msg);
765
+ const primaryKey = [remoteJid, participant, msg.key.id, msg.key.fromMe ? '1' : '0', stanzaId || ''].join('|');
766
+ const keys = [primaryKey];
767
+ // fallback alias key to collapse LID->PN duplicate deliveries for the same incoming user message ID
768
+ if (!msg.key.fromMe && ((0, WABinary_1.isJidUser)(msg.key.remoteJid) || (0, WABinary_1.isLidUser)(msg.key.remoteJid))) {
769
+ keys.push(`incoming-user-id|${msg.key.id}|${stanzaId || ''}`);
770
+ }
771
+ return keys;
772
+ };
773
+ const getDedupState = (msg) => msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
774
+ ? 'ciphertext'
775
+ : 'final';
776
+ const getPendingDedupState = (dedupState) => dedupState === 'final' ? 'processing' : dedupState;
730
777
  const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
731
778
  var _a, _b, _c;
732
- ev.emit('messages.upsert', { messages: [msg], type });
733
- if (!!msg.pushName) {
734
- let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
735
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
736
- if (!msg.key.fromMe) {
737
- ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
738
- }
739
- // update our pushname too
740
- if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
741
- ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
742
- }
779
+ const dedupKeys = buildMessageDedupKeys(msg);
780
+ const dedupState = getDedupState(msg);
781
+ const dedupStateBeforeProcess = new Map();
782
+ const previousDedupState = dedupKeys
783
+ .map(key => receivedMessageDedupCache.get(key))
784
+ .find(state => !!state);
785
+ if (previousDedupState === 'final'
786
+ || previousDedupState === 'processing'
787
+ || (previousDedupState === 'ciphertext' && dedupState === 'ciphertext')) {
788
+ logger.debug({ dedupKeys, messageId: msg.key.id, type, dedupState, previousDedupState }, 'skipping duplicate messages.upsert');
789
+ return;
743
790
  }
744
- const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
745
- const shouldProcessHistoryMsg = historyMsg
746
- ? (shouldSyncHistoryMessage(historyMsg)
747
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
748
- : false;
749
- if (historyMsg && !authState.creds.myAppStateKeyId) {
750
- logger.warn('skipping app state sync, as myAppStateKeyId is not set');
751
- pendingAppStateSync = true;
791
+ for (const key of dedupKeys) {
792
+ dedupStateBeforeProcess.set(key, receivedMessageDedupCache.get(key));
793
+ receivedMessageDedupCache.set(key, getPendingDedupState(dedupState));
752
794
  }
753
- await Promise.all([
754
- (async () => {
755
- if (historyMsg
756
- && authState.creds.myAppStateKeyId) {
757
- pendingAppStateSync = false;
758
- await doAppStateSync();
795
+ try {
796
+ ev.emit('messages.upsert', { messages: [msg], type });
797
+ if (!!msg.pushName) {
798
+ let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
799
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
800
+ if (!msg.key.fromMe) {
801
+ ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
759
802
  }
760
- })(),
761
- (0, process_message_1.default)(msg, {
762
- shouldProcessHistoryMsg,
763
- placeholderResendCache,
764
- ev,
765
- creds: authState.creds,
766
- keyStore: authState.keys,
767
- logger,
768
- options: config.options,
769
- getMessage: config.getMessage,
770
- })
771
- ]);
772
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
773
- && pendingAppStateSync) {
774
- await doAppStateSync();
775
- pendingAppStateSync = false;
776
- }
777
- async function doAppStateSync() {
778
- if (!authState.creds.accountSyncCounter) {
779
- logger.info('doing initial app state sync');
780
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
781
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
782
- ev.emit('creds.update', { accountSyncCounter });
783
- if (needToFlushWithAppStateSync) {
784
- logger.debug('flushing with app state sync');
803
+ if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
804
+ ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
805
+ }
806
+ }
807
+ const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
808
+ const shouldProcessHistoryMsg = historyMsg
809
+ ? (shouldSyncHistoryMessage(historyMsg)
810
+ && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
811
+ : false;
812
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
813
+ if (awaitingSyncTimeout) {
814
+ clearTimeout(awaitingSyncTimeout);
815
+ awaitingSyncTimeout = undefined;
816
+ }
817
+ if (shouldProcessHistoryMsg) {
818
+ syncState = SyncState.Syncing;
819
+ logger.info('Transitioned to Syncing state');
820
+ } else {
821
+ syncState = SyncState.Online;
822
+ logger.info('History sync skipped, transitioning to Online state and flushing buffer');
785
823
  ev.flush();
786
824
  }
787
825
  }
826
+ const doAppStateSync = async () => {
827
+ if (syncState === SyncState.Syncing) {
828
+ logger.info('Doing app state sync');
829
+ await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
830
+ syncState = SyncState.Online;
831
+ logger.info('App state sync complete, transitioning to Online state and flushing buffer');
832
+ ev.flush();
833
+ const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
834
+ ev.emit('creds.update', { accountSyncCounter });
835
+ }
836
+ };
837
+ if (historyMsg && !authState.creds.myAppStateKeyId) {
838
+ logger.warn('skipping app state sync, as myAppStateKeyId is not set');
839
+ pendingAppStateSync = true;
840
+ }
841
+ await Promise.all([
842
+ (async () => {
843
+ if (historyMsg
844
+ && authState.creds.myAppStateKeyId) {
845
+ pendingAppStateSync = false;
846
+ await doAppStateSync();
847
+ }
848
+ })(),
849
+ (0, process_message_1.default)(msg, {
850
+ signalRepository,
851
+ shouldProcessHistoryMsg,
852
+ placeholderResendCache,
853
+ ev,
854
+ creds: authState.creds,
855
+ keyStore: authState.keys,
856
+ logger,
857
+ options: config.options,
858
+ getMessage: config.getMessage,
859
+ })
860
+ ]);
861
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
862
+ && pendingAppStateSync) {
863
+ await doAppStateSync();
864
+ pendingAppStateSync = false;
865
+ }
866
+ for (const key of dedupKeys) {
867
+ receivedMessageDedupCache.set(key, dedupState);
868
+ }
869
+ }
870
+ catch (error) {
871
+ for (const key of dedupKeys) {
872
+ const currentState = receivedMessageDedupCache.get(key);
873
+ if (currentState === 'processing') {
874
+ const previousState = dedupStateBeforeProcess.get(key);
875
+ if (previousState) {
876
+ receivedMessageDedupCache.set(key, previousState);
877
+ }
878
+ else {
879
+ receivedMessageDedupCache.del(key);
880
+ }
881
+ }
882
+ }
883
+ throw error;
788
884
  }
789
885
  });
790
886
  ws.on('CB:presence', handlePresenceUpdate);
@@ -804,7 +900,6 @@ const makeChatsSocket = (config) => {
804
900
  }
805
901
  break;
806
902
  case 'groups':
807
- // handled in groups.ts
808
903
  break;
809
904
  default:
810
905
  logger.info({ node }, 'received unknown sync');
@@ -821,16 +916,43 @@ const makeChatsSocket = (config) => {
821
916
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
822
917
  .catch(error => onUnexpectedError(error, 'presence update requests'));
823
918
  }
824
- if (receivedPendingNotifications && // if we don't have the app state key
825
- // we keep buffering events until we finally have
826
- // the key and can sync the messages
919
+ if (receivedPendingNotifications &&
827
920
  !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
828
921
  ev.buffer();
829
922
  needToFlushWithAppStateSync = true;
830
923
  }
924
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
925
+ return;
926
+ }
927
+ syncState = SyncState.AwaitingInitialSync;
928
+ logger.info('Connection is now AwaitingInitialSync, buffering events');
929
+ ev.buffer();
930
+ const willSyncHistory = shouldSyncHistoryMessage(
931
+ WAProto_1.proto.Message.HistorySyncNotification.create({
932
+ syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
933
+ })
934
+ );
935
+ if (!willSyncHistory) {
936
+ logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
937
+ syncState = SyncState.Online;
938
+ setTimeout(() => ev.flush(), 0);
939
+ return;
940
+ }
941
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
942
+ if (awaitingSyncTimeout) {
943
+ clearTimeout(awaitingSyncTimeout);
944
+ }
945
+ awaitingSyncTimeout = setTimeout(() => {
946
+ if (syncState === SyncState.AwaitingInitialSync) {
947
+ logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
948
+ syncState = SyncState.Online;
949
+ ev.flush();
950
+ }
951
+ }, 20000);
831
952
  });
832
953
  return {
833
954
  ...sock,
955
+ createCallLink,
834
956
  getBotListV2,
835
957
  processingMutex,
836
958
  fetchPrivacySettings,
@@ -848,6 +970,7 @@ const makeChatsSocket = (config) => {
848
970
  updateProfileStatus,
849
971
  updateProfileName,
850
972
  updateBlockStatus,
973
+ updateDisableLinkPreviewsPrivacy,
851
974
  updateCallPrivacy,
852
975
  updateMessagesPrivacy,
853
976
  updateLastSeenPrivacy,
@@ -861,6 +984,9 @@ const makeChatsSocket = (config) => {
861
984
  resyncAppState,
862
985
  chatModify,
863
986
  cleanDirtyBits,
987
+ addOrEditContact,
988
+ removeContact,
989
+ addLabel,
864
990
  addChatLabel,
865
991
  removeChatLabel,
866
992
  addMessageLabel,
@@ -6,5 +6,5 @@ const business_1 = require("./business");
6
6
  const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
- })); // ⒷⒶⒾⓁⒺⓎⓈ ⒷⓎ ⓋⓎⓏⒺⓃ
9
+ }));
10
10
  exports.default = makeWASocket;