@neelegirl/baileys 1.5.3 → 1.5.4

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