phantom-baileys 0.0.9 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (441) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +592 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +81 -0
  6. package/WAProto/index.d.ts +5147 -41513
  7. package/WAProto/index.js +84008 -142014
  8. package/lib/Defaults/index.d.ts +29 -8
  9. package/lib/Defaults/index.d.ts.map +1 -0
  10. package/lib/Defaults/index.js +80 -60
  11. package/lib/Defaults/index.js.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  14. package/lib/Signal/Group/ciphertext-message.js +12 -0
  15. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  20. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  21. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  22. package/lib/Signal/Group/group_cipher.js +82 -0
  23. package/lib/Signal/Group/group_cipher.js.map +1 -0
  24. package/lib/Signal/Group/index.d.ts +12 -0
  25. package/lib/Signal/Group/index.d.ts.map +1 -0
  26. package/lib/Signal/Group/index.js +12 -0
  27. package/lib/Signal/Group/index.js.map +1 -0
  28. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  29. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  30. package/lib/Signal/Group/keyhelper.js +18 -0
  31. package/lib/Signal/Group/keyhelper.js.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  34. package/lib/Signal/Group/sender-chain-key.js +26 -0
  35. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-message.js +66 -0
  43. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-name.js +48 -0
  47. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-record.js +41 -0
  51. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-state.js +84 -0
  55. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  58. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +3 -16
  59. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  60. package/lib/Signal/libsignal.d.ts +5 -3
  61. package/lib/Signal/libsignal.d.ts.map +1 -0
  62. package/lib/Signal/libsignal.js +331 -80
  63. package/lib/Signal/libsignal.js.map +1 -0
  64. package/lib/Signal/lid-mapping.d.ts +19 -0
  65. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  66. package/lib/Signal/lid-mapping.js +271 -0
  67. package/lib/Signal/lid-mapping.js.map +1 -0
  68. package/lib/Socket/Client/index.d.ts +3 -3
  69. package/lib/Socket/Client/index.d.ts.map +1 -0
  70. package/lib/Socket/Client/index.js +3 -19
  71. package/lib/Socket/Client/index.js.map +1 -0
  72. package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +4 -5
  73. package/lib/Socket/Client/types.d.ts.map +1 -0
  74. package/lib/Socket/Client/types.js +11 -0
  75. package/lib/Socket/Client/types.js.map +1 -0
  76. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +3 -2
  77. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  78. package/lib/Socket/Client/websocket.js +54 -0
  79. package/lib/Socket/Client/websocket.js.map +1 -0
  80. package/lib/Socket/business.d.ts +184 -101
  81. package/lib/Socket/business.d.ts.map +1 -0
  82. package/lib/Socket/business.js +162 -43
  83. package/lib/Socket/business.js.map +1 -0
  84. package/lib/Socket/chats.d.ts +72 -42
  85. package/lib/Socket/chats.d.ts.map +1 -0
  86. package/lib/Socket/chats.js +340 -299
  87. package/lib/Socket/chats.js.map +1 -0
  88. package/lib/Socket/communities.d.ts +309 -0
  89. package/lib/Socket/communities.d.ts.map +1 -0
  90. package/lib/Socket/communities.js +431 -0
  91. package/lib/Socket/communities.js.map +1 -0
  92. package/lib/Socket/dugong.d.ts +79 -0
  93. package/lib/Socket/dugong.d.ts.map +1 -0
  94. package/lib/Socket/dugong.js +527 -0
  95. package/lib/Socket/dugong.js.map +1 -0
  96. package/lib/Socket/groups.d.ts +93 -58
  97. package/lib/Socket/groups.d.ts.map +1 -0
  98. package/lib/Socket/groups.js +96 -84
  99. package/lib/Socket/groups.js.map +1 -0
  100. package/lib/Socket/index.d.ts +232 -107
  101. package/lib/Socket/index.d.ts.map +1 -0
  102. package/lib/Socket/index.js +13 -10
  103. package/lib/Socket/index.js.map +1 -0
  104. package/lib/Socket/messages-recv.d.ts +170 -90
  105. package/lib/Socket/messages-recv.d.ts.map +1 -0
  106. package/lib/Socket/messages-recv.js +798 -462
  107. package/lib/Socket/messages-recv.js.map +1 -0
  108. package/lib/Socket/messages-send.d.ts +180 -99
  109. package/lib/Socket/messages-send.d.ts.map +1 -0
  110. package/lib/Socket/messages-send.js +833 -709
  111. package/lib/Socket/messages-send.js.map +1 -0
  112. package/lib/Socket/mex.d.ts +3 -0
  113. package/lib/Socket/mex.d.ts.map +1 -0
  114. package/lib/Socket/mex.js +42 -0
  115. package/lib/Socket/mex.js.map +1 -0
  116. package/lib/Socket/newsletter.d.ts +120 -75
  117. package/lib/Socket/newsletter.d.ts.map +1 -0
  118. package/lib/Socket/newsletter.js +227 -198
  119. package/lib/Socket/newsletter.js.map +1 -0
  120. package/lib/Socket/socket.d.ts +31 -20
  121. package/lib/Socket/socket.d.ts.map +1 -0
  122. package/lib/Socket/socket.js +508 -215
  123. package/lib/Socket/socket.js.map +1 -0
  124. package/lib/Types/Auth.d.ts +18 -11
  125. package/lib/Types/Auth.d.ts.map +1 -0
  126. package/lib/Types/Auth.js +2 -2
  127. package/lib/Types/Auth.js.map +1 -0
  128. package/lib/Types/Bussines.d.ts +25 -0
  129. package/lib/Types/Bussines.d.ts.map +1 -0
  130. package/lib/Types/Bussines.js +2 -0
  131. package/lib/Types/Bussines.js.map +1 -0
  132. package/lib/Types/Call.d.ts +2 -0
  133. package/lib/Types/Call.d.ts.map +1 -0
  134. package/lib/Types/Call.js +2 -2
  135. package/lib/Types/Call.js.map +1 -0
  136. package/lib/Types/Chat.d.ts +24 -8
  137. package/lib/Types/Chat.d.ts.map +1 -0
  138. package/lib/Types/Chat.js +8 -4
  139. package/lib/Types/Chat.js.map +1 -0
  140. package/lib/Types/Contact.d.ts +6 -1
  141. package/lib/Types/Contact.d.ts.map +1 -0
  142. package/lib/Types/Contact.js +2 -2
  143. package/lib/Types/Contact.js.map +1 -0
  144. package/lib/Types/Events.d.ts +82 -17
  145. package/lib/Types/Events.d.ts.map +1 -0
  146. package/lib/Types/Events.js +2 -2
  147. package/lib/Types/Events.js.map +1 -0
  148. package/lib/Types/GroupMetadata.d.ts +15 -3
  149. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  150. package/lib/Types/GroupMetadata.js +2 -2
  151. package/lib/Types/GroupMetadata.js.map +1 -0
  152. package/lib/Types/Label.d.ts +1 -0
  153. package/lib/Types/Label.d.ts.map +1 -0
  154. package/lib/Types/Label.js +3 -5
  155. package/lib/Types/Label.js.map +1 -0
  156. package/lib/Types/LabelAssociation.d.ts +1 -0
  157. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  158. package/lib/Types/LabelAssociation.js +3 -5
  159. package/lib/Types/LabelAssociation.js.map +1 -0
  160. package/lib/Types/Message.d.ts +77 -202
  161. package/lib/Types/Message.d.ts.map +1 -0
  162. package/lib/Types/Message.js +11 -9
  163. package/lib/Types/Message.js.map +1 -0
  164. package/lib/Types/Newsletter.d.ts +128 -85
  165. package/lib/Types/Newsletter.d.ts.map +1 -0
  166. package/lib/Types/Newsletter.js +25 -26
  167. package/lib/Types/Newsletter.js.map +1 -0
  168. package/lib/Types/Product.d.ts +2 -1
  169. package/lib/Types/Product.d.ts.map +1 -0
  170. package/lib/Types/Product.js +2 -2
  171. package/lib/Types/Product.js.map +1 -0
  172. package/lib/Types/Signal.d.ts +20 -1
  173. package/lib/Types/Signal.d.ts.map +1 -0
  174. package/lib/Types/Signal.js +2 -2
  175. package/lib/Types/Signal.js.map +1 -0
  176. package/lib/Types/Socket.d.ts +41 -24
  177. package/lib/Types/Socket.d.ts.map +1 -0
  178. package/lib/Types/Socket.js +3 -2
  179. package/lib/Types/Socket.js.map +1 -0
  180. package/lib/Types/State.d.ts +14 -2
  181. package/lib/Types/State.d.ts.map +1 -0
  182. package/lib/Types/State.js +13 -2
  183. package/lib/Types/State.js.map +1 -0
  184. package/lib/Types/USync.d.ts +3 -2
  185. package/lib/Types/USync.d.ts.map +1 -0
  186. package/lib/Types/USync.js +2 -2
  187. package/lib/Types/USync.js.map +1 -0
  188. package/lib/Types/index.d.ts +15 -16
  189. package/lib/Types/index.d.ts.map +1 -0
  190. package/lib/Types/index.js +15 -31
  191. package/lib/Types/index.js.map +1 -0
  192. package/lib/Utils/auth-utils.d.ts +7 -6
  193. package/lib/Utils/auth-utils.d.ts.map +1 -0
  194. package/lib/Utils/auth-utils.js +228 -165
  195. package/lib/Utils/auth-utils.js.map +1 -0
  196. package/lib/Utils/browser-utils.d.ts +4 -0
  197. package/lib/Utils/browser-utils.d.ts.map +1 -0
  198. package/lib/Utils/browser-utils.js +28 -0
  199. package/lib/Utils/browser-utils.js.map +1 -0
  200. package/lib/Utils/business.d.ts +4 -3
  201. package/lib/Utils/business.d.ts.map +1 -0
  202. package/lib/Utils/business.js +66 -69
  203. package/lib/Utils/business.js.map +1 -0
  204. package/lib/Utils/chat-utils.d.ts +16 -16
  205. package/lib/Utils/chat-utils.d.ts.map +1 -0
  206. package/lib/Utils/chat-utils.js +299 -232
  207. package/lib/Utils/chat-utils.js.map +1 -0
  208. package/lib/Utils/crypto.d.ts +18 -21
  209. package/lib/Utils/crypto.d.ts.map +1 -0
  210. package/lib/Utils/crypto.js +44 -125
  211. package/lib/Utils/crypto.js.map +1 -0
  212. package/lib/Utils/decode-wa-message.d.ts +20 -8
  213. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  214. package/lib/Utils/decode-wa-message.js +139 -90
  215. package/lib/Utils/decode-wa-message.js.map +1 -0
  216. package/lib/Utils/event-buffer.d.ts +7 -8
  217. package/lib/Utils/event-buffer.d.ts.map +1 -0
  218. package/lib/Utils/event-buffer.js +129 -72
  219. package/lib/Utils/event-buffer.js.map +1 -0
  220. package/lib/Utils/generics.d.ts +25 -22
  221. package/lib/Utils/generics.d.ts.map +1 -0
  222. package/lib/Utils/generics.js +157 -175
  223. package/lib/Utils/generics.js.map +1 -0
  224. package/lib/Utils/history.d.ts +14 -11
  225. package/lib/Utils/history.d.ts.map +1 -0
  226. package/lib/Utils/history.js +83 -46
  227. package/lib/Utils/history.js.map +1 -0
  228. package/lib/Utils/identity-change-handler.d.ts +37 -0
  229. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  230. package/lib/Utils/identity-change-handler.js +49 -0
  231. package/lib/Utils/identity-change-handler.js.map +1 -0
  232. package/lib/Utils/index.d.ts +22 -17
  233. package/lib/Utils/index.d.ts.map +1 -0
  234. package/lib/Utils/index.js +22 -33
  235. package/lib/Utils/index.js.map +1 -0
  236. package/lib/Utils/link-preview.d.ts +5 -5
  237. package/lib/Utils/link-preview.d.ts.map +1 -0
  238. package/lib/Utils/link-preview.js +14 -22
  239. package/lib/Utils/link-preview.js.map +1 -0
  240. package/lib/Utils/logger.d.ts +12 -1
  241. package/lib/Utils/logger.d.ts.map +1 -0
  242. package/lib/Utils/logger.js +3 -7
  243. package/lib/Utils/logger.js.map +1 -0
  244. package/lib/Utils/lt-hash.d.ts +8 -12
  245. package/lib/Utils/lt-hash.d.ts.map +1 -0
  246. package/lib/Utils/lt-hash.js +3 -46
  247. package/lib/Utils/lt-hash.js.map +1 -0
  248. package/lib/Utils/make-mutex.d.ts +2 -0
  249. package/lib/Utils/make-mutex.d.ts.map +1 -0
  250. package/lib/Utils/make-mutex.js +24 -34
  251. package/lib/Utils/make-mutex.js.map +1 -0
  252. package/lib/Utils/message-retry-manager.d.ts +110 -0
  253. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  254. package/lib/Utils/message-retry-manager.js +225 -0
  255. package/lib/Utils/message-retry-manager.js.map +1 -0
  256. package/lib/Utils/messages-media.d.ts +59 -42
  257. package/lib/Utils/messages-media.d.ts.map +1 -0
  258. package/lib/Utils/messages-media.js +411 -356
  259. package/lib/Utils/messages-media.js.map +1 -0
  260. package/lib/Utils/messages.d.ts +32 -18
  261. package/lib/Utils/messages.d.ts.map +1 -0
  262. package/lib/Utils/messages.js +412 -723
  263. package/lib/Utils/messages.js.map +1 -0
  264. package/lib/Utils/noise-handler.d.ts +13 -13
  265. package/lib/Utils/noise-handler.d.ts.map +1 -0
  266. package/lib/Utils/noise-handler.js +149 -108
  267. package/lib/Utils/noise-handler.js.map +1 -0
  268. package/lib/Utils/offline-node-processor.d.ts +17 -0
  269. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  270. package/lib/Utils/offline-node-processor.js +40 -0
  271. package/lib/Utils/offline-node-processor.js.map +1 -0
  272. package/lib/Utils/pre-key-manager.d.ts +28 -0
  273. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  274. package/lib/Utils/pre-key-manager.js +106 -0
  275. package/lib/Utils/pre-key-manager.js.map +1 -0
  276. package/lib/Utils/process-message.d.ts +30 -11
  277. package/lib/Utils/process-message.d.ts.map +1 -0
  278. package/lib/Utils/process-message.js +321 -166
  279. package/lib/Utils/process-message.js.map +1 -0
  280. package/lib/Utils/reporting-utils.d.ts +11 -0
  281. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  282. package/lib/Utils/reporting-utils.js +258 -0
  283. package/lib/Utils/reporting-utils.js.map +1 -0
  284. package/lib/Utils/rich-messages.d.ts +129 -0
  285. package/lib/Utils/rich-messages.d.ts.map +1 -0
  286. package/lib/Utils/rich-messages.js +455 -0
  287. package/lib/Utils/rich-messages.js.map +1 -0
  288. package/lib/Utils/signal.d.ts +7 -6
  289. package/lib/Utils/signal.d.ts.map +1 -0
  290. package/lib/Utils/signal.js +65 -65
  291. package/lib/Utils/signal.js.map +1 -0
  292. package/lib/Utils/stanza-ack.d.ts +11 -0
  293. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  294. package/lib/Utils/stanza-ack.js +38 -0
  295. package/lib/Utils/stanza-ack.js.map +1 -0
  296. package/lib/Utils/sync-action-utils.d.ts +19 -0
  297. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  298. package/lib/Utils/sync-action-utils.js +48 -0
  299. package/lib/Utils/sync-action-utils.js.map +1 -0
  300. package/lib/Utils/tc-token-utils.d.ts +12 -0
  301. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  302. package/lib/Utils/tc-token-utils.js +18 -0
  303. package/lib/Utils/tc-token-utils.js.map +1 -0
  304. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  305. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  306. package/lib/Utils/use-multi-file-auth-state.js +79 -253
  307. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  308. package/lib/Utils/validate-connection.d.ts +6 -6
  309. package/lib/Utils/validate-connection.d.ts.map +1 -0
  310. package/lib/Utils/validate-connection.js +111 -116
  311. package/lib/Utils/validate-connection.js.map +1 -0
  312. package/lib/WABinary/constants.d.ts +5 -4
  313. package/lib/WABinary/constants.d.ts.map +1 -0
  314. package/lib/WABinary/constants.js +1281 -20
  315. package/lib/WABinary/constants.js.map +1 -0
  316. package/lib/WABinary/decode.d.ts +4 -3
  317. package/lib/WABinary/decode.d.ts.map +1 -0
  318. package/lib/WABinary/decode.js +51 -53
  319. package/lib/WABinary/decode.js.map +1 -0
  320. package/lib/WABinary/encode.d.ts +2 -1
  321. package/lib/WABinary/encode.d.ts.map +1 -0
  322. package/lib/WABinary/encode.js +12 -44
  323. package/lib/WABinary/encode.js.map +1 -0
  324. package/lib/WABinary/generic-utils.d.ts +9 -6
  325. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  326. package/lib/WABinary/generic-utils.js +124 -43
  327. package/lib/WABinary/generic-utils.js.map +1 -0
  328. package/lib/WABinary/index.d.ts +6 -5
  329. package/lib/WABinary/index.d.ts.map +1 -0
  330. package/lib/WABinary/index.js +6 -21
  331. package/lib/WABinary/index.js.map +1 -0
  332. package/lib/WABinary/jid-utils.d.ts +24 -7
  333. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  334. package/lib/WABinary/jid-utils.js +74 -40
  335. package/lib/WABinary/jid-utils.js.map +1 -0
  336. package/lib/WABinary/types.d.ts +2 -1
  337. package/lib/WABinary/types.d.ts.map +1 -0
  338. package/lib/WABinary/types.js +2 -2
  339. package/lib/WABinary/types.js.map +1 -0
  340. package/lib/WAM/BinaryInfo.d.ts +2 -1
  341. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  342. package/lib/WAM/BinaryInfo.js +2 -5
  343. package/lib/WAM/BinaryInfo.js.map +1 -0
  344. package/lib/WAM/constants.d.ts +5 -3
  345. package/lib/WAM/constants.d.ts.map +1 -0
  346. package/lib/WAM/constants.js +19071 -11568
  347. package/lib/WAM/constants.js.map +1 -0
  348. package/lib/WAM/encode.d.ts +3 -2
  349. package/lib/WAM/encode.d.ts.map +1 -0
  350. package/lib/WAM/encode.js +17 -22
  351. package/lib/WAM/encode.js.map +1 -0
  352. package/lib/WAM/index.d.ts +4 -3
  353. package/lib/WAM/index.d.ts.map +1 -0
  354. package/lib/WAM/index.js +4 -19
  355. package/lib/WAM/index.js.map +1 -0
  356. package/lib/WAProto/fix-imports.d.ts +1 -0
  357. package/lib/WAProto/fix-imports.js +71 -0
  358. package/lib/WAProto/index.js +89345 -0
  359. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  360. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  361. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
  362. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  363. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  364. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  365. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  366. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  367. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  368. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  369. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
  370. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  371. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  372. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  373. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  374. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  375. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  376. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  377. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  378. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  379. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
  380. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  381. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
  382. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  383. package/lib/WAUSync/Protocols/index.d.ts +5 -4
  384. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  385. package/lib/WAUSync/Protocols/index.js +5 -20
  386. package/lib/WAUSync/Protocols/index.js.map +1 -0
  387. package/lib/WAUSync/USyncQuery.d.ts +5 -4
  388. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  389. package/lib/WAUSync/USyncQuery.js +40 -35
  390. package/lib/WAUSync/USyncQuery.js.map +1 -0
  391. package/lib/WAUSync/USyncUser.d.ts +7 -4
  392. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  393. package/lib/WAUSync/USyncUser.js +2 -5
  394. package/lib/WAUSync/USyncUser.js.map +1 -0
  395. package/lib/WAUSync/index.d.ts +4 -3
  396. package/lib/WAUSync/index.d.ts.map +1 -0
  397. package/lib/WAUSync/index.js +4 -19
  398. package/lib/WAUSync/index.js.map +1 -0
  399. package/lib/index.d.ts +13 -0
  400. package/lib/index.d.ts.map +1 -0
  401. package/lib/index.js +16 -31
  402. package/lib/index.js.map +1 -0
  403. package/package.json +35 -75
  404. package/Readme.md +0 -1
  405. package/WASignalGroup/GroupProtocol.js +0 -1697
  406. package/WASignalGroup/ciphertext_message.js +0 -16
  407. package/WASignalGroup/group_cipher.js +0 -120
  408. package/WASignalGroup/group_session_builder.js +0 -46
  409. package/WASignalGroup/index.js +0 -5
  410. package/WASignalGroup/keyhelper.js +0 -21
  411. package/WASignalGroup/protobufs.js +0 -3
  412. package/WASignalGroup/queue_job.js +0 -69
  413. package/WASignalGroup/sender_chain_key.js +0 -50
  414. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  415. package/WASignalGroup/sender_key_message.js +0 -92
  416. package/WASignalGroup/sender_key_name.js +0 -70
  417. package/WASignalGroup/sender_key_record.js +0 -56
  418. package/WASignalGroup/sender_key_state.js +0 -129
  419. package/lib/Defaults/baileys-version.json +0 -3
  420. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  421. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  422. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  423. package/lib/Socket/Client/web-socket-client.js +0 -62
  424. package/lib/Socket/registration.d.ts +0 -264
  425. package/lib/Socket/registration.js +0 -166
  426. package/lib/Socket/usync.d.ts +0 -37
  427. package/lib/Socket/usync.js +0 -70
  428. package/lib/Store/index.d.ts +0 -3
  429. package/lib/Store/index.js +0 -10
  430. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  431. package/lib/Store/make-cache-manager-store.js +0 -83
  432. package/lib/Store/make-in-memory-store.d.ts +0 -118
  433. package/lib/Store/make-in-memory-store.js +0 -431
  434. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  435. package/lib/Store/make-ordered-dictionary.js +0 -81
  436. package/lib/Store/object-repository.d.ts +0 -10
  437. package/lib/Store/object-repository.js +0 -27
  438. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  439. package/lib/Utils/baileys-event-stream.js +0 -63
  440. package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
  441. package/lib/Utils/use-single-file-auth-state.js +0 -75
@@ -1,34 +1,38 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.makeChatsSocket = void 0;
7
- const node_cache_1 = __importDefault(require("node-cache"));
8
- const boom_1 = require("@hapi/boom");
9
- const WAProto_1 = require("../../WAProto");
10
- const Defaults_1 = require("../Defaults");
11
- const Types_1 = require("../Types");
12
- const Utils_1 = require("../Utils");
13
- const make_mutex_1 = require("../Utils/make-mutex");
14
- const process_message_1 = __importDefault(require("../Utils/process-message"));
15
- const WABinary_1 = require("../WABinary");
16
- const WAUSync_1 = require("../WAUSync");
17
- const usync_1 = require("./usync");
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { Boom } from '@hapi/boom';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
5
+ import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
6
+ import { SyncState } from '../Types/State.js';
7
+ import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
8
+ import { makeMutex } from '../Utils/make-mutex.js';
9
+ import processMessage from '../Utils/process-message.js';
10
+ import { buildTcTokenFromJid } from '../Utils/tc-token-utils.js';
11
+ import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
12
+ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
13
+ import { makeSocket } from './socket.js';
18
14
  const MAX_SYNC_ATTEMPTS = 2;
19
- const makeChatsSocket = (config) => {
20
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
21
- const sock = (0, usync_1.makeUSyncSocket)(config);
22
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
15
+ export const makeChatsSocket = (config) => {
16
+ const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, getMessage } = config;
17
+ const sock = makeSocket(config);
18
+ const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession } = sock;
23
19
  let privacySettings;
24
- let needToFlushWithAppStateSync = false;
25
- let pendingAppStateSync = false;
26
- /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
- const processingMutex = (0, make_mutex_1.makeMutex)();
28
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
30
- useClones: false
31
- });
20
+ let syncState = SyncState.Connecting;
21
+ /** this mutex ensures that messages are processed in order */
22
+ const messageMutex = makeMutex();
23
+ /** this mutex ensures that receipts are processed in order */
24
+ const receiptMutex = makeMutex();
25
+ /** this mutex ensures that app state patches are processed in order */
26
+ const appStatePatchMutex = makeMutex();
27
+ /** this mutex ensures that notifications are processed in order */
28
+ const notificationMutex = makeMutex();
29
+ // Timeout for AwaitingInitialSync state
30
+ let awaitingSyncTimeout;
31
+ const placeholderResendCache = config.placeholderResendCache ||
32
+ new NodeCache({
33
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
34
+ useClones: false
35
+ });
32
36
  if (!config.placeholderResendCache) {
33
37
  config.placeholderResendCache = placeholderResendCache;
34
38
  }
@@ -43,14 +47,12 @@ const makeChatsSocket = (config) => {
43
47
  tag: 'iq',
44
48
  attrs: {
45
49
  xmlns: 'privacy',
46
- to: WABinary_1.S_WHATSAPP_NET,
50
+ to: S_WHATSAPP_NET,
47
51
  type: 'get'
48
52
  },
49
- content: [
50
- { tag: 'privacy', attrs: {} }
51
- ]
53
+ content: [{ tag: 'privacy', attrs: {} }]
52
54
  });
53
- privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
55
+ privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
54
56
  }
55
57
  return privacySettings;
56
58
  };
@@ -60,10 +62,11 @@ const makeChatsSocket = (config) => {
60
62
  tag: 'iq',
61
63
  attrs: {
62
64
  xmlns: 'privacy',
63
- to: WABinary_1.S_WHATSAPP_NET,
65
+ to: S_WHATSAPP_NET,
64
66
  type: 'set'
65
67
  },
66
- content: [{
68
+ content: [
69
+ {
67
70
  tag: 'privacy',
68
71
  attrs: {},
69
72
  content: [
@@ -72,7 +75,8 @@ const makeChatsSocket = (config) => {
72
75
  attrs: { name, value }
73
76
  }
74
77
  ]
75
- }]
78
+ }
79
+ ]
76
80
  });
77
81
  };
78
82
  const updateMessagesPrivacy = async (value) => {
@@ -104,15 +108,17 @@ const makeChatsSocket = (config) => {
104
108
  tag: 'iq',
105
109
  attrs: {
106
110
  xmlns: 'disappearing_mode',
107
- to: WABinary_1.S_WHATSAPP_NET,
111
+ to: S_WHATSAPP_NET,
108
112
  type: 'set'
109
113
  },
110
- content: [{
114
+ content: [
115
+ {
111
116
  tag: 'disappearing_mode',
112
117
  attrs: {
113
118
  duration: duration.toString()
114
119
  }
115
- }]
120
+ }
121
+ ]
116
122
  });
117
123
  };
118
124
  const getBotListV2 = async () => {
@@ -120,21 +126,23 @@ const makeChatsSocket = (config) => {
120
126
  tag: 'iq',
121
127
  attrs: {
122
128
  xmlns: 'bot',
123
- to: WABinary_1.S_WHATSAPP_NET,
129
+ to: S_WHATSAPP_NET,
124
130
  type: 'get'
125
131
  },
126
- content: [{
132
+ content: [
133
+ {
127
134
  tag: 'bot',
128
135
  attrs: {
129
136
  v: '2'
130
137
  }
131
- }]
138
+ }
139
+ ]
132
140
  });
133
- const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
141
+ const botNode = getBinaryNodeChild(resp, 'bot');
134
142
  const botList = [];
135
- for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
143
+ for (const section of getBinaryNodeChildren(botNode, 'section')) {
136
144
  if (section.attrs.type === 'all') {
137
- for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
145
+ for (const bot of getBinaryNodeChildren(section, 'bot')) {
138
146
  botList.push({
139
147
  jid: bot.attrs.jid,
140
148
  personaId: bot.attrs['persona_id']
@@ -144,78 +152,10 @@ const makeChatsSocket = (config) => {
144
152
  }
145
153
  return botList;
146
154
  };
147
- /** helper function to run a generic IQ query */
148
- const interactiveQuery = async (userNodes, queryNode) => {
149
- const result = await query({
150
- tag: 'iq',
151
- attrs: {
152
- to: WABinary_1.S_WHATSAPP_NET,
153
- type: 'get',
154
- xmlns: 'usync',
155
- },
156
- content: [
157
- {
158
- tag: 'usync',
159
- attrs: {
160
- sid: generateMessageTag(),
161
- mode: 'query',
162
- last: 'true',
163
- index: '0',
164
- context: 'interactive',
165
- },
166
- content: [
167
- {
168
- tag: 'query',
169
- attrs: {},
170
- content: [queryNode]
171
- },
172
- {
173
- tag: 'list',
174
- attrs: {},
175
- content: userNodes
176
- }
177
- ]
178
- }
179
- ],
180
- });
181
- const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
182
- const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
183
- const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
184
- return users;
185
- };
186
- const fetchUserLid = async (jid) => {
187
- const [result] = await interactiveQuery([
188
- {
189
- tag: 'user',
190
- attrs: { jid }
191
- }
192
- ], {
193
- tag: 'lid',
194
- attrs: {}
195
- });
196
- if (result) {
197
- const lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
198
- return lid.attrs.val;
199
- }
200
- };
201
- const onWhatsApp = async (...jids) => {
202
- const usyncQuery = new WAUSync_1.USyncQuery()
203
- .withContactProtocol()
204
- .withLIDProtocol();
205
- for (const jid of jids) {
206
- const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
207
- usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
208
- }
209
- const results = await sock.executeUSyncQuery(usyncQuery);
210
- if (results) {
211
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
212
- }
213
- };
214
155
  const fetchStatus = async (...jids) => {
215
- const usyncQuery = new WAUSync_1.USyncQuery()
216
- .withStatusProtocol();
156
+ const usyncQuery = new USyncQuery().withStatusProtocol();
217
157
  for (const jid of jids) {
218
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
158
+ usyncQuery.withUser(new USyncUser().withId(jid));
219
159
  }
220
160
  const result = await sock.executeUSyncQuery(usyncQuery);
221
161
  if (result) {
@@ -223,10 +163,9 @@ const makeChatsSocket = (config) => {
223
163
  }
224
164
  };
225
165
  const fetchDisappearingDuration = async (...jids) => {
226
- const usyncQuery = new WAUSync_1.USyncQuery()
227
- .withDisappearingModeProtocol();
166
+ const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
228
167
  for (const jid of jids) {
229
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
168
+ usyncQuery.withUser(new USyncUser().withId(jid));
230
169
  }
231
170
  const result = await sock.executeUSyncQuery(usyncQuery);
232
171
  if (result) {
@@ -234,22 +173,25 @@ const makeChatsSocket = (config) => {
234
173
  }
235
174
  };
236
175
  /** update the profile picture for yourself or a group */
237
- const updateProfilePicture = async (jid, content) => {
176
+ const updateProfilePicture = async (jid, content, dimensions) => {
238
177
  let targetJid;
239
178
  if (!jid) {
240
- 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');
179
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
241
180
  }
242
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
243
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
181
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
182
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
244
183
  }
245
- const { img } = await (0, Utils_1.generateProfilePicture)(content);
184
+ else {
185
+ targetJid = undefined;
186
+ }
187
+ const { img } = await generateProfilePicture(content, dimensions);
246
188
  await query({
247
189
  tag: 'iq',
248
190
  attrs: {
249
- target: targetJid,
250
- to: WABinary_1.S_WHATSAPP_NET,
191
+ to: S_WHATSAPP_NET,
251
192
  type: 'set',
252
- xmlns: 'w:profile:picture'
193
+ xmlns: 'w:profile:picture',
194
+ ...(targetJid ? { target: targetJid } : {})
253
195
  },
254
196
  content: [
255
197
  {
@@ -264,18 +206,21 @@ const makeChatsSocket = (config) => {
264
206
  const removeProfilePicture = async (jid) => {
265
207
  let targetJid;
266
208
  if (!jid) {
267
- 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');
209
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
210
+ }
211
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
212
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
268
213
  }
269
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
270
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
214
+ else {
215
+ targetJid = undefined;
271
216
  }
272
217
  await query({
273
218
  tag: 'iq',
274
219
  attrs: {
275
- target: targetJid,
276
- to: WABinary_1.S_WHATSAPP_NET,
220
+ to: S_WHATSAPP_NET,
277
221
  type: 'set',
278
- xmlns: 'w:profile:picture'
222
+ xmlns: 'w:profile:picture',
223
+ ...(targetJid ? { target: targetJid } : {})
279
224
  }
280
225
  });
281
226
  };
@@ -284,7 +229,7 @@ const makeChatsSocket = (config) => {
284
229
  await query({
285
230
  tag: 'iq',
286
231
  attrs: {
287
- to: WABinary_1.S_WHATSAPP_NET,
232
+ to: S_WHATSAPP_NET,
288
233
  type: 'set',
289
234
  xmlns: 'status'
290
235
  },
@@ -305,20 +250,19 @@ const makeChatsSocket = (config) => {
305
250
  tag: 'iq',
306
251
  attrs: {
307
252
  xmlns: 'blocklist',
308
- to: WABinary_1.S_WHATSAPP_NET,
253
+ to: S_WHATSAPP_NET,
309
254
  type: 'get'
310
255
  }
311
256
  });
312
- const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
313
- return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
314
- .map(n => n.attrs.jid);
257
+ const listNode = getBinaryNodeChild(result, 'list');
258
+ return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
315
259
  };
316
260
  const updateBlockStatus = async (jid, action) => {
317
261
  await query({
318
262
  tag: 'iq',
319
263
  attrs: {
320
264
  xmlns: 'blocklist',
321
- to: WABinary_1.S_WHATSAPP_NET,
265
+ to: S_WHATSAPP_NET,
322
266
  type: 'set'
323
267
  },
324
268
  content: [
@@ -333,7 +277,6 @@ const makeChatsSocket = (config) => {
333
277
  });
334
278
  };
335
279
  const getBusinessProfile = async (jid) => {
336
- var _a, _b, _c, _d, _e, _f, _g;
337
280
  const results = await query({
338
281
  tag: 'iq',
339
282
  attrs: {
@@ -341,38 +284,42 @@ const makeChatsSocket = (config) => {
341
284
  xmlns: 'w:biz',
342
285
  type: 'get'
343
286
  },
344
- content: [{
287
+ content: [
288
+ {
345
289
  tag: 'business_profile',
346
290
  attrs: { v: '244' },
347
- content: [{
291
+ content: [
292
+ {
348
293
  tag: 'profile',
349
294
  attrs: { jid }
350
- }]
351
- }]
295
+ }
296
+ ]
297
+ }
298
+ ]
352
299
  });
353
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
354
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
300
+ const profileNode = getBinaryNodeChild(results, 'business_profile');
301
+ const profiles = getBinaryNodeChild(profileNode, 'profile');
355
302
  if (profiles) {
356
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
357
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
358
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
359
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
360
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
361
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
362
- const businessHoursConfig = businessHours ?
363
- (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
364
- undefined;
365
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
303
+ const address = getBinaryNodeChild(profiles, 'address');
304
+ const description = getBinaryNodeChild(profiles, 'description');
305
+ const website = getBinaryNodeChild(profiles, 'website');
306
+ const email = getBinaryNodeChild(profiles, 'email');
307
+ const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
308
+ const businessHours = getBinaryNodeChild(profiles, 'business_hours');
309
+ const businessHoursConfig = businessHours
310
+ ? getBinaryNodeChildren(businessHours, 'business_hours_config')
311
+ : undefined;
312
+ const websiteStr = website?.content?.toString();
366
313
  return {
367
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
368
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
369
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
314
+ wid: profiles.attrs?.jid,
315
+ address: address?.content?.toString(),
316
+ description: description?.content?.toString() || '',
370
317
  website: websiteStr ? [websiteStr] : [],
371
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
372
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
373
- 'business_hours': {
374
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
375
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
318
+ email: email?.content?.toString(),
319
+ category: category?.content?.toString(),
320
+ business_hours: {
321
+ timezone: businessHours?.attrs?.timezone,
322
+ business_config: businessHoursConfig?.map(({ attrs }) => attrs)
376
323
  }
377
324
  };
378
325
  }
@@ -382,17 +329,17 @@ const makeChatsSocket = (config) => {
382
329
  await sendNode({
383
330
  tag: 'iq',
384
331
  attrs: {
385
- to: WABinary_1.S_WHATSAPP_NET,
332
+ to: S_WHATSAPP_NET,
386
333
  type: 'set',
387
334
  xmlns: 'urn:xmpp:whatsapp:dirty',
388
- id: generateMessageTag(),
335
+ id: generateMessageTag()
389
336
  },
390
337
  content: [
391
338
  {
392
339
  tag: 'clean',
393
340
  attrs: {
394
341
  type,
395
- ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
342
+ ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
396
343
  }
397
344
  }
398
345
  ]
@@ -401,17 +348,25 @@ const makeChatsSocket = (config) => {
401
348
  const newAppStateChunkHandler = (isInitialSync) => {
402
349
  return {
403
350
  onMutation(mutation) {
404
- (0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
351
+ processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
405
352
  }
406
353
  };
407
354
  };
408
355
  const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
356
+ const appStateSyncKeyCache = new Map();
357
+ const getCachedAppStateSyncKey = async (keyId) => {
358
+ if (appStateSyncKeyCache.has(keyId)) {
359
+ return appStateSyncKeyCache.get(keyId) ?? undefined;
360
+ }
361
+ const key = await getAppStateSyncKey(keyId);
362
+ appStateSyncKeyCache.set(keyId, key ?? null);
363
+ return key;
364
+ };
409
365
  // we use this to determine which events to fire
410
366
  // otherwise when we resync from scratch -- all notifications will fire
411
367
  const initialVersionMap = {};
412
368
  const globalMutationMap = {};
413
369
  await authState.keys.transaction(async () => {
414
- var _a;
415
370
  const collectionsToHandle = new Set(collections);
416
371
  // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
417
372
  const attemptsMap = {};
@@ -430,7 +385,7 @@ const makeChatsSocket = (config) => {
430
385
  }
431
386
  }
432
387
  else {
433
- state = (0, Utils_1.newLTHashState)();
388
+ state = newLTHashState();
434
389
  }
435
390
  states[name] = state;
436
391
  logger.info(`resyncing ${name} from v${state.version}`);
@@ -440,14 +395,14 @@ const makeChatsSocket = (config) => {
440
395
  name,
441
396
  version: state.version.toString(),
442
397
  // return snapshot if being synced from scratch
443
- 'return_snapshot': (!state.version).toString()
398
+ return_snapshot: (!state.version).toString()
444
399
  }
445
400
  });
446
401
  }
447
402
  const result = await query({
448
403
  tag: 'iq',
449
404
  attrs: {
450
- to: WABinary_1.S_WHATSAPP_NET,
405
+ to: S_WHATSAPP_NET,
451
406
  xmlns: 'w:sync:app:state',
452
407
  type: 'set'
453
408
  },
@@ -460,26 +415,22 @@ const makeChatsSocket = (config) => {
460
415
  ]
461
416
  });
462
417
  // extract from binary node
463
- const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
418
+ const decoded = await extractSyncdPatches(result, config?.options);
464
419
  for (const key in decoded) {
465
420
  const name = key;
466
421
  const { patches, hasMorePatches, snapshot } = decoded[name];
467
422
  try {
468
423
  if (snapshot) {
469
- const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
424
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getCachedAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
470
425
  states[name] = newState;
471
426
  Object.assign(globalMutationMap, mutationMap);
472
427
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
473
- await authState.keys.set({ 'app-state-sync-version': {
474
- [name]: newState
475
- } });
428
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
476
429
  }
477
430
  // only process if there are syncd patches
478
431
  if (patches.length) {
479
- const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
480
- await authState.keys.set({ 'app-state-sync-version': {
481
- [name]: newState
482
- } });
432
+ const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getCachedAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
433
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
483
434
  logger.info(`synced ${name} to v${newState.version}`);
484
435
  initialVersionMap[name] = newState.version;
485
436
  Object.assign(globalMutationMap, mutationMap);
@@ -487,7 +438,8 @@ const makeChatsSocket = (config) => {
487
438
  if (hasMorePatches) {
488
439
  logger.info(`${name} has more patches...`);
489
440
  }
490
- else { // collection is done with sync
441
+ else {
442
+ // collection is done with sync
491
443
  collectionsToHandle.delete(name);
492
444
  }
493
445
  }
@@ -495,12 +447,10 @@ const makeChatsSocket = (config) => {
495
447
  // if retry attempts overshoot
496
448
  // or key not found
497
449
  const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
498
- ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
450
+ error.output?.statusCode === 404 ||
499
451
  error.name === 'TypeError';
500
452
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
501
- await authState.keys.set({ 'app-state-sync-version': {
502
- [name]: null
503
- } });
453
+ await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
504
454
  // increment number of retries
505
455
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
506
456
  if (isIrrecoverableError) {
@@ -510,7 +460,7 @@ const makeChatsSocket = (config) => {
510
460
  }
511
461
  }
512
462
  }
513
- });
463
+ }, authState?.creds?.me?.id || 'resync-app-state');
514
464
  const { onMutation } = newAppStateChunkHandler(isInitialSync);
515
465
  for (const key in globalMutationMap) {
516
466
  onMutation(globalMutationMap[key]);
@@ -520,47 +470,70 @@ const makeChatsSocket = (config) => {
520
470
  * fetch the profile picture of a user/group
521
471
  * type = "preview" for a low res picture
522
472
  * type = "image for the high res picture"
523
- */;
473
+ */
524
474
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
525
- var _a;
526
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
475
+ const baseContent = [{ tag: 'picture', attrs: { type, query: 'url' } }];
476
+ const tcTokenContent = await buildTcTokenFromJid({ authState, jid, baseContent });
477
+ jid = jidNormalizedUser(jid);
527
478
  const result = await query({
528
479
  tag: 'iq',
529
480
  attrs: {
530
481
  target: jid,
531
- to: WABinary_1.S_WHATSAPP_NET,
482
+ to: S_WHATSAPP_NET,
532
483
  type: 'get',
533
484
  xmlns: 'w:profile:picture'
534
485
  },
486
+ content: tcTokenContent
487
+ }, timeoutMs);
488
+ const child = getBinaryNodeChild(result, 'picture');
489
+ return child?.attrs?.url;
490
+ };
491
+ const createCallLink = async (type, event, timeoutMs) => {
492
+ const result = await query({
493
+ tag: 'call',
494
+ attrs: {
495
+ id: generateMessageTag(),
496
+ to: '@call'
497
+ },
535
498
  content: [
536
- { tag: 'picture', attrs: { type, query: 'url' } }
499
+ {
500
+ tag: 'link_create',
501
+ attrs: { media: type },
502
+ content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
503
+ }
537
504
  ]
538
505
  }, timeoutMs);
539
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
540
- return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
506
+ const child = getBinaryNodeChild(result, 'link_create');
507
+ return child?.attrs?.token;
541
508
  };
542
509
  const sendPresenceUpdate = async (type, toJid) => {
543
510
  const me = authState.creds.me;
544
- if (type === 'available' || type === 'unavailable') {
511
+ const isAvailableType = type === 'available';
512
+ if (isAvailableType || type === 'unavailable') {
545
513
  if (!me.name) {
546
514
  logger.warn('no name present, ignoring presence update request...');
547
515
  return;
548
516
  }
549
- ev.emit('connection.update', { isOnline: type === 'available' });
517
+ ev.emit('connection.update', { isOnline: isAvailableType });
518
+ if (isAvailableType) {
519
+ void sendUnifiedSession();
520
+ }
550
521
  await sendNode({
551
522
  tag: 'presence',
552
523
  attrs: {
553
- name: me.name,
524
+ name: me.name.replace(/@/g, ''),
554
525
  type
555
526
  }
556
527
  });
557
528
  }
558
529
  else {
530
+ const { server } = jidDecode(toJid);
531
+ const isLid = server === 'lid';
559
532
  await sendNode({
560
533
  tag: 'chatstate',
561
534
  attrs: {
562
- from: me.id,
563
- to: toJid,
535
+ from: isLid ? me.lid : me.id,
536
+ to: toJid
564
537
  },
565
538
  content: [
566
539
  {
@@ -575,29 +548,23 @@ const makeChatsSocket = (config) => {
575
548
  * @param toJid the jid to subscribe to
576
549
  * @param tcToken token for subscription, use if present
577
550
  */
578
- const presenceSubscribe = (toJid, tcToken) => (sendNode({
579
- tag: 'presence',
580
- attrs: {
581
- to: toJid,
582
- id: generateMessageTag(),
583
- type: 'subscribe'
584
- },
585
- content: tcToken ?
586
- [
587
- {
588
- tag: 'tctoken',
589
- attrs: {},
590
- content: tcToken
591
- }
592
- ] :
593
- undefined
594
- }));
551
+ const presenceSubscribe = async (toJid) => {
552
+ const tcTokenContent = await buildTcTokenFromJid({ authState, jid: toJid });
553
+ return sendNode({
554
+ tag: 'presence',
555
+ attrs: {
556
+ to: toJid,
557
+ id: generateMessageTag(),
558
+ type: 'subscribe'
559
+ },
560
+ content: tcTokenContent
561
+ });
562
+ };
595
563
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
596
- var _a;
597
564
  let presence;
598
565
  const jid = attrs.from;
599
566
  const participant = attrs.participant || attrs.from;
600
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
567
+ if (shouldIgnoreJid(jid) && jid !== S_WHATSAPP_NET) {
601
568
  return;
602
569
  }
603
570
  if (tag === 'presence') {
@@ -612,7 +579,7 @@ const makeChatsSocket = (config) => {
612
579
  if (type === 'paused') {
613
580
  type = 'available';
614
581
  }
615
- if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
582
+ if (firstChild.attrs?.media === 'audio') {
616
583
  type = 'recording';
617
584
  }
618
585
  presence = { lastKnownPresence: type };
@@ -621,31 +588,29 @@ const makeChatsSocket = (config) => {
621
588
  logger.error({ tag, attrs, content }, 'recv invalid presence node');
622
589
  }
623
590
  if (presence) {
624
- ev.emit('presence.update', { id: jid, presences: {
625
- [participant]: presence
626
- } });
591
+ ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
627
592
  }
628
593
  };
629
594
  const appPatch = async (patchCreate) => {
630
595
  const name = patchCreate.type;
631
596
  const myAppStateKeyId = authState.creds.myAppStateKeyId;
632
597
  if (!myAppStateKeyId) {
633
- throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
598
+ throw new Boom('App state key not present!', { statusCode: 400 });
634
599
  }
635
600
  let initial;
636
601
  let encodeResult;
637
- await processingMutex.mutex(async () => {
602
+ await appStatePatchMutex.mutex(async () => {
638
603
  await authState.keys.transaction(async () => {
639
604
  logger.debug({ patch: patchCreate }, 'applying app patch');
640
605
  await resyncAppState([name], false);
641
606
  const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
642
- initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
643
- encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
607
+ initial = currentSyncVersion || newLTHashState();
608
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
644
609
  const { patch, state } = encodeResult;
645
610
  const node = {
646
611
  tag: 'iq',
647
612
  attrs: {
648
- to: WABinary_1.S_WHATSAPP_NET,
613
+ to: S_WHATSAPP_NET,
649
614
  type: 'set',
650
615
  xmlns: 'w:sync:app:state'
651
616
  },
@@ -659,13 +624,13 @@ const makeChatsSocket = (config) => {
659
624
  attrs: {
660
625
  name,
661
626
  version: (state.version - 1).toString(),
662
- 'return_snapshot': 'false'
627
+ return_snapshot: 'false'
663
628
  },
664
629
  content: [
665
630
  {
666
631
  tag: 'patch',
667
632
  attrs: {},
668
- content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
633
+ content: proto.SyncdPatch.encode(patch).finish()
669
634
  }
670
635
  ]
671
636
  }
@@ -674,14 +639,12 @@ const makeChatsSocket = (config) => {
674
639
  ]
675
640
  };
676
641
  await query(node);
677
- await authState.keys.set({ 'app-state-sync-version': {
678
- [name]: state
679
- } });
680
- });
642
+ await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
643
+ }, authState?.creds?.me?.id || 'app-patch');
681
644
  });
682
645
  if (config.emitOwnEvents) {
683
646
  const { onMutation } = newAppStateChunkHandler(false);
684
- const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
647
+ const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
685
648
  for (const key in mutationMap) {
686
649
  onMutation(mutationMap[key]);
687
650
  }
@@ -689,32 +652,33 @@ const makeChatsSocket = (config) => {
689
652
  };
690
653
  /** sending non-abt props may fix QR scan fail if server expects */
691
654
  const fetchProps = async () => {
692
- var _a, _b;
655
+ //TODO: implement both protocol 1 and protocol 2 prop fetching, specially for abKey for WM
693
656
  const resultNode = await query({
694
657
  tag: 'iq',
695
658
  attrs: {
696
- to: WABinary_1.S_WHATSAPP_NET,
659
+ to: S_WHATSAPP_NET,
697
660
  xmlns: 'w',
698
- type: 'get',
661
+ type: 'get'
699
662
  },
700
663
  content: [
701
664
  {
702
665
  tag: 'props',
703
666
  attrs: {
704
667
  protocol: '2',
705
- hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
668
+ hash: authState?.creds?.lastPropHash || ''
706
669
  }
707
670
  }
708
671
  ]
709
672
  });
710
- const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
673
+ const propsNode = getBinaryNodeChild(resultNode, 'props');
711
674
  let props = {};
712
675
  if (propsNode) {
713
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
714
- authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
676
+ if (propsNode.attrs?.hash) {
677
+ // on some clients, the hash is returning as undefined
678
+ authState.creds.lastPropHash = propsNode?.attrs?.hash;
715
679
  ev.emit('creds.update', authState.creds);
716
680
  }
717
- props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
681
+ props = reduceBinaryNodeToDictionary(propsNode, 'prop');
718
682
  }
719
683
  logger.debug('fetched props');
720
684
  return props;
@@ -725,9 +689,17 @@ const makeChatsSocket = (config) => {
725
689
  * requires the last messages till the last message received; required for archive & unread
726
690
  */
727
691
  const chatModify = (mod, jid) => {
728
- const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
692
+ const patch = chatModificationToAppPatch(mod, jid);
729
693
  return appPatch(patch);
730
694
  };
695
+ /**
696
+ * Enable/Disable link preview privacy, not related to baileys link preview generation
697
+ */
698
+ const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
699
+ return chatModify({
700
+ disableLinkPreviews: { isPreviewsDisabled }
701
+ }, '');
702
+ };
731
703
  /**
732
704
  * Star or Unstar a message
733
705
  */
@@ -739,6 +711,22 @@ const makeChatsSocket = (config) => {
739
711
  }
740
712
  }, jid);
741
713
  };
714
+ /**
715
+ * Add or Edit Contact
716
+ */
717
+ const addOrEditContact = (jid, contact) => {
718
+ return chatModify({
719
+ contact
720
+ }, jid);
721
+ };
722
+ /**
723
+ * Remove Contact
724
+ */
725
+ const removeContact = (jid) => {
726
+ return chatModify({
727
+ contact: null
728
+ }, jid);
729
+ };
742
730
  /**
743
731
  * Adds label
744
732
  */
@@ -791,49 +779,84 @@ const makeChatsSocket = (config) => {
791
779
  }
792
780
  }, jid);
793
781
  };
782
+ /**
783
+ * Add or Edit Quick Reply
784
+ */
785
+ const addOrEditQuickReply = (quickReply) => {
786
+ return chatModify({
787
+ quickReply
788
+ }, '');
789
+ };
790
+ /**
791
+ * Remove Quick Reply
792
+ */
793
+ const removeQuickReply = (timestamp) => {
794
+ return chatModify({
795
+ quickReply: { timestamp, deleted: true }
796
+ }, '');
797
+ };
794
798
  /**
795
799
  * queries need to be fired on connection open
796
800
  * help ensure parity with WA Web
797
801
  * */
798
802
  const executeInitQueries = async () => {
799
- await Promise.all([
800
- fetchProps(),
801
- fetchBlocklist(),
802
- fetchPrivacySettings(),
803
- ]);
803
+ await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
804
804
  };
805
805
  const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
806
- var _a, _b, _c;
807
806
  ev.emit('messages.upsert', { messages: [msg], type });
808
807
  if (!!msg.pushName) {
809
- let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
810
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
808
+ let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
809
+ jid = jidNormalizedUser(jid);
811
810
  if (!msg.key.fromMe) {
812
811
  ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
813
812
  }
814
813
  // update our pushname too
815
- if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
814
+ if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
816
815
  ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
817
816
  }
818
817
  }
819
- const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
820
- const shouldProcessHistoryMsg = historyMsg ?
821
- (shouldSyncHistoryMessage(historyMsg) &&
822
- Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
823
- false;
824
- if (historyMsg && !authState.creds.myAppStateKeyId) {
825
- logger.warn('skipping app state sync, as myAppStateKeyId is not set');
826
- pendingAppStateSync = true;
818
+ const historyMsg = getHistoryMsg(msg.message);
819
+ const shouldProcessHistoryMsg = historyMsg
820
+ ? shouldSyncHistoryMessage(historyMsg) &&
821
+ PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
822
+ : false;
823
+ // State machine: decide on sync and flush
824
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
825
+ if (awaitingSyncTimeout) {
826
+ clearTimeout(awaitingSyncTimeout);
827
+ awaitingSyncTimeout = undefined;
828
+ }
829
+ if (shouldProcessHistoryMsg) {
830
+ syncState = SyncState.Syncing;
831
+ logger.info('Transitioned to Syncing state');
832
+ // Let doAppStateSync handle the final flush after it's done
833
+ }
834
+ else {
835
+ syncState = SyncState.Online;
836
+ logger.info('History sync skipped, transitioning to Online state and flushing buffer');
837
+ ev.flush();
838
+ }
827
839
  }
840
+ const doAppStateSync = async () => {
841
+ if (syncState === SyncState.Syncing) {
842
+ logger.info('Doing app state sync');
843
+ await resyncAppState(ALL_WA_PATCH_NAMES, true);
844
+ // Sync is complete, go online and flush everything
845
+ syncState = SyncState.Online;
846
+ logger.info('App state sync complete, transitioning to Online state and flushing buffer');
847
+ ev.flush();
848
+ const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
849
+ ev.emit('creds.update', { accountSyncCounter });
850
+ }
851
+ };
828
852
  await Promise.all([
829
853
  (async () => {
830
- if (historyMsg &&
831
- authState.creds.myAppStateKeyId) {
832
- pendingAppStateSync = false;
854
+ if (shouldProcessHistoryMsg) {
833
855
  await doAppStateSync();
834
856
  }
835
857
  })(),
836
- (0, process_message_1.default)(msg, {
858
+ processMessage(msg, {
859
+ signalRepository,
837
860
  shouldProcessHistoryMsg,
838
861
  placeholderResendCache,
839
862
  ev,
@@ -841,31 +864,19 @@ const makeChatsSocket = (config) => {
841
864
  keyStore: authState.keys,
842
865
  logger,
843
866
  options: config.options,
844
- getMessage: config.getMessage,
867
+ getMessage
845
868
  })
846
869
  ]);
847
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
848
- pendingAppStateSync) {
870
+ // If the app state key arrives and we are waiting to sync, trigger the sync now.
871
+ if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
872
+ logger.info('App state sync key arrived, triggering app state sync');
849
873
  await doAppStateSync();
850
- pendingAppStateSync = false;
851
- }
852
- async function doAppStateSync() {
853
- if (!authState.creds.accountSyncCounter) {
854
- logger.info('doing initial app state sync');
855
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
856
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
857
- ev.emit('creds.update', { accountSyncCounter });
858
- if (needToFlushWithAppStateSync) {
859
- logger.debug('flushing with app state sync');
860
- ev.flush();
861
- }
862
- }
863
874
  }
864
875
  });
865
876
  ws.on('CB:presence', handlePresenceUpdate);
866
877
  ws.on('CB:chatstate', handlePresenceUpdate);
867
878
  ws.on('CB:ib,,dirty', async (node) => {
868
- const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
879
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
869
880
  const type = attrs.type;
870
881
  switch (type) {
871
882
  case 'account_sync':
@@ -887,37 +898,62 @@ const makeChatsSocket = (config) => {
887
898
  }
888
899
  });
889
900
  ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
890
- var _a;
891
901
  if (connection === 'open') {
892
902
  if (fireInitQueries) {
893
- executeInitQueries()
894
- .catch(error => onUnexpectedError(error, 'init queries'));
903
+ executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
895
904
  }
896
- sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
897
- .catch(error => onUnexpectedError(error, 'presence update requests'));
905
+ sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
906
+ }
907
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
908
+ return;
909
+ }
910
+ syncState = SyncState.AwaitingInitialSync;
911
+ logger.info('Connection is now AwaitingInitialSync, buffering events');
912
+ ev.buffer();
913
+ const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.create({
914
+ syncType: proto.HistorySync.HistorySyncType.RECENT
915
+ }));
916
+ if (!willSyncHistory) {
917
+ logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
918
+ syncState = SyncState.Online;
919
+ setTimeout(() => ev.flush(), 0);
920
+ return;
921
+ }
922
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
923
+ if (awaitingSyncTimeout) {
924
+ clearTimeout(awaitingSyncTimeout);
925
+ }
926
+ awaitingSyncTimeout = setTimeout(() => {
927
+ if (syncState === SyncState.AwaitingInitialSync) {
928
+ // TODO: investigate
929
+ logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
930
+ syncState = SyncState.Online;
931
+ ev.flush();
932
+ }
933
+ }, 20000);
934
+ });
935
+ ev.on('lid-mapping.update', async ({ lid, pn }) => {
936
+ try {
937
+ await signalRepository.lidMapping.storeLIDPNMappings([{ lid, pn }]);
898
938
  }
899
- if (receivedPendingNotifications && // if we don't have the app state key
900
- // we keep buffering events until we finally have
901
- // the key and can sync the messages
902
- // todo scrutinize
903
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
904
- ev.buffer();
905
- needToFlushWithAppStateSync = true;
939
+ catch (error) {
940
+ logger.warn({ lid, pn, error }, 'Failed to store LID-PN mapping');
906
941
  }
907
942
  });
908
943
  return {
909
944
  ...sock,
910
- interactiveQuery,
945
+ createCallLink,
911
946
  getBotListV2,
912
- processingMutex,
947
+ messageMutex,
948
+ receiptMutex,
949
+ appStatePatchMutex,
950
+ notificationMutex,
913
951
  fetchPrivacySettings,
914
952
  upsertMessage,
915
953
  appPatch,
916
- fetchUserLid,
917
954
  sendPresenceUpdate,
918
955
  presenceSubscribe,
919
956
  profilePictureUrl,
920
- onWhatsApp,
921
957
  fetchBlocklist,
922
958
  fetchStatus,
923
959
  fetchDisappearingDuration,
@@ -926,6 +962,7 @@ const makeChatsSocket = (config) => {
926
962
  updateProfileStatus,
927
963
  updateProfileName,
928
964
  updateBlockStatus,
965
+ updateDisableLinkPreviewsPrivacy,
929
966
  updateCallPrivacy,
930
967
  updateMessagesPrivacy,
931
968
  updateLastSeenPrivacy,
@@ -939,12 +976,16 @@ const makeChatsSocket = (config) => {
939
976
  resyncAppState,
940
977
  chatModify,
941
978
  cleanDirtyBits,
979
+ addOrEditContact,
980
+ removeContact,
942
981
  addLabel,
943
982
  addChatLabel,
944
983
  removeChatLabel,
945
984
  addMessageLabel,
946
985
  removeMessageLabel,
947
- star
986
+ star,
987
+ addOrEditQuickReply,
988
+ removeQuickReply
948
989
  };
949
990
  };
950
- exports.makeChatsSocket = makeChatsSocket;
991
+ //# sourceMappingURL=chats.js.map