@modzneverdie/baileys 17.1.2 → 17.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 (427) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +6035 -0
  4. package/WAProto/fix-imports.js +81 -0
  5. package/WAProto/index.d.ts +2 -0
  6. package/WAProto/index.js +59469 -96804
  7. package/lib/Defaults/index.d.ts +29 -8
  8. package/lib/Defaults/index.d.ts.map +1 -0
  9. package/lib/Defaults/index.js +134 -141
  10. package/lib/Defaults/index.js.map +1 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
  12. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  13. package/lib/Signal/Group/ciphertext-message.js +2 -5
  14. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts +4 -3
  16. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  17. package/lib/Signal/Group/group-session-builder.js +7 -41
  18. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  19. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  20. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  21. package/lib/Signal/Group/group_cipher.js +37 -51
  22. package/lib/Signal/Group/group_cipher.js.map +1 -0
  23. package/lib/Signal/Group/index.d.ts +12 -11
  24. package/lib/Signal/Group/index.d.ts.map +1 -0
  25. package/lib/Signal/Group/index.js +12 -57
  26. package/lib/Signal/Group/index.js.map +1 -0
  27. package/lib/Signal/Group/keyhelper.d.ts +2 -1
  28. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  29. package/lib/Signal/Group/keyhelper.js +7 -44
  30. package/lib/Signal/Group/keyhelper.js.map +1 -0
  31. package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
  32. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  33. package/lib/Signal/Group/sender-chain-key.js +7 -15
  34. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  35. package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
  38. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  39. package/lib/Signal/Group/sender-key-message.d.ts +2 -1
  40. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  41. package/lib/Signal/Group/sender-key-message.js +9 -12
  42. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  43. package/lib/Signal/Group/sender-key-name.d.ts +1 -0
  44. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  45. package/lib/Signal/Group/sender-key-name.js +2 -5
  46. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  47. package/lib/Signal/Group/sender-key-record.d.ts +3 -2
  48. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  49. package/lib/Signal/Group/sender-key-record.js +9 -21
  50. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  51. package/lib/Signal/Group/sender-key-state.d.ts +7 -6
  52. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  53. package/lib/Signal/Group/sender-key-state.js +27 -42
  54. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  55. package/lib/Signal/Group/sender-message-key.d.ts +1 -0
  56. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  57. package/lib/Signal/Group/sender-message-key.js +4 -7
  58. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  59. package/lib/Signal/libsignal.d.ts +5 -3
  60. package/lib/Signal/libsignal.d.ts.map +1 -0
  61. package/lib/Signal/libsignal.js +319 -90
  62. package/lib/Signal/libsignal.js.map +1 -0
  63. package/lib/Signal/lid-mapping.d.ts +19 -0
  64. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  65. package/lib/Signal/lid-mapping.js +271 -0
  66. package/lib/Signal/lid-mapping.js.map +1 -0
  67. package/lib/Socket/Client/index.d.ts +3 -3
  68. package/lib/Socket/Client/index.d.ts.map +1 -0
  69. package/lib/Socket/Client/index.js +3 -19
  70. package/lib/Socket/Client/index.js.map +1 -0
  71. package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +4 -5
  72. package/lib/Socket/Client/types.d.ts.map +1 -0
  73. package/lib/Socket/Client/types.js +11 -0
  74. package/lib/Socket/Client/types.js.map +1 -0
  75. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +3 -2
  76. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  77. package/lib/Socket/Client/websocket.js +54 -0
  78. package/lib/Socket/Client/websocket.js.map +1 -0
  79. package/lib/Socket/business.d.ts +533 -168
  80. package/lib/Socket/business.d.ts.map +1 -0
  81. package/lib/Socket/business.js +405 -243
  82. package/lib/Socket/business.js.map +1 -0
  83. package/lib/Socket/chats.d.ts +84 -240
  84. package/lib/Socket/chats.d.ts.map +1 -0
  85. package/lib/Socket/chats.js +406 -385
  86. package/lib/Socket/chats.js.map +1 -0
  87. package/lib/Socket/communities.d.ts +645 -0
  88. package/lib/Socket/communities.d.ts.map +1 -0
  89. package/lib/Socket/communities.js +431 -0
  90. package/lib/Socket/communities.js.map +1 -0
  91. package/lib/Socket/dugong.d.ts +125 -249
  92. package/lib/Socket/dugong.d.ts.map +1 -0
  93. package/lib/Socket/dugong.js +749 -465
  94. package/lib/Socket/dugong.js.map +1 -0
  95. package/lib/Socket/groups.d.ts +93 -58
  96. package/lib/Socket/groups.d.ts.map +1 -0
  97. package/lib/Socket/groups.js +105 -95
  98. package/lib/Socket/groups.js.map +1 -0
  99. package/lib/Socket/index.d.ts +632 -169
  100. package/lib/Socket/index.d.ts.map +1 -0
  101. package/lib/Socket/index.js +15 -11
  102. package/lib/Socket/index.js.map +1 -0
  103. package/lib/Socket/messages-recv.d.ts +162 -85
  104. package/lib/Socket/messages-recv.d.ts.map +1 -0
  105. package/lib/Socket/messages-recv.js +806 -608
  106. package/lib/Socket/messages-recv.js.map +1 -0
  107. package/lib/Socket/messages-send.d.ts +576 -146
  108. package/lib/Socket/messages-send.d.ts.map +1 -0
  109. package/lib/Socket/messages-send.js +1563 -861
  110. package/lib/Socket/messages-send.js.map +1 -0
  111. package/lib/Socket/mex.d.ts +3 -0
  112. package/lib/Socket/mex.d.ts.map +1 -0
  113. package/lib/Socket/mex.js +48 -0
  114. package/lib/Socket/mex.js.map +1 -0
  115. package/lib/Socket/newsletter.d.ts +129 -86
  116. package/lib/Socket/newsletter.d.ts.map +1 -0
  117. package/lib/Socket/newsletter.js +438 -297
  118. package/lib/Socket/newsletter.js.map +1 -0
  119. package/lib/Socket/socket.d.ts +31 -19
  120. package/lib/Socket/socket.d.ts.map +1 -0
  121. package/lib/Socket/socket.js +512 -241
  122. package/lib/Socket/socket.js.map +1 -0
  123. package/lib/Types/Auth.d.ts +18 -12
  124. package/lib/Types/Auth.d.ts.map +1 -0
  125. package/lib/Types/Auth.js +2 -2
  126. package/lib/Types/Auth.js.map +1 -0
  127. package/lib/Types/Bussines.d.ts +37 -0
  128. package/lib/Types/Bussines.d.ts.map +1 -0
  129. package/lib/Types/Bussines.js +2 -0
  130. package/lib/Types/Bussines.js.map +1 -0
  131. package/lib/Types/Call.d.ts +3 -1
  132. package/lib/Types/Call.d.ts.map +1 -0
  133. package/lib/Types/Call.js +2 -2
  134. package/lib/Types/Call.js.map +1 -0
  135. package/lib/Types/Chat.d.ts +34 -13
  136. package/lib/Types/Chat.d.ts.map +1 -0
  137. package/lib/Types/Chat.js +8 -4
  138. package/lib/Types/Chat.js.map +1 -0
  139. package/lib/Types/Contact.d.ts +6 -1
  140. package/lib/Types/Contact.d.ts.map +1 -0
  141. package/lib/Types/Contact.js +2 -2
  142. package/lib/Types/Contact.js.map +1 -0
  143. package/lib/Types/Events.d.ts +97 -17
  144. package/lib/Types/Events.d.ts.map +1 -0
  145. package/lib/Types/Events.js +2 -2
  146. package/lib/Types/Events.js.map +1 -0
  147. package/lib/Types/GroupMetadata.d.ts +18 -5
  148. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  149. package/lib/Types/GroupMetadata.js +2 -2
  150. package/lib/Types/GroupMetadata.js.map +1 -0
  151. package/lib/Types/Label.d.ts +12 -0
  152. package/lib/Types/Label.d.ts.map +1 -0
  153. package/lib/Types/Label.js +3 -5
  154. package/lib/Types/Label.js.map +1 -0
  155. package/lib/Types/LabelAssociation.d.ts +1 -0
  156. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  157. package/lib/Types/LabelAssociation.js +3 -5
  158. package/lib/Types/LabelAssociation.js.map +1 -0
  159. package/lib/Types/Message.d.ts +355 -206
  160. package/lib/Types/Message.d.ts.map +1 -0
  161. package/lib/Types/Message.js +11 -9
  162. package/lib/Types/Message.js.map +1 -0
  163. package/lib/Types/Newsletter.d.ts +130 -98
  164. package/lib/Types/Newsletter.d.ts.map +1 -0
  165. package/lib/Types/Newsletter.js +31 -38
  166. package/lib/Types/Newsletter.js.map +1 -0
  167. package/lib/Types/Product.d.ts +2 -1
  168. package/lib/Types/Product.d.ts.map +1 -0
  169. package/lib/Types/Product.js +2 -2
  170. package/lib/Types/Product.js.map +1 -0
  171. package/lib/Types/Signal.d.ts +20 -1
  172. package/lib/Types/Signal.d.ts.map +1 -0
  173. package/lib/Types/Signal.js +2 -2
  174. package/lib/Types/Signal.js.map +1 -0
  175. package/lib/Types/Socket.d.ts +152 -105
  176. package/lib/Types/Socket.d.ts.map +1 -0
  177. package/lib/Types/Socket.js +3 -2
  178. package/lib/Types/Socket.js.map +1 -0
  179. package/lib/Types/State.d.ts +14 -2
  180. package/lib/Types/State.d.ts.map +1 -0
  181. package/lib/Types/State.js +13 -2
  182. package/lib/Types/State.js.map +1 -0
  183. package/lib/Types/USync.d.ts +3 -2
  184. package/lib/Types/USync.d.ts.map +1 -0
  185. package/lib/Types/USync.js +2 -2
  186. package/lib/Types/USync.js.map +1 -0
  187. package/lib/Types/index.d.ts +54 -45
  188. package/lib/Types/index.d.ts.map +1 -0
  189. package/lib/Types/index.js +32 -41
  190. package/lib/Types/index.js.map +1 -0
  191. package/lib/Utils/auth-utils.d.ts +7 -6
  192. package/lib/Utils/auth-utils.d.ts.map +1 -0
  193. package/lib/Utils/auth-utils.js +228 -144
  194. package/lib/Utils/auth-utils.js.map +1 -0
  195. package/lib/Utils/browser-utils.d.ts +4 -0
  196. package/lib/Utils/browser-utils.d.ts.map +1 -0
  197. package/lib/Utils/browser-utils.js +28 -0
  198. package/lib/Utils/browser-utils.js.map +1 -0
  199. package/lib/Utils/business.d.ts +3 -2
  200. package/lib/Utils/business.d.ts.map +1 -0
  201. package/lib/Utils/business.js +66 -69
  202. package/lib/Utils/business.js.map +1 -0
  203. package/lib/Utils/chat-utils.d.ts +19 -20
  204. package/lib/Utils/chat-utils.d.ts.map +1 -0
  205. package/lib/Utils/chat-utils.js +331 -248
  206. package/lib/Utils/chat-utils.js.map +1 -0
  207. package/lib/Utils/crypto.d.ts +10 -14
  208. package/lib/Utils/crypto.d.ts.map +1 -0
  209. package/lib/Utils/crypto.js +57 -90
  210. package/lib/Utils/crypto.js.map +1 -0
  211. package/lib/Utils/decode-wa-message.d.ts +37 -8
  212. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  213. package/lib/Utils/decode-wa-message.js +169 -84
  214. package/lib/Utils/decode-wa-message.js.map +1 -0
  215. package/lib/Utils/event-buffer.d.ts +7 -8
  216. package/lib/Utils/event-buffer.d.ts.map +1 -0
  217. package/lib/Utils/event-buffer.js +138 -78
  218. package/lib/Utils/event-buffer.js.map +1 -0
  219. package/lib/Utils/generics.d.ts +26 -27
  220. package/lib/Utils/generics.d.ts.map +1 -0
  221. package/lib/Utils/generics.js +170 -209
  222. package/lib/Utils/generics.js.map +1 -0
  223. package/lib/Utils/history.d.ts +16 -9
  224. package/lib/Utils/history.d.ts.map +1 -0
  225. package/lib/Utils/history.js +83 -48
  226. package/lib/Utils/history.js.map +1 -0
  227. package/lib/Utils/identity-change-handler.d.ts +37 -0
  228. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  229. package/lib/Utils/identity-change-handler.js +49 -0
  230. package/lib/Utils/identity-change-handler.js.map +1 -0
  231. package/lib/Utils/index.d.ts +23 -17
  232. package/lib/Utils/index.d.ts.map +1 -0
  233. package/lib/Utils/index.js +23 -33
  234. package/lib/Utils/index.js.map +1 -0
  235. package/lib/Utils/link-preview.d.ts +5 -5
  236. package/lib/Utils/link-preview.d.ts.map +1 -0
  237. package/lib/Utils/link-preview.js +14 -22
  238. package/lib/Utils/link-preview.js.map +1 -0
  239. package/lib/Utils/logger.d.ts +12 -3
  240. package/lib/Utils/logger.d.ts.map +1 -0
  241. package/lib/Utils/logger.js +3 -7
  242. package/lib/Utils/logger.js.map +1 -0
  243. package/lib/Utils/lt-hash.d.ts +8 -12
  244. package/lib/Utils/lt-hash.d.ts.map +1 -0
  245. package/lib/Utils/lt-hash.js +3 -46
  246. package/lib/Utils/lt-hash.js.map +1 -0
  247. package/lib/Utils/make-mutex.d.ts +4 -2
  248. package/lib/Utils/make-mutex.d.ts.map +1 -0
  249. package/lib/Utils/make-mutex.js +24 -34
  250. package/lib/Utils/make-mutex.js.map +1 -0
  251. package/lib/Utils/message-retry-manager.d.ts +110 -0
  252. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  253. package/lib/Utils/message-retry-manager.js +225 -0
  254. package/lib/Utils/message-retry-manager.js.map +1 -0
  255. package/lib/Utils/messages-media.d.ts +56 -42
  256. package/lib/Utils/messages-media.d.ts.map +1 -0
  257. package/lib/Utils/messages-media.js +411 -448
  258. package/lib/Utils/messages-media.js.map +1 -0
  259. package/lib/Utils/messages.d.ts +32 -18
  260. package/lib/Utils/messages.d.ts.map +1 -0
  261. package/lib/Utils/messages.js +1132 -710
  262. package/lib/Utils/messages.js.map +1 -0
  263. package/lib/Utils/noise-handler.d.ts +12 -13
  264. package/lib/Utils/noise-handler.d.ts.map +1 -0
  265. package/lib/Utils/noise-handler.js +145 -99
  266. package/lib/Utils/noise-handler.js.map +1 -0
  267. package/lib/Utils/offline-node-processor.d.ts +17 -0
  268. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  269. package/lib/Utils/offline-node-processor.js +40 -0
  270. package/lib/Utils/offline-node-processor.js.map +1 -0
  271. package/lib/Utils/pre-key-manager.d.ts +28 -0
  272. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  273. package/lib/Utils/pre-key-manager.js +106 -0
  274. package/lib/Utils/pre-key-manager.js.map +1 -0
  275. package/lib/Utils/process-message.d.ts +31 -12
  276. package/lib/Utils/process-message.d.ts.map +1 -0
  277. package/lib/Utils/process-message.js +357 -150
  278. package/lib/Utils/process-message.js.map +1 -0
  279. package/lib/Utils/reporting-utils.d.ts +11 -0
  280. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  281. package/lib/Utils/reporting-utils.js +258 -0
  282. package/lib/Utils/reporting-utils.js.map +1 -0
  283. package/lib/Utils/rich-messages.d.ts +277 -0
  284. package/lib/Utils/rich-messages.d.ts.map +1 -0
  285. package/lib/Utils/rich-messages.js +1144 -0
  286. package/lib/Utils/rich-messages.js.map +1 -0
  287. package/lib/Utils/signal.d.ts +7 -5
  288. package/lib/Utils/signal.d.ts.map +1 -0
  289. package/lib/Utils/signal.js +78 -72
  290. package/lib/Utils/signal.js.map +1 -0
  291. package/lib/Utils/stanza-ack.d.ts +11 -0
  292. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  293. package/lib/Utils/stanza-ack.js +38 -0
  294. package/lib/Utils/stanza-ack.js.map +1 -0
  295. package/lib/Utils/sticker-pack.d.ts +10 -0
  296. package/lib/Utils/sticker-pack.js +111 -0
  297. package/lib/Utils/sync-action-utils.d.ts +19 -0
  298. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  299. package/lib/Utils/sync-action-utils.js +48 -0
  300. package/lib/Utils/sync-action-utils.js.map +1 -0
  301. package/lib/Utils/tc-token-utils.d.ts +12 -0
  302. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  303. package/lib/Utils/tc-token-utils.js +18 -0
  304. package/lib/Utils/tc-token-utils.js.map +1 -0
  305. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
  306. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  307. package/lib/Utils/use-multi-file-auth-state.js +29 -27
  308. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  309. package/lib/Utils/validate-connection.d.ts +7 -7
  310. package/lib/Utils/validate-connection.d.ts.map +1 -0
  311. package/lib/Utils/validate-connection.js +70 -99
  312. package/lib/Utils/validate-connection.js.map +1 -0
  313. package/lib/WABinary/constants.d.ts +25 -27
  314. package/lib/WABinary/constants.d.ts.map +1 -0
  315. package/lib/WABinary/constants.js +1281 -20
  316. package/lib/WABinary/constants.js.map +1 -0
  317. package/lib/WABinary/decode.d.ts +5 -5
  318. package/lib/WABinary/decode.d.ts.map +1 -0
  319. package/lib/WABinary/decode.js +52 -42
  320. package/lib/WABinary/decode.js.map +1 -0
  321. package/lib/WABinary/encode.d.ts +3 -3
  322. package/lib/WABinary/encode.d.ts.map +1 -0
  323. package/lib/WABinary/encode.js +110 -155
  324. package/lib/WABinary/encode.js.map +1 -0
  325. package/lib/WABinary/generic-utils.d.ts +8 -8
  326. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  327. package/lib/WABinary/generic-utils.js +142 -149
  328. package/lib/WABinary/generic-utils.js.map +1 -0
  329. package/lib/WABinary/index.d.ts +6 -5
  330. package/lib/WABinary/index.d.ts.map +1 -0
  331. package/lib/WABinary/index.js +6 -21
  332. package/lib/WABinary/index.js.map +1 -0
  333. package/lib/WABinary/jid-utils.d.ts +25 -8
  334. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  335. package/lib/WABinary/jid-utils.js +74 -40
  336. package/lib/WABinary/jid-utils.js.map +1 -0
  337. package/lib/WABinary/types.d.ts +2 -1
  338. package/lib/WABinary/types.d.ts.map +1 -0
  339. package/lib/WABinary/types.js +2 -2
  340. package/lib/WABinary/types.js.map +1 -0
  341. package/lib/WAM/BinaryInfo.d.ts +3 -11
  342. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  343. package/lib/WAM/BinaryInfo.js +2 -5
  344. package/lib/WAM/BinaryInfo.js.map +1 -0
  345. package/lib/WAM/constants.d.ts +5 -3
  346. package/lib/WAM/constants.d.ts.map +1 -0
  347. package/lib/WAM/constants.js +19071 -11568
  348. package/lib/WAM/constants.js.map +1 -0
  349. package/lib/WAM/encode.d.ts +2 -2
  350. package/lib/WAM/encode.d.ts.map +1 -0
  351. package/lib/WAM/encode.js +17 -22
  352. package/lib/WAM/encode.js.map +1 -0
  353. package/lib/WAM/index.d.ts +4 -3
  354. package/lib/WAM/index.d.ts.map +1 -0
  355. package/lib/WAM/index.js +4 -19
  356. package/lib/WAM/index.js.map +1 -0
  357. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  358. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  359. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
  360. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  361. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  362. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  363. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  364. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  365. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  366. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  367. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
  368. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  369. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  370. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  371. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  372. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  373. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  374. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  375. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  376. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  377. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
  378. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  379. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
  380. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  381. package/lib/WAUSync/Protocols/index.d.ts +5 -4
  382. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  383. package/lib/WAUSync/Protocols/index.js +5 -20
  384. package/lib/WAUSync/Protocols/index.js.map +1 -0
  385. package/lib/WAUSync/USyncQuery.d.ts +5 -4
  386. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  387. package/lib/WAUSync/USyncQuery.js +40 -35
  388. package/lib/WAUSync/USyncQuery.js.map +1 -0
  389. package/lib/WAUSync/USyncUser.d.ts +6 -5
  390. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  391. package/lib/WAUSync/USyncUser.js +2 -5
  392. package/lib/WAUSync/USyncUser.js.map +1 -0
  393. package/lib/WAUSync/index.d.ts +4 -3
  394. package/lib/WAUSync/index.d.ts.map +1 -0
  395. package/lib/WAUSync/index.js +4 -19
  396. package/lib/WAUSync/index.js.map +1 -0
  397. package/lib/index.d.ts +10 -9
  398. package/lib/index.d.ts.map +1 -0
  399. package/lib/index.js +12 -33
  400. package/lib/index.js.map +1 -0
  401. package/package.json +64 -105
  402. package/README.md +0 -364
  403. package/engine-requirements.js +0 -10
  404. package/lib/Defaults/baileys-version.json +0 -3
  405. package/lib/Defaults/phonenumber-mcc.json +0 -223
  406. package/lib/Signal/Group/queue-job.d.ts +0 -1
  407. package/lib/Signal/Group/queue-job.js +0 -57
  408. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  409. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  410. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  411. package/lib/Socket/Client/web-socket-client.js +0 -62
  412. package/lib/Socket/registration.d.ts +0 -267
  413. package/lib/Socket/registration.js +0 -166
  414. package/lib/Socket/usync.d.ts +0 -36
  415. package/lib/Socket/usync.js +0 -70
  416. package/lib/Store/index.d.ts +0 -3
  417. package/lib/Store/index.js +0 -10
  418. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  419. package/lib/Store/make-cache-manager-store.js +0 -83
  420. package/lib/Store/make-in-memory-store.d.ts +0 -118
  421. package/lib/Store/make-in-memory-store.js +0 -427
  422. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  423. package/lib/Store/make-ordered-dictionary.js +0 -81
  424. package/lib/Store/object-repository.d.ts +0 -10
  425. package/lib/Store/object-repository.js +0 -27
  426. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  427. package/lib/Utils/baileys-event-stream.js +0 -63
@@ -1,10 +0,0 @@
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.makeCacheManagerAuthState = exports.makeInMemoryStore = void 0;
7
- const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
8
- exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
9
- const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
10
- exports.makeInMemoryStore = make_in_memory_store_1.default;
@@ -1,13 +0,0 @@
1
- import { AuthenticationCreds } from '../Types';
2
- declare const makeCacheManagerAuthState: (store: Storage, sessionKey: string) => Promise<{
3
- clearState: () => Promise<void>;
4
- saveCreds: () => Promise<void>;
5
- state: {
6
- creds: AuthenticationCreds;
7
- keys: {
8
- get: (type: string, ids: string[]) => Promise<{}>;
9
- set: (data: any) => Promise<void>;
10
- };
11
- };
12
- }>;
13
- export default makeCacheManagerAuthState;
@@ -1,83 +0,0 @@
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
- const cache_manager_1 = require("cache-manager");
7
- const WAProto_1 = require("../../WAProto");
8
- const Utils_1 = require("../Utils");
9
- const logger_1 = __importDefault(require("../Utils/logger"));
10
- const makeCacheManagerAuthState = async (store, sessionKey) => {
11
- const defaultKey = (file) => `${sessionKey}:${file}`;
12
- const databaseConn = await (0, cache_manager_1.caching)(store);
13
- const writeData = async (file, data) => {
14
- let ttl = undefined;
15
- if (file === 'creds') {
16
- ttl = 63115200; // 2 years
17
- }
18
- await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl);
19
- };
20
- const readData = async (file) => {
21
- try {
22
- const data = await databaseConn.get(defaultKey(file));
23
- if (data) {
24
- return JSON.parse(data, Utils_1.BufferJSON.reviver);
25
- }
26
- return null;
27
- }
28
- catch (error) {
29
- logger_1.default.error(error);
30
- return null;
31
- }
32
- };
33
- const removeData = async (file) => {
34
- try {
35
- return await databaseConn.del(defaultKey(file));
36
- }
37
- catch (_a) {
38
- logger_1.default.error(`Error removing ${file} from session ${sessionKey}`);
39
- }
40
- };
41
- const clearState = async () => {
42
- try {
43
- const result = await databaseConn.store.keys(`${sessionKey}*`);
44
- await Promise.all(result.map(async (key) => await databaseConn.del(key)));
45
- }
46
- catch (err) {
47
- }
48
- };
49
- const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)();
50
- return {
51
- clearState,
52
- saveCreds: () => writeData('creds', creds),
53
- state: {
54
- creds,
55
- keys: {
56
- get: async (type, ids) => {
57
- const data = {};
58
- await Promise.all(ids.map(async (id) => {
59
- let value = await readData(`${type}-${id}`);
60
- if (type === 'app-state-sync-key' && value) {
61
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
62
- }
63
- data[id] = value;
64
- }));
65
- return data;
66
- },
67
- set: async (data) => {
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- const tasks = [];
70
- for (const category in data) {
71
- for (const id in data[category]) {
72
- const value = data[category][id];
73
- const key = `${category}-${id}`;
74
- tasks.push(value ? writeData(key, value) : removeData(key));
75
- }
76
- }
77
- await Promise.all(tasks);
78
- },
79
- }
80
- }
81
- };
82
- };
83
- exports.default = makeCacheManagerAuthState;
@@ -1,118 +0,0 @@
1
- import type KeyedDB from '@adiwajshing/keyed-db';
2
- import type { Comparable } from '@adiwajshing/keyed-db/lib/Types';
3
- import type { Logger } from 'pino';
4
- import { proto } from '../../WAProto';
5
- import type makeMDSocket from '../Socket';
6
- import type { BaileysEventEmitter, Chat, ConnectionState, Contact, GroupMetadata, PresenceData, WAMessage, WAMessageCursor, WAMessageKey } from '../Types';
7
- import { Label } from '../Types/Label';
8
- import { LabelAssociation } from '../Types/LabelAssociation';
9
- import { ObjectRepository } from './object-repository';
10
- type WASocket = ReturnType<typeof makeMDSocket>;
11
- export declare const waChatKey: (pin: boolean) => {
12
- key: (c: Chat) => string;
13
- compare: (k1: string, k2: string) => number;
14
- };
15
- export declare const waMessageID: (m: WAMessage) => string;
16
- export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>;
17
- export type BaileysInMemoryStoreConfig = {
18
- chatKey?: Comparable<Chat, string>;
19
- labelAssociationKey?: Comparable<LabelAssociation, string>;
20
- logger?: Logger;
21
- socket?: WASocket;
22
- };
23
- declare const _default: (config: BaileysInMemoryStoreConfig) => {
24
- chats: KeyedDB<Chat, string>;
25
- contacts: {
26
- [_: string]: Contact;
27
- };
28
- messages: {
29
- [_: string]: {
30
- array: proto.IWebMessageInfo[];
31
- get: (id: string) => proto.IWebMessageInfo | undefined;
32
- upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
33
- update: (item: proto.IWebMessageInfo) => boolean;
34
- remove: (item: proto.IWebMessageInfo) => boolean;
35
- updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
36
- clear: () => void;
37
- filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
38
- toJSON: () => proto.IWebMessageInfo[];
39
- fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
40
- };
41
- };
42
- groupMetadata: {
43
- [_: string]: GroupMetadata;
44
- };
45
- state: ConnectionState;
46
- presences: {
47
- [id: string]: {
48
- [participant: string]: PresenceData;
49
- };
50
- };
51
- labels: ObjectRepository<Label>;
52
- labelAssociations: KeyedDB<LabelAssociation, string>;
53
- bind: (ev: BaileysEventEmitter) => void;
54
- /** loads messages from the store, if not found -- uses the legacy connection */
55
- loadMessages: (jid: string, count: number, cursor: WAMessageCursor) => Promise<proto.IWebMessageInfo[]>;
56
- /**
57
- * Get all available labels for profile
58
- *
59
- * Keep in mind that the list is formed from predefined tags and tags
60
- * that were "caught" during their editing.
61
- */
62
- getLabels: () => ObjectRepository<Label>;
63
- /**
64
- * Get labels for chat
65
- *
66
- * @returns Label IDs
67
- **/
68
- getChatLabels: (chatId: string) => LabelAssociation[];
69
- /**
70
- * Get labels for message
71
- *
72
- * @returns Label IDs
73
- **/
74
- getMessageLabels: (messageId: string) => string[];
75
- loadMessage: (jid: string, id: string) => Promise<proto.IWebMessageInfo | undefined>;
76
- mostRecentMessage: (jid: string) => Promise<proto.IWebMessageInfo>;
77
- fetchImageUrl: (jid: string, sock: WASocket | undefined) => Promise<string | null | undefined>;
78
- fetchGroupMetadata: (jid: string, sock: WASocket | undefined) => Promise<GroupMetadata>;
79
- fetchMessageReceipts: ({ remoteJid, id }: WAMessageKey) => Promise<proto.IUserReceipt[] | null | undefined>;
80
- toJSON: () => {
81
- chats: KeyedDB<Chat, string>;
82
- contacts: {
83
- [_: string]: Contact;
84
- };
85
- messages: {
86
- [_: string]: {
87
- array: proto.IWebMessageInfo[];
88
- get: (id: string) => proto.IWebMessageInfo | undefined;
89
- upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
90
- update: (item: proto.IWebMessageInfo) => boolean;
91
- remove: (item: proto.IWebMessageInfo) => boolean;
92
- updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
93
- clear: () => void;
94
- filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
95
- toJSON: () => proto.IWebMessageInfo[];
96
- fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
97
- };
98
- };
99
- labels: ObjectRepository<Label>;
100
- labelAssociations: KeyedDB<LabelAssociation, string>;
101
- };
102
- fromJSON: (json: {
103
- chats: Chat[];
104
- contacts: {
105
- [id: string]: Contact;
106
- };
107
- messages: {
108
- [id: string]: proto.IWebMessageInfo[];
109
- };
110
- labels: {
111
- [labelId: string]: Label;
112
- };
113
- labelAssociations: LabelAssociation[];
114
- }) => void;
115
- writeToFile: (path: string) => void;
116
- readFromFile: (path: string) => void;
117
- };
118
- export default _default;
@@ -1,427 +0,0 @@
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.waLabelAssociationKey = exports.waMessageID = exports.waChatKey = void 0;
7
- const WAProto_1 = require("../../WAProto");
8
- const Defaults_1 = require("../Defaults");
9
- const LabelAssociation_1 = require("../Types/LabelAssociation");
10
- const Utils_1 = require("../Utils");
11
- const WABinary_1 = require("../WABinary");
12
- const make_ordered_dictionary_1 = __importDefault(require("./make-ordered-dictionary"));
13
- const object_repository_1 = require("./object-repository");
14
- const waChatKey = (pin) => ({
15
- key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
16
- compare: (k1, k2) => k2.localeCompare(k1)
17
- });
18
- exports.waChatKey = waChatKey;
19
- const waMessageID = (m) => m.key.id || '';
20
- exports.waMessageID = waMessageID;
21
- exports.waLabelAssociationKey = {
22
- key: (la) => (la.type === LabelAssociation_1.LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
23
- compare: (k1, k2) => k2.localeCompare(k1)
24
- };
25
- const makeMessagesDictionary = () => (0, make_ordered_dictionary_1.default)(exports.waMessageID);
26
- exports.default = (config) => {
27
- const socket = config.socket;
28
- const chatKey = config.chatKey || (0, exports.waChatKey)(true);
29
- const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
30
- const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
31
- const KeyedDB = require('@adiwajshing/keyed-db').default;
32
- const chats = new KeyedDB(chatKey, c => c.id);
33
- const messages = {};
34
- const contacts = {};
35
- const groupMetadata = {};
36
- const presences = {};
37
- const state = { connection: 'close' };
38
- const labels = new object_repository_1.ObjectRepository();
39
- const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
40
- const assertMessageList = (jid) => {
41
- if (!messages[jid]) {
42
- messages[jid] = makeMessagesDictionary();
43
- }
44
- return messages[jid];
45
- };
46
- const contactsUpsert = (newContacts) => {
47
- const oldContacts = new Set(Object.keys(contacts));
48
- for (const contact of newContacts) {
49
- oldContacts.delete(contact.id);
50
- contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
51
- }
52
- return oldContacts;
53
- };
54
- const labelsUpsert = (newLabels) => {
55
- for (const label of newLabels) {
56
- labels.upsertById(label.id, label);
57
- }
58
- };
59
- const getValidContacts = () => {
60
- for (const contact of Object.keys(contacts)) {
61
- if (contact.indexOf('@') < 0) {
62
- delete contacts[contact];
63
- }
64
- }
65
- return Object.keys(contacts);
66
- };
67
- /**
68
- * binds to a BaileysEventEmitter.
69
- * It listens to all events and constructs a state that you can query accurate data from.
70
- * Eg. can use the store to fetch chats, contacts, messages etc.
71
- * @param ev typically the event emitter from the socket connection
72
- */
73
- const bind = (ev) => {
74
- ev.on('connection.update', update => {
75
- Object.assign(state, update);
76
- });
77
- ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
78
- if (isLatest) {
79
- chats.clear();
80
- for (const id in messages) {
81
- delete messages[id];
82
- }
83
- }
84
- const chatsAdded = chats.insertIfAbsent(...newChats).length;
85
- logger.debug({ chatsAdded }, 'synced chats');
86
- const oldContacts = contactsUpsert(newContacts);
87
- if (isLatest) {
88
- for (const jid of oldContacts) {
89
- delete contacts[jid];
90
- }
91
- }
92
- logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
93
- for (const msg of newMessages) {
94
- const jid = msg.key.remoteJid;
95
- const list = assertMessageList(jid);
96
- list.upsert(msg, 'prepend');
97
- }
98
- logger.debug({ messages: newMessages.length }, 'synced messages');
99
- });
100
- ev.on('contacts.upsert', contacts => {
101
- contactsUpsert(contacts);
102
- });
103
- ev.on('contacts.update', async (updates) => {
104
- var _a;
105
- for (const update of updates) {
106
- let contact;
107
- if (contacts[update.id]) {
108
- contact = contacts[update.id];
109
- }
110
- else {
111
- const validContacts = getValidContacts();
112
- const contactHashes = validContacts.map((contactId) => {
113
- const { user } = (0, WABinary_1.jidDecode)(contactId);
114
- return [contactId, ((0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
115
- });
116
- contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
117
- }
118
- if (contact) {
119
- if (update.imgUrl === 'changed') {
120
- contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
121
- }
122
- else if (update.imgUrl === 'removed') {
123
- delete contact.imgUrl;
124
- }
125
- Object.assign(contacts[contact.id], contact);
126
- }
127
- else {
128
- logger.debug({ update }, 'got update for non-existant contact');
129
- }
130
- }
131
- });
132
- ev.on('chats.upsert', newChats => {
133
- chats.upsert(...newChats);
134
- });
135
- ev.on('chats.update', updates => {
136
- for (let update of updates) {
137
- const result = chats.update(update.id, chat => {
138
- if (update.unreadCount > 0) {
139
- update = { ...update };
140
- update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
141
- }
142
- Object.assign(chat, update);
143
- });
144
- if (!result) {
145
- logger.debug({ update }, 'got update for non-existant chat');
146
- }
147
- }
148
- });
149
- ev.on('labels.edit', (label) => {
150
- if (label.deleted) {
151
- return labels.deleteById(label.id);
152
- }
153
- // WhatsApp can store only up to 20 labels
154
- if (labels.count() < 20) {
155
- return labels.upsertById(label.id, label);
156
- }
157
- logger.error('Labels count exceed');
158
- });
159
- ev.on('labels.association', ({ type, association }) => {
160
- switch (type) {
161
- case 'add':
162
- labelAssociations.upsert(association);
163
- break;
164
- case 'remove':
165
- labelAssociations.delete(association);
166
- break;
167
- default:
168
- console.error(`unknown operation type [${type}]`);
169
- }
170
- });
171
- ev.on('presence.update', ({ id, presences: update }) => {
172
- presences[id] = presences[id] || {};
173
- Object.assign(presences[id], update);
174
- });
175
- ev.on('chats.delete', deletions => {
176
- for (const item of deletions) {
177
- if (chats.get(item)) {
178
- chats.deleteById(item);
179
- }
180
- }
181
- });
182
- ev.on('messages.upsert', ({ messages: newMessages, type }) => {
183
- switch (type) {
184
- case 'append':
185
- case 'notify':
186
- for (const msg of newMessages) {
187
- const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
188
- const list = assertMessageList(jid);
189
- list.upsert(msg, 'append');
190
- if (type === 'notify') {
191
- if (!chats.get(jid)) {
192
- ev.emit('chats.upsert', [
193
- {
194
- id: jid,
195
- conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
196
- unreadCount: 1
197
- }
198
- ]);
199
- }
200
- }
201
- }
202
- break;
203
- }
204
- });
205
- ev.on('messages.update', updates => {
206
- var _a;
207
- for (const { update, key } of updates) {
208
- const list = assertMessageList((0, WABinary_1.jidNormalizedUser)(key.remoteJid));
209
- if (update === null || update === void 0 ? void 0 : update.status) {
210
- const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
211
- if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
212
- logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
213
- delete update.status;
214
- logger.debug({ update }, 'new update object');
215
- }
216
- }
217
- const result = list.updateAssign(key.id, update);
218
- if (!result) {
219
- logger.debug({ update }, 'got update for non-existent message');
220
- }
221
- }
222
- });
223
- ev.on('messages.delete', item => {
224
- if ('all' in item) {
225
- const list = messages[item.jid];
226
- list === null || list === void 0 ? void 0 : list.clear();
227
- }
228
- else {
229
- const jid = item.keys[0].remoteJid;
230
- const list = messages[jid];
231
- if (list) {
232
- const idSet = new Set(item.keys.map(k => k.id));
233
- list.filter(m => !idSet.has(m.key.id));
234
- }
235
- }
236
- });
237
- ev.on('groups.update', updates => {
238
- for (const update of updates) {
239
- const id = update.id;
240
- if (groupMetadata[id]) {
241
- Object.assign(groupMetadata[id], update);
242
- }
243
- else {
244
- logger.debug({ update }, 'got update for non-existant group metadata');
245
- }
246
- }
247
- });
248
- ev.on('group-participants.update', ({ id, participants, action }) => {
249
- const metadata = groupMetadata[id];
250
- if (metadata) {
251
- switch (action) {
252
- case 'add':
253
- metadata.participants.push(...participants.map(id => ({ id, isAdmin: false, isSuperAdmin: false })));
254
- break;
255
- case 'demote':
256
- case 'promote':
257
- for (const participant of metadata.participants) {
258
- if (participants.includes(participant.id)) {
259
- participant.isAdmin = action === 'promote';
260
- }
261
- }
262
- break;
263
- case 'remove':
264
- metadata.participants = metadata.participants.filter(p => !participants.includes(p.id));
265
- break;
266
- }
267
- }
268
- });
269
- ev.on('message-receipt.update', updates => {
270
- for (const { key, receipt } of updates) {
271
- const obj = messages[key.remoteJid];
272
- const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
273
- if (msg) {
274
- (0, Utils_1.updateMessageWithReceipt)(msg, receipt);
275
- }
276
- }
277
- });
278
- ev.on('messages.reaction', (reactions) => {
279
- for (const { key, reaction } of reactions) {
280
- const obj = messages[key.remoteJid];
281
- const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
282
- if (msg) {
283
- (0, Utils_1.updateMessageWithReaction)(msg, reaction);
284
- }
285
- }
286
- });
287
- };
288
- const toJSON = () => ({
289
- chats,
290
- contacts,
291
- messages,
292
- labels,
293
- labelAssociations
294
- });
295
- const fromJSON = (json) => {
296
- chats.upsert(...json.chats);
297
- labelAssociations.upsert(...json.labelAssociations || []);
298
- contactsUpsert(Object.values(json.contacts));
299
- labelsUpsert(Object.values(json.labels || {}));
300
- for (const jid in json.messages) {
301
- const list = assertMessageList(jid);
302
- for (const msg of json.messages[jid]) {
303
- list.upsert(WAProto_1.proto.WebMessageInfo.fromObject(msg), 'append');
304
- }
305
- }
306
- };
307
- return {
308
- chats,
309
- contacts,
310
- messages,
311
- groupMetadata,
312
- state,
313
- presences,
314
- labels,
315
- labelAssociations,
316
- bind,
317
- /** loads messages from the store, if not found -- uses the legacy connection */
318
- loadMessages: async (jid, count, cursor) => {
319
- const list = assertMessageList(jid);
320
- const mode = !cursor || 'before' in cursor ? 'before' : 'after';
321
- const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
322
- const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
323
- let messages;
324
- if (list && mode === 'before' && (!cursorKey || cursorValue)) {
325
- if (cursorValue) {
326
- const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
327
- messages = list.array.slice(0, msgIdx);
328
- }
329
- else {
330
- messages = list.array;
331
- }
332
- const diff = count - messages.length;
333
- if (diff < 0) {
334
- messages = messages.slice(-count); // get the last X messages
335
- }
336
- }
337
- else {
338
- messages = [];
339
- }
340
- return messages;
341
- },
342
- /**
343
- * Get all available labels for profile
344
- *
345
- * Keep in mind that the list is formed from predefined tags and tags
346
- * that were "caught" during their editing.
347
- */
348
- getLabels: () => {
349
- return labels;
350
- },
351
- /**
352
- * Get labels for chat
353
- *
354
- * @returns Label IDs
355
- **/
356
- getChatLabels: (chatId) => {
357
- return labelAssociations.filter((la) => la.chatId === chatId).all();
358
- },
359
- /**
360
- * Get labels for message
361
- *
362
- * @returns Label IDs
363
- **/
364
- getMessageLabels: (messageId) => {
365
- const associations = labelAssociations
366
- .filter((la) => la.messageId === messageId)
367
- .all();
368
- return associations.map(({ labelId }) => labelId);
369
- },
370
- loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
371
- mostRecentMessage: async (jid) => {
372
- var _a;
373
- const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
374
- return message;
375
- },
376
- fetchImageUrl: async (jid, sock) => {
377
- const contact = contacts[jid];
378
- if (!contact) {
379
- return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
380
- }
381
- if (typeof contact.imgUrl === 'undefined') {
382
- contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
383
- }
384
- return contact.imgUrl;
385
- },
386
- fetchGroupMetadata: async (jid, sock) => {
387
- if (!groupMetadata[jid]) {
388
- const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
389
- if (metadata) {
390
- groupMetadata[jid] = metadata;
391
- }
392
- }
393
- return groupMetadata[jid];
394
- },
395
- // fetchBroadcastListInfo: async(jid: string, sock: WASocket | undefined) => {
396
- // if(!groupMetadata[jid]) {
397
- // const metadata = await sock?.getBroadcastListInfo(jid)
398
- // if(metadata) {
399
- // groupMetadata[jid] = metadata
400
- // }
401
- // }
402
- // return groupMetadata[jid]
403
- // },
404
- fetchMessageReceipts: async ({ remoteJid, id }) => {
405
- const list = messages[remoteJid];
406
- const msg = list === null || list === void 0 ? void 0 : list.get(id);
407
- return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
408
- },
409
- toJSON,
410
- fromJSON,
411
- writeToFile: (path) => {
412
- // require fs here so that in case "fs" is not available -- the app does not crash
413
- const { writeFileSync } = require('fs');
414
- writeFileSync(path, JSON.stringify(toJSON()));
415
- },
416
- readFromFile: (path) => {
417
- // require fs here so that in case "fs" is not available -- the app does not crash
418
- const { readFileSync, existsSync } = require('fs');
419
- if (existsSync(path)) {
420
- logger.debug({ path }, 'reading from file');
421
- const jsonStr = readFileSync(path, { encoding: 'utf-8' });
422
- const json = JSON.parse(jsonStr);
423
- fromJSON(json);
424
- }
425
- }
426
- };
427
- };
@@ -1,13 +0,0 @@
1
- declare function makeOrderedDictionary<T>(idGetter: (item: T) => string): {
2
- array: T[];
3
- get: (id: string) => T | undefined;
4
- upsert: (item: T, mode: 'append' | 'prepend') => void;
5
- update: (item: T) => boolean;
6
- remove: (item: T) => boolean;
7
- updateAssign: (id: string, update: Partial<T>) => boolean;
8
- clear: () => void;
9
- filter: (contain: (item: T) => boolean) => void;
10
- toJSON: () => T[];
11
- fromJSON: (newItems: T[]) => void;
12
- };
13
- export default makeOrderedDictionary;