@neelegirl/baileys 1.5.6 → 1.5.8

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 (421) hide show
  1. package/README.md +24 -27
  2. package/WAProto/WAProto.proto +665 -291
  3. package/WAProto/index.d.ts +48037 -2294
  4. package/WAProto/index.js +139804 -45203
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +64 -58
  7. package/lib/Defaults/index.js +96 -74
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
  10. package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
  11. package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
  12. package/lib/Signal/WASignalGroup/group.proto +42 -0
  13. package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
  14. package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
  15. package/lib/Signal/WASignalGroup/index.js +6 -0
  16. package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
  17. package/lib/Signal/WASignalGroup/protobufs.js +3 -0
  18. package/lib/Signal/WASignalGroup/queue_job.js +69 -0
  19. package/lib/Signal/WASignalGroup/readme.md +6 -0
  20. package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
  21. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
  22. package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
  23. package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
  24. package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
  25. package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
  26. package/lib/Signal/{Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
  27. package/lib/Signal/libsignal.d.ts +4 -5
  28. package/lib/Signal/libsignal.js +112 -292
  29. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  30. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  31. package/lib/Socket/Client/index.d.ts +2 -3
  32. package/lib/Socket/Client/index.js +22 -3
  33. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  34. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  35. package/lib/Socket/Client/types.d.ts +15 -15
  36. package/lib/Socket/Client/types.js +15 -8
  37. package/lib/Socket/Client/websocket.d.ts +12 -12
  38. package/lib/Socket/Client/websocket.js +36 -24
  39. package/lib/Socket/business.d.ts +177 -178
  40. package/lib/Socket/business.js +71 -179
  41. package/lib/Socket/chats.d.ts +93 -93
  42. package/lib/Socket/chats.js +625 -474
  43. package/lib/Socket/communities.d.ts +62 -83
  44. package/lib/Socket/communities.js +414 -412
  45. package/lib/Socket/groups.d.ts +112 -118
  46. package/lib/Socket/groups.js +171 -146
  47. package/lib/Socket/index.d.ts +182 -222
  48. package/lib/Socket/index.js +17 -12
  49. package/lib/Socket/messages-recv.d.ts +169 -165
  50. package/lib/Socket/messages-recv.js +1721 -1185
  51. package/lib/Socket/messages-send.d.ts +160 -161
  52. package/lib/Socket/messages-send.js +992 -642
  53. package/lib/Socket/mex.d.ts +0 -1
  54. package/lib/Socket/mex.js +9 -4
  55. package/lib/Socket/newsletter.d.ts +139 -139
  56. package/lib/Socket/newsletter.js +258 -153
  57. package/lib/Socket/registration.d.ts +266 -0
  58. package/lib/Socket/registration.js +166 -0
  59. package/lib/Socket/socket.d.ts +36 -42
  60. package/lib/Socket/socket.js +615 -533
  61. package/lib/Socket/usync.d.ts +37 -0
  62. package/lib/Socket/usync.js +83 -0
  63. package/lib/Store/index.d.ts +4 -0
  64. package/lib/Store/index.js +24 -0
  65. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  66. package/lib/Store/make-cache-manager-store.js +90 -0
  67. package/lib/Store/make-in-memory-store.d.ts +123 -0
  68. package/lib/Store/make-in-memory-store.js +429 -0
  69. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  70. package/lib/Store/make-ordered-dictionary.js +86 -0
  71. package/lib/Store/object-repository.d.ts +10 -0
  72. package/lib/Store/object-repository.js +31 -0
  73. package/lib/Types/Auth.d.ts +96 -87
  74. package/lib/Types/Auth.js +3 -2
  75. package/lib/Types/Call.d.ts +13 -13
  76. package/lib/Types/Call.js +3 -2
  77. package/lib/Types/Chat.d.ts +94 -79
  78. package/lib/Types/Chat.js +9 -8
  79. package/lib/Types/Contact.d.ts +9 -13
  80. package/lib/Types/Contact.js +3 -2
  81. package/lib/Types/Events.d.ts +179 -152
  82. package/lib/Types/Events.js +3 -2
  83. package/lib/Types/GroupMetadata.d.ts +48 -49
  84. package/lib/Types/GroupMetadata.js +3 -2
  85. package/lib/Types/Label.d.ts +14 -13
  86. package/lib/Types/Label.js +30 -24
  87. package/lib/Types/LabelAssociation.d.ts +20 -15
  88. package/lib/Types/LabelAssociation.js +12 -6
  89. package/lib/Types/Message.d.ts +404 -234
  90. package/lib/Types/Message.js +13 -11
  91. package/lib/Types/MexUpdates.d.ts +9 -0
  92. package/lib/Types/MexUpdates.js +18 -0
  93. package/lib/Types/Newsletter.d.ts +104 -130
  94. package/lib/Types/Newsletter.js +40 -31
  95. package/lib/Types/Product.d.ts +71 -58
  96. package/lib/Types/Product.js +3 -2
  97. package/lib/Types/Signal.d.ts +55 -63
  98. package/lib/Types/Signal.js +3 -2
  99. package/lib/Types/Socket.d.ts +66 -77
  100. package/lib/Types/Socket.js +3 -3
  101. package/lib/Types/State.d.ts +19 -17
  102. package/lib/Types/State.js +14 -13
  103. package/lib/Types/USync.d.ts +8 -8
  104. package/lib/Types/USync.js +3 -2
  105. package/lib/Types/index.d.ts +61 -47
  106. package/lib/Types/index.js +48 -26
  107. package/lib/Utils/auth-utils.d.ts +10 -8
  108. package/lib/Utils/auth-utils.js +154 -206
  109. package/lib/Utils/baileys-event-stream.d.ts +7 -6
  110. package/lib/Utils/baileys-event-stream.js +43 -29
  111. package/lib/Utils/business.d.ts +20 -14
  112. package/lib/Utils/business.js +134 -110
  113. package/lib/Utils/chat-utils.d.ts +69 -57
  114. package/lib/Utils/chat-utils.js +380 -362
  115. package/lib/Utils/check-npm-version.d.ts +15 -0
  116. package/lib/Utils/check-npm-version.js +52 -0
  117. package/lib/Utils/crypto.d.ts +45 -30
  118. package/lib/Utils/crypto.js +178 -141
  119. package/lib/Utils/decode-wa-message.d.ts +35 -42
  120. package/lib/Utils/decode-wa-message.js +150 -176
  121. package/lib/Utils/event-buffer.d.ts +17 -12
  122. package/lib/Utils/event-buffer.js +286 -269
  123. package/lib/Utils/generics.d.ts +99 -60
  124. package/lib/Utils/generics.js +481 -244
  125. package/lib/Utils/history.d.ts +22 -18
  126. package/lib/Utils/history.js +80 -54
  127. package/lib/Utils/index.d.ts +19 -20
  128. package/lib/Utils/index.js +41 -19
  129. package/lib/Utils/link-preview.d.ts +14 -12
  130. package/lib/Utils/link-preview.js +75 -40
  131. package/lib/Utils/logger.d.ts +11 -10
  132. package/lib/Utils/logger.js +7 -3
  133. package/lib/Utils/lt-hash.d.ts +13 -12
  134. package/lib/Utils/lt-hash.js +37 -27
  135. package/lib/Utils/make-mutex.d.ts +7 -6
  136. package/lib/Utils/make-mutex.js +29 -20
  137. package/lib/Utils/message-retry-manager.d.ts +6 -6
  138. package/lib/Utils/message-retry-manager.js +36 -8
  139. package/lib/Utils/messages-media.d.ts +102 -87
  140. package/lib/Utils/messages-media.js +570 -427
  141. package/lib/Utils/messages.d.ts +64 -37
  142. package/lib/Utils/messages.js +1270 -511
  143. package/lib/Utils/noise-handler.d.ts +18 -18
  144. package/lib/Utils/noise-handler.js +109 -101
  145. package/lib/Utils/process-message.d.ts +32 -25
  146. package/lib/Utils/process-message.js +281 -266
  147. package/lib/Utils/signal.d.ts +32 -24
  148. package/lib/Utils/signal.js +105 -98
  149. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  150. package/lib/Utils/use-mongo-file-auth-state.js +84 -0
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -5
  152. package/lib/Utils/use-multi-file-auth-state.js +186 -69
  153. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  154. package/lib/Utils/use-single-file-auth-state.js +80 -0
  155. package/lib/Utils/validate-connection.d.ts +13 -11
  156. package/lib/Utils/validate-connection.js +116 -124
  157. package/lib/WABinary/constants.d.ts +27 -25
  158. package/lib/WABinary/constants.js +1292 -1277
  159. package/lib/WABinary/decode.d.ts +9 -7
  160. package/lib/WABinary/decode.js +189 -139
  161. package/lib/WABinary/encode.d.ts +3 -3
  162. package/lib/WABinary/encode.js +154 -105
  163. package/lib/WABinary/generic-utils.d.ts +27 -14
  164. package/lib/WABinary/generic-utils.js +102 -62
  165. package/lib/WABinary/index.d.ts +5 -6
  166. package/lib/WABinary/index.js +25 -6
  167. package/lib/WABinary/jid-utils.d.ts +46 -41
  168. package/lib/WABinary/jid-utils.js +80 -84
  169. package/lib/WABinary/types.d.ts +13 -10
  170. package/lib/WABinary/types.js +3 -2
  171. package/lib/WAM/BinaryInfo.d.ts +15 -8
  172. package/lib/WAM/BinaryInfo.js +14 -7
  173. package/lib/WAM/constants.d.ts +37 -30
  174. package/lib/WAM/constants.js +11983 -19465
  175. package/lib/WAM/encode.d.ts +3 -3
  176. package/lib/WAM/encode.js +110 -95
  177. package/lib/WAM/index.d.ts +3 -4
  178. package/lib/WAM/index.js +23 -4
  179. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
  180. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
  181. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  182. package/lib/WAUSync/Protocols/USyncContactProtocol.js +19 -12
  183. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
  184. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
  185. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
  186. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
  187. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
  188. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  189. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
  191. package/lib/WAUSync/Protocols/index.d.ts +6 -5
  192. package/lib/WAUSync/Protocols/index.js +26 -5
  193. package/lib/WAUSync/USyncQuery.d.ts +28 -26
  194. package/lib/WAUSync/USyncQuery.js +62 -64
  195. package/lib/WAUSync/USyncUser.d.ts +10 -11
  196. package/lib/WAUSync/USyncUser.js +19 -12
  197. package/lib/WAUSync/index.d.ts +3 -4
  198. package/lib/WAUSync/index.js +23 -4
  199. package/lib/index.d.ts +11 -10
  200. package/lib/index.js +33 -11
  201. package/package.json +43 -48
  202. package/WAProto/GenerateStatics.sh +0 -3
  203. package/WAProto/fix-imports.js +0 -29
  204. package/engine-requirements.js +0 -10
  205. package/lib/Defaults/index.d.ts.map +0 -1
  206. package/lib/Defaults/index.js.map +0 -1
  207. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  208. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  209. package/lib/Signal/Group/ciphertext-message.js +0 -12
  210. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  211. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  212. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  213. package/lib/Signal/Group/group-session-builder.js +0 -30
  214. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  215. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  216. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  217. package/lib/Signal/Group/group_cipher.js +0 -82
  218. package/lib/Signal/Group/group_cipher.js.map +0 -1
  219. package/lib/Signal/Group/index.d.ts +0 -12
  220. package/lib/Signal/Group/index.d.ts.map +0 -1
  221. package/lib/Signal/Group/index.js +0 -12
  222. package/lib/Signal/Group/index.js.map +0 -1
  223. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  224. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  225. package/lib/Signal/Group/keyhelper.js +0 -18
  226. package/lib/Signal/Group/keyhelper.js.map +0 -1
  227. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  228. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  229. package/lib/Signal/Group/sender-chain-key.js +0 -26
  230. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  231. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  232. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  233. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  234. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  235. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  236. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  237. package/lib/Signal/Group/sender-key-message.js +0 -66
  238. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  239. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  240. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  241. package/lib/Signal/Group/sender-key-name.js +0 -48
  242. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  243. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  244. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  245. package/lib/Signal/Group/sender-key-record.js +0 -41
  246. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  247. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  248. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  249. package/lib/Signal/Group/sender-key-state.js +0 -84
  250. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  251. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  252. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  253. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  254. package/lib/Signal/libsignal.d.ts.map +0 -1
  255. package/lib/Signal/libsignal.js.map +0 -1
  256. package/lib/Signal/lid-mapping.d.ts +0 -23
  257. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  258. package/lib/Signal/lid-mapping.js +0 -171
  259. package/lib/Signal/lid-mapping.js.map +0 -1
  260. package/lib/Socket/Client/index.d.ts.map +0 -1
  261. package/lib/Socket/Client/index.js.map +0 -1
  262. package/lib/Socket/Client/types.d.ts.map +0 -1
  263. package/lib/Socket/Client/types.js.map +0 -1
  264. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  265. package/lib/Socket/Client/websocket.js.map +0 -1
  266. package/lib/Socket/business.d.ts.map +0 -1
  267. package/lib/Socket/business.js.map +0 -1
  268. package/lib/Socket/chats.d.ts.map +0 -1
  269. package/lib/Socket/chats.js.map +0 -1
  270. package/lib/Socket/communities.d.ts.map +0 -1
  271. package/lib/Socket/communities.js.map +0 -1
  272. package/lib/Socket/groups.d.ts.map +0 -1
  273. package/lib/Socket/groups.js.map +0 -1
  274. package/lib/Socket/index.d.ts.map +0 -1
  275. package/lib/Socket/index.js.map +0 -1
  276. package/lib/Socket/messages-recv.d.ts.map +0 -1
  277. package/lib/Socket/messages-recv.js.map +0 -1
  278. package/lib/Socket/messages-send.d.ts.map +0 -1
  279. package/lib/Socket/messages-send.js.map +0 -1
  280. package/lib/Socket/mex.d.ts.map +0 -1
  281. package/lib/Socket/mex.js.map +0 -1
  282. package/lib/Socket/newsletter.d.ts.map +0 -1
  283. package/lib/Socket/newsletter.js.map +0 -1
  284. package/lib/Socket/socket.d.ts.map +0 -1
  285. package/lib/Socket/socket.js.map +0 -1
  286. package/lib/Types/Auth.d.ts.map +0 -1
  287. package/lib/Types/Auth.js.map +0 -1
  288. package/lib/Types/Bussines.d.ts +0 -25
  289. package/lib/Types/Bussines.d.ts.map +0 -1
  290. package/lib/Types/Bussines.js +0 -2
  291. package/lib/Types/Bussines.js.map +0 -1
  292. package/lib/Types/Call.d.ts.map +0 -1
  293. package/lib/Types/Call.js.map +0 -1
  294. package/lib/Types/Chat.d.ts.map +0 -1
  295. package/lib/Types/Chat.js.map +0 -1
  296. package/lib/Types/Contact.d.ts.map +0 -1
  297. package/lib/Types/Contact.js.map +0 -1
  298. package/lib/Types/Events.d.ts.map +0 -1
  299. package/lib/Types/Events.js.map +0 -1
  300. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  301. package/lib/Types/GroupMetadata.js.map +0 -1
  302. package/lib/Types/Label.d.ts.map +0 -1
  303. package/lib/Types/Label.js.map +0 -1
  304. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  305. package/lib/Types/LabelAssociation.js.map +0 -1
  306. package/lib/Types/Message.d.ts.map +0 -1
  307. package/lib/Types/Message.js.map +0 -1
  308. package/lib/Types/Newsletter.d.ts.map +0 -1
  309. package/lib/Types/Newsletter.js.map +0 -1
  310. package/lib/Types/Product.d.ts.map +0 -1
  311. package/lib/Types/Product.js.map +0 -1
  312. package/lib/Types/Signal.d.ts.map +0 -1
  313. package/lib/Types/Signal.js.map +0 -1
  314. package/lib/Types/Socket.d.ts.map +0 -1
  315. package/lib/Types/Socket.js.map +0 -1
  316. package/lib/Types/State.d.ts.map +0 -1
  317. package/lib/Types/State.js.map +0 -1
  318. package/lib/Types/USync.d.ts.map +0 -1
  319. package/lib/Types/USync.js.map +0 -1
  320. package/lib/Types/index.d.ts.map +0 -1
  321. package/lib/Types/index.js.map +0 -1
  322. package/lib/Utils/auth-utils.d.ts.map +0 -1
  323. package/lib/Utils/auth-utils.js.map +0 -1
  324. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  325. package/lib/Utils/baileys-event-stream.js.map +0 -1
  326. package/lib/Utils/browser-utils.d.ts +0 -4
  327. package/lib/Utils/browser-utils.d.ts.map +0 -1
  328. package/lib/Utils/browser-utils.js +0 -28
  329. package/lib/Utils/browser-utils.js.map +0 -1
  330. package/lib/Utils/business.d.ts.map +0 -1
  331. package/lib/Utils/business.js.map +0 -1
  332. package/lib/Utils/chat-utils.d.ts.map +0 -1
  333. package/lib/Utils/chat-utils.js.map +0 -1
  334. package/lib/Utils/crypto.d.ts.map +0 -1
  335. package/lib/Utils/crypto.js.map +0 -1
  336. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  337. package/lib/Utils/decode-wa-message.js.map +0 -1
  338. package/lib/Utils/event-buffer.d.ts.map +0 -1
  339. package/lib/Utils/event-buffer.js.map +0 -1
  340. package/lib/Utils/generics.d.ts.map +0 -1
  341. package/lib/Utils/generics.js.map +0 -1
  342. package/lib/Utils/history.d.ts.map +0 -1
  343. package/lib/Utils/history.js.map +0 -1
  344. package/lib/Utils/index.d.ts.map +0 -1
  345. package/lib/Utils/index.js.map +0 -1
  346. package/lib/Utils/link-preview.d.ts.map +0 -1
  347. package/lib/Utils/link-preview.js.map +0 -1
  348. package/lib/Utils/logger.d.ts.map +0 -1
  349. package/lib/Utils/logger.js.map +0 -1
  350. package/lib/Utils/lt-hash.d.ts.map +0 -1
  351. package/lib/Utils/lt-hash.js.map +0 -1
  352. package/lib/Utils/make-mutex.d.ts.map +0 -1
  353. package/lib/Utils/make-mutex.js.map +0 -1
  354. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  355. package/lib/Utils/message-retry-manager.js.map +0 -1
  356. package/lib/Utils/messages-media.d.ts.map +0 -1
  357. package/lib/Utils/messages-media.js.map +0 -1
  358. package/lib/Utils/messages.d.ts.map +0 -1
  359. package/lib/Utils/messages.js.map +0 -1
  360. package/lib/Utils/noise-handler.d.ts.map +0 -1
  361. package/lib/Utils/noise-handler.js.map +0 -1
  362. package/lib/Utils/pre-key-manager.d.ts +0 -28
  363. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  364. package/lib/Utils/pre-key-manager.js +0 -106
  365. package/lib/Utils/pre-key-manager.js.map +0 -1
  366. package/lib/Utils/process-message.d.ts.map +0 -1
  367. package/lib/Utils/process-message.js.map +0 -1
  368. package/lib/Utils/signal.d.ts.map +0 -1
  369. package/lib/Utils/signal.js.map +0 -1
  370. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  371. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  372. package/lib/Utils/validate-connection.d.ts.map +0 -1
  373. package/lib/Utils/validate-connection.js.map +0 -1
  374. package/lib/WABinary/constants.d.ts.map +0 -1
  375. package/lib/WABinary/constants.js.map +0 -1
  376. package/lib/WABinary/decode.d.ts.map +0 -1
  377. package/lib/WABinary/decode.js.map +0 -1
  378. package/lib/WABinary/encode.d.ts.map +0 -1
  379. package/lib/WABinary/encode.js.map +0 -1
  380. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  381. package/lib/WABinary/generic-utils.js.map +0 -1
  382. package/lib/WABinary/index.d.ts.map +0 -1
  383. package/lib/WABinary/index.js.map +0 -1
  384. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  385. package/lib/WABinary/jid-utils.js.map +0 -1
  386. package/lib/WABinary/types.d.ts.map +0 -1
  387. package/lib/WABinary/types.js.map +0 -1
  388. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  389. package/lib/WAM/BinaryInfo.js.map +0 -1
  390. package/lib/WAM/constants.d.ts.map +0 -1
  391. package/lib/WAM/constants.js.map +0 -1
  392. package/lib/WAM/encode.d.ts.map +0 -1
  393. package/lib/WAM/encode.js.map +0 -1
  394. package/lib/WAM/index.d.ts.map +0 -1
  395. package/lib/WAM/index.js.map +0 -1
  396. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  397. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  398. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  399. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  400. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  401. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  402. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  403. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  404. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  405. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  406. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  407. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  408. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  409. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  410. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
  411. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  412. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  413. package/lib/WAUSync/Protocols/index.js.map +0 -1
  414. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  415. package/lib/WAUSync/USyncQuery.js.map +0 -1
  416. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  417. package/lib/WAUSync/USyncUser.js.map +0 -1
  418. package/lib/WAUSync/index.d.ts.map +0 -1
  419. package/lib/WAUSync/index.js.map +0 -1
  420. package/lib/index.d.ts.map +0 -1
  421. package/lib/index.js.map +0 -1
@@ -1,39 +1,38 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import { WAMessageStubType } from '../Types/index.js';
3
- import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
4
- import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
5
- import { aesDecryptGCM, hmacSign } from './crypto.js';
6
- import { toNumber } from './generics.js';
7
- import { downloadAndProcessHistorySyncNotification } from './history.js';
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const WAProto_1 = require("../../WAProto")
6
+ const Types_1 = require("../Types")
7
+ const messages_1 = require("../Utils/messages")
8
+ const WABinary_1 = require("../WABinary")
9
+ const crypto_1 = require("./crypto")
10
+ const generics_1 = require("./generics")
11
+ const history_1 = require("./history")
12
+ const chats_1 = require("../Socket/chats")
8
13
  const REAL_MSG_STUB_TYPES = new Set([
9
- WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
10
- WAMessageStubType.CALL_MISSED_GROUP_VOICE,
11
- WAMessageStubType.CALL_MISSED_VIDEO,
12
- WAMessageStubType.CALL_MISSED_VOICE
13
- ]);
14
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
14
+ Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
15
+ Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
16
+ Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
17
+ Types_1.WAMessageStubType.CALL_MISSED_VOICE
18
+ ])
19
+
20
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
21
+ Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
22
+ ])
23
+
15
24
  /** Cleans a received message to further processing */
16
- export const cleanMessage = (message, meId, meLid) => {
25
+ const cleanMessage = (message, meId) => {
17
26
  // ensure remoteJid and participant doesn't have device or agent in it
18
- if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
19
- message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
20
- }
21
- else {
22
- message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
23
- }
24
- if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
25
- message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
26
- }
27
- else {
28
- message.key.participant = jidNormalizedUser(message.key.participant);
29
- }
30
- const content = normalizeMessageContent(message.message);
27
+ message.key.remoteJid = WABinary_1.jidNormalizedUser(message.key.remoteJid)
28
+ message.key.participant = message.key.participant ? WABinary_1.jidNormalizedUser(message.key.participant) : undefined
29
+ const content = messages_1.normalizeMessageContent(message.message)
31
30
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
32
31
  if (content?.reactionMessage) {
33
- normaliseKey(content.reactionMessage.key);
32
+ normaliseKey(content.reactionMessage.key)
34
33
  }
35
34
  if (content?.pollUpdateMessage) {
36
- normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
35
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey)
37
36
  }
38
37
  function normaliseKey(msgKey) {
39
38
  // if the reaction is from another user
@@ -42,178 +41,188 @@ export const cleanMessage = (message, meId, meLid) => {
42
41
  // if the sender believed the message being reacted to is not from them
43
42
  // we've to correct the key to be from them, or some other participant
44
43
  msgKey.fromMe = !msgKey.fromMe
45
- ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
46
- areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
47
- : // if the message being reacted to, was from them
48
- // fromMe automatically becomes false
49
- false;
44
+ ? WABinary_1.areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId)
45
+ // if the message being reacted to, was from them
46
+ // fromMe automatically becomes false
47
+ : false
50
48
  // set the remoteJid to being the same as the chat the message came from
51
- // TODO: investigate inconsistencies
52
- msgKey.remoteJid = message.key.remoteJid;
49
+ msgKey.remoteJid = message.key.remoteJid
53
50
  // set participant of the message
54
- msgKey.participant = msgKey.participant || message.key.participant;
51
+ msgKey.participant = msgKey.participant || message.key.participant
55
52
  }
56
53
  }
57
- };
58
- // TODO: target:audit AUDIT THIS FUNCTION AGAIN
59
- export const isRealMessage = (message) => {
60
- const normalizedContent = normalizeMessageContent(message.message);
61
- const hasSomeContent = !!getContentType(normalizedContent);
62
- return ((!!normalizedContent ||
54
+ }
55
+
56
+ const isRealMessage = (message, meId) => {
57
+ const normalizedContent = messages_1.normalizeMessageContent(message.message)
58
+ const hasSomeContent = !!messages_1.getContentType(normalizedContent)
59
+ return (
60
+ !!normalizedContent ||
63
61
  REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
64
- REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
65
- hasSomeContent &&
66
- !normalizedContent?.protocolMessage &&
67
- !normalizedContent?.reactionMessage &&
68
- !normalizedContent?.pollUpdateMessage);
69
- };
70
- export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
62
+ (
63
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) &&
64
+ message.messageStubParameters?.some(p => WABinary_1.areJidsSameUser(meId, p))
65
+ )
66
+ ) &&
67
+ hasSomeContent &&
68
+ !normalizedContent?.protocolMessage &&
69
+ !normalizedContent?.reactionMessage &&
70
+ !normalizedContent?.pollUpdateMessage
71
+ }
72
+
73
+ const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType)
74
+
71
75
  /**
72
76
  * Get the ID of the chat from the given key.
73
77
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
74
78
  */
75
- export const getChatId = ({ remoteJid, participant, fromMe }) => {
76
- if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
77
- return participant;
79
+ const getChatId = ({ remoteJid, participant, fromMe }) => {
80
+ if (WABinary_1.isJidBroadcast(remoteJid)
81
+ && !WABinary_1.isJidStatusBroadcast(remoteJid)
82
+ && !fromMe) {
83
+ return participant
78
84
  }
79
- return remoteJid;
80
- };
85
+ return remoteJid
86
+ }
87
+
81
88
  /**
82
89
  * Decrypt a poll vote
83
90
  * @param vote encrypted vote
84
91
  * @param ctx additional info about the poll required for decryption
85
92
  * @returns list of SHA256 options
86
93
  */
87
- export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
94
+ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
88
95
  const sign = Buffer.concat([
89
96
  toBinary(pollMsgId),
90
97
  toBinary(pollCreatorJid),
91
98
  toBinary(voterJid),
92
99
  toBinary('Poll Vote'),
93
100
  new Uint8Array([1])
94
- ]);
95
- const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
96
- const decKey = hmacSign(sign, key0, 'sha256');
97
- const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
98
- const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
99
- return proto.Message.PollVoteMessage.decode(decrypted);
101
+ ])
102
+ const key0 = crypto_1.hmacSign(pollEncKey, new Uint8Array(32), 'sha256')
103
+ const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
104
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`)
105
+ const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, aad)
106
+ return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted)
100
107
  function toBinary(txt) {
101
- return Buffer.from(txt);
108
+ return Buffer.from(txt)
102
109
  }
103
110
  }
104
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options }) => {
105
- const meId = creds.me.id;
106
- const { accountSettings } = creds;
107
- const chat = { id: jidNormalizedUser(getChatId(message.key)) };
108
- const isRealMsg = isRealMessage(message);
111
+
112
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
113
+ const meId = creds.me.id
114
+ const { accountSettings } = creds
115
+ const chat = { id: WABinary_1.jidNormalizedUser(getChatId(message.key)) }
116
+ const isRealMsg = isRealMessage(message, meId)
109
117
  if (isRealMsg) {
110
- chat.messages = [{ message }];
111
- chat.conversationTimestamp = toNumber(message.messageTimestamp);
118
+ chat.messages = [{ message }]
119
+ chat.conversationTimestamp = generics_1.toNumber(message.messageTimestamp)
112
120
  // only increment unread count if not CIPHERTEXT and from another person
113
121
  if (shouldIncrementChatUnread(message)) {
114
- chat.unreadCount = (chat.unreadCount || 0) + 1;
122
+ chat.unreadCount = (chat.unreadCount || 0) + 1
115
123
  }
116
124
  }
117
- const content = normalizeMessageContent(message.message);
125
+ const content = messages_1.normalizeMessageContent(message.message)
118
126
  // unarchive chat if it's a real message, or someone reacted to our message
119
127
  // and we've the unarchive chats setting on
120
- if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
121
- chat.archived = false;
122
- chat.readOnly = false;
128
+ if (isRealMsg || content?.reactionMessage?.key?.fromMe
129
+ && accountSettings?.unarchiveChats) {
130
+ chat.archived = false
131
+ chat.readOnly = false
123
132
  }
124
- const protocolMsg = content?.protocolMessage;
133
+ const protocolMsg = content?.protocolMessage
125
134
  if (protocolMsg) {
126
135
  switch (protocolMsg.type) {
127
- case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
128
- const histNotification = protocolMsg.historySyncNotification;
129
- const process = shouldProcessHistoryMsg;
130
- const isLatest = !creds.processedHistoryMessages?.length;
136
+ case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
137
+ const histNotification = protocolMsg.historySyncNotification
138
+ const process = shouldProcessHistoryMsg
139
+ const isLatest = !creds.processedHistoryMessages?.length
131
140
  logger?.info({
132
141
  histNotification,
133
142
  process,
134
143
  id: message.key.id,
135
- isLatest
136
- }, 'got history notification');
144
+ isLatest,
145
+ }, 'got history notification')
137
146
  if (process) {
138
- // TODO: investigate
139
- if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
147
+ if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
140
148
  ev.emit('creds.update', {
141
149
  processedHistoryMessages: [
142
150
  ...(creds.processedHistoryMessages || []),
143
151
  { key: message.key, messageTimestamp: message.messageTimestamp }
144
152
  ]
145
- });
153
+ })
146
154
  }
147
- const data = await downloadAndProcessHistorySyncNotification(histNotification, options);
155
+ const data = await history_1.downloadAndProcessHistorySyncNotification(histNotification, options)
148
156
  ev.emit('messaging-history.set', {
149
157
  ...data,
150
- isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
158
+ isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
159
+ ? isLatest
160
+ : undefined,
151
161
  peerDataRequestSessionId: histNotification.peerDataRequestSessionId
152
- });
162
+ })
153
163
  }
154
- break;
155
- case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
156
- const keys = protocolMsg.appStateSyncKeyShare.keys;
164
+ break
165
+ case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
166
+ const keys = protocolMsg.appStateSyncKeyShare.keys
157
167
  if (keys?.length) {
158
- let newAppStateSyncKeyId = '';
168
+ let newAppStateSyncKeyId = ''
159
169
  await keyStore.transaction(async () => {
160
- const newKeys = [];
170
+ const newKeys = []
161
171
  for (const { keyData, keyId } of keys) {
162
- const strKeyId = Buffer.from(keyId.keyId).toString('base64');
163
- newKeys.push(strKeyId);
164
- await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
165
- newAppStateSyncKeyId = strKeyId;
172
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64')
173
+ newKeys.push(strKeyId)
174
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
175
+ newAppStateSyncKeyId = strKeyId
166
176
  }
167
- logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
168
- }, meId);
169
- ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
177
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys')
178
+ })
179
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId })
170
180
  }
171
181
  else {
172
- logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
182
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys')
173
183
  }
174
- break;
175
- case proto.Message.ProtocolMessage.Type.REVOKE:
184
+ break
185
+ case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
176
186
  ev.emit('messages.update', [
177
187
  {
178
188
  key: {
179
189
  ...message.key,
180
190
  id: protocolMsg.key.id
181
191
  },
182
- update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
192
+ update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
183
193
  }
184
- ]);
185
- break;
186
- case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
194
+ ])
195
+ break
196
+ case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
187
197
  Object.assign(chat, {
188
- ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
198
+ ephemeralSettingTimestamp: generics_1.toNumber(message.messageTimestamp),
189
199
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
190
- });
191
- break;
192
- case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
193
- const response = protocolMsg.peerDataOperationRequestResponseMessage;
200
+ })
201
+ break
202
+ case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
203
+ const response = protocolMsg.peerDataOperationRequestResponseMessage
194
204
  if (response) {
195
- await placeholderResendCache?.del(response.stanzaId);
205
+ placeholderResendCache?.del(response.stanzaId)
196
206
  // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
197
- const { peerDataOperationResult } = response;
207
+ const { peerDataOperationResult } = response
198
208
  for (const result of peerDataOperationResult) {
199
- const { placeholderMessageResendResponse: retryResponse } = result;
209
+ const { placeholderMessageResendResponse: retryResponse } = result
200
210
  //eslint-disable-next-line max-depth
201
211
  if (retryResponse) {
202
- const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
212
+ const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes)
203
213
  // wait till another upsert event is available, don't want it to be part of the PDO response message
204
- // TODO: parse through proper message handling utilities (to add relevant key fields)
205
214
  setTimeout(() => {
206
215
  ev.emit('messages.upsert', {
207
216
  messages: [webMessageInfo],
208
217
  type: 'notify',
209
218
  requestId: response.stanzaId
210
- });
211
- }, 500);
219
+ })
220
+ }, 500)
212
221
  }
213
222
  }
214
223
  }
215
- break;
216
- case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
224
+ break
225
+ case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
217
226
  ev.emit('messages.update', [
218
227
  {
219
228
  // flip the sender / fromMe properties because they're in the perspective of the sender
@@ -225,159 +234,162 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
225
234
  }
226
235
  },
227
236
  messageTimestamp: protocolMsg.timestampMs
228
- ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
237
+ ? Math.floor(generics_1.toNumber(protocolMsg.timestampMs) / 1000)
229
238
  : message.messageTimestamp
230
239
  }
231
240
  }
232
- ]);
233
- break;
234
- case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
235
- const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
236
- const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
237
- logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
238
- const pairs = [];
239
- for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
240
- const lid = latestLid || assignedLid;
241
- pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
242
- }
243
- await signalRepository.lidMapping.storeLIDPNMappings(pairs);
244
- if (pairs.length) {
245
- for (const { pn, lid } of pairs) {
246
- await signalRepository.migrateSession(pn, lid);
247
- }
248
- }
241
+ ])
242
+ break
243
+ case WAProto_1.proto.Message.ProtocolMessage.Type.LIMIT_SHARING:
244
+ ev.emit('limit-sharing.update', {
245
+ id: protocolMsg.key.remoteJid,
246
+ author: WABinary_1.areJidsSameUser(message.key.remoteJid, protocolMsg.key.remoteJid) ? WABinary_1.jidNormalizedUser(meId) : message.key.remoteJid,
247
+ action: `${protocolMsg.limitSharing.sharingLimited ? 'on' : 'off'}`,
248
+ trigger: protocolMsg.limitSharing.trigger,
249
+ update_time: protocolMsg.limitSharing.limitSharingSettingTimestamp
250
+ })
251
+ break
249
252
  }
250
253
  }
251
254
  else if (content?.reactionMessage) {
252
255
  const reaction = {
253
256
  ...content.reactionMessage,
254
- key: message.key
255
- };
256
- ev.emit('messages.reaction', [
257
- {
257
+ key: message.key,
258
+ }
259
+ ev.emit('messages.reaction', [{
258
260
  reaction,
259
261
  key: content.reactionMessage?.key
260
- }
261
- ]);
262
+ }])
262
263
  }
263
264
  else if (message.messageStubType) {
264
- const jid = message.key?.remoteJid;
265
+ const jid = message.key?.remoteJid
266
+
265
267
  //let actor = whatsappID (message.participant)
266
- let participants;
267
- const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
268
- id: jid,
269
- author: message.key.participant,
270
- authorPn: message.key.participantAlt,
271
- participants,
272
- action
273
- });
268
+ let participants
269
+
270
+ const jid2 = message.key.participant;
271
+ const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: jid2, participants, action}))
274
272
  const emitGroupUpdate = (update) => {
275
- ev.emit('groups.update', [
276
- { id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
277
- ]);
278
- };
273
+ ev.emit('groups.update', [{ id: jid, ...update, author: message.participant ? message.participant : undefined }])
274
+ }
275
+ const emitCommunityUpdate = (update) => {
276
+ ev.emit('communities.update', [{ id: jid, ...update, author: message.participant ? message.participant : undefined }])
277
+ }
279
278
  const emitGroupRequestJoin = (participant, action, method) => {
280
- ev.emit('group.join-request', {
281
- id: jid,
282
- author: message.key.participant,
283
- authorPn: message.key.participantAlt,
284
- participant: participant.lid,
285
- participantPn: participant.pn,
286
- action,
287
- method: method
288
- });
289
- };
290
- const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
279
+ ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method })
280
+ }
281
+ const participantsIncludesMe = () => participants.find(jid => WABinary_1.areJidsSameUser(meId, jid))
291
282
  switch (message.messageStubType) {
292
- case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
293
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
294
- emitParticipantsUpdate('modify');
295
- break;
296
- case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
297
- case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
298
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
299
- emitParticipantsUpdate('remove');
283
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
284
+ participants = message.messageStubParameters || []
285
+ emitParticipantsUpdate('modify')
286
+ break
287
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
288
+ participants = message.messageStubParameters || [];
289
+ emitParticipantsUpdate('leave');
290
+ // mark the chat read only if you left the group
291
+ if (participantsIncludesMe()) {
292
+ chat.readOnly = true;
293
+ }
294
+ break;
295
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
296
+ participants = message.messageStubParameters || []
297
+ emitParticipantsUpdate('remove')
300
298
  // mark the chat read only if you left the group
301
299
  if (participantsIncludesMe()) {
302
- chat.readOnly = true;
300
+ chat.readOnly = true
303
301
  }
304
- break;
305
- case WAMessageStubType.GROUP_PARTICIPANT_ADD:
306
- case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
307
- case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
308
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
302
+ break
303
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
304
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
305
+ let actionGp = 'invite'
306
+ participants = message.messageStubParameters || []
307
+ if (participantsIncludesMe()) chat.readOnly = false;
308
+ if (message?.key?.participant && !participants.includes(message?.key?.participant)) {
309
+ actionGp = 'approval-invite'
310
+ }
311
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
312
+ participants = message.messageStubParameters || []
309
313
  if (participantsIncludesMe()) {
310
- chat.readOnly = false;
314
+ chat.readOnly = false
311
315
  }
312
- emitParticipantsUpdate('add');
313
- break;
314
- case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
315
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
316
- emitParticipantsUpdate('demote');
317
- break;
318
- case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
319
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
320
- emitParticipantsUpdate('promote');
321
- break;
322
- case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
323
- const announceValue = message.messageStubParameters?.[0];
324
- emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
325
- break;
326
- case WAMessageStubType.GROUP_CHANGE_RESTRICT:
327
- const restrictValue = message.messageStubParameters?.[0];
328
- emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
329
- break;
330
- case WAMessageStubType.GROUP_CHANGE_SUBJECT:
331
- const name = message.messageStubParameters?.[0];
332
- chat.name = name;
333
- emitGroupUpdate({ subject: name });
334
- break;
335
- case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
336
- const description = message.messageStubParameters?.[0];
337
- chat.description = description;
338
- emitGroupUpdate({ desc: description });
339
- break;
340
- case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
341
- const code = message.messageStubParameters?.[0];
342
- emitGroupUpdate({ inviteCode: code });
343
- break;
344
- case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
345
- const memberAddValue = message.messageStubParameters?.[0];
346
- emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
347
- break;
348
- case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
349
- const approvalMode = message.messageStubParameters?.[0];
350
- emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
351
- break;
352
- case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
353
- const participant = JSON.parse(message.messageStubParameters?.[0]);
354
- const action = message.messageStubParameters?.[1];
355
- const method = message.messageStubParameters?.[2];
356
- emitGroupRequestJoin(participant, action, method);
357
- break;
316
+ emitParticipantsUpdate('add')
317
+ break
318
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
319
+ case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_DEMOTE:
320
+ participants = message.messageStubParameters || []
321
+ emitParticipantsUpdate('demote')
322
+ break
323
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
324
+ case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_PROMOTE:
325
+ participants = message.messageStubParameters || []
326
+ emitParticipantsUpdate('promote')
327
+ break
328
+ case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
329
+ const announceValue = message.messageStubParameters?.[0]
330
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' })
331
+ break
332
+ case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
333
+ const restrictValue = message.messageStubParameters?.[0]
334
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' })
335
+ break
336
+ case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
337
+ const name = message.messageStubParameters?.[0]
338
+ chat.name = name
339
+ emitGroupUpdate({ subject: name })
340
+ break
341
+ case Types_1.WAMessageStubType.COMMUNITY_PARENT_GROUP_SUBJECT_CHANGED:
342
+ const name2 = message.messageStubParameters?.[0]
343
+ chat.name2 = name2
344
+ emitCommunityUpdate({ subject: name2 })
345
+ break
346
+ case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
347
+ const description = message.messageStubParameters?.[0]
348
+ chat.description = description
349
+ emitGroupUpdate({ desc: description })
350
+ break
351
+ case Types_1.WAMessageStubType.COMMUNITY_CHANGE_DESCRIPTION:
352
+ const description2 = message.messageStubParameters?.[0]
353
+ chat.description2 = description2
354
+ emitCommunityUpdate({ desc: description2 })
355
+ break
356
+ case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
357
+ const code = message.messageStubParameters?.[0]
358
+ emitGroupUpdate({ inviteCode: code })
359
+ break
360
+ case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
361
+ const memberAddValue = message.messageStubParameters?.[0]
362
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' })
363
+ break
364
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
365
+ const approvalMode = message.messageStubParameters?.[0]
366
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' })
367
+ break
368
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
369
+ const participant = message.messageStubParameters?.[0]
370
+ const action = message.messageStubParameters?.[1]
371
+ const method = message.messageStubParameters?.[2]
372
+ emitGroupRequestJoin(participant, action, method)
373
+ break
358
374
  }
359
- } /* else if(content?.pollUpdateMessage) {
360
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
375
+ }
376
+ else if (content?.pollUpdateMessage) {
377
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey
361
378
  // we need to fetch the poll creation message to get the poll enc key
362
- // TODO: make standalone, remove getMessage reference
363
- // TODO: Remove entirely
364
- const pollMsg = await getMessage(creationMsgKey)
365
- if(pollMsg) {
366
- const meIdNormalised = jidNormalizedUser(meId)
367
- const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
368
- const voterJid = getKeyAuthor(message.key, meIdNormalised)
369
- const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
370
-
379
+ const pollMsg2 = await getMessage(creationMsgKey);
380
+ const pollMsg = pollMsg.botInvokeMessage?.message || pollMsg2;
381
+ if (pollMsg) {
382
+ const meIdNormalised = WABinary_1.jidNormalizedUser(meId)
383
+ const pollCreatorJid = generics_1.getKeyAuthor(creationMsgKey, meIdNormalised)
384
+ const voterJid = generics_1.getKeyAuthor(message.key, meIdNormalised)
385
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret
371
386
  try {
372
- const voteMsg = decryptPollVote(
373
- content.pollUpdateMessage.vote!,
374
- {
375
- pollEncKey,
376
- pollCreatorJid,
377
- pollMsgId: creationMsgKey.id!,
378
- voterJid,
379
- }
380
- )
387
+ const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
388
+ pollEncKey,
389
+ pollCreatorJid,
390
+ pollMsgId: creationMsgKey.id,
391
+ voterJid,
392
+ })
381
393
  ev.emit('messages.update', [
382
394
  {
383
395
  key: creationMsgKey,
@@ -386,28 +398,31 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
386
398
  {
387
399
  pollUpdateMessageKey: message.key,
388
400
  vote: voteMsg,
389
- senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
401
+ senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
390
402
  }
391
403
  ]
392
404
  }
393
405
  }
394
406
  ])
395
- } catch(err) {
396
- logger?.warn(
397
- { err, creationMsgKey },
398
- 'failed to decrypt poll vote'
399
- )
400
407
  }
401
- } else {
402
- logger?.warn(
403
- { creationMsgKey },
404
- 'poll creation message not found, cannot decrypt update'
405
- )
408
+ catch (err) {
409
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt poll vote')
410
+ }
411
+ }
412
+ else {
413
+ logger?.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update')
406
414
  }
407
- } */
415
+ }
408
416
  if (Object.keys(chat).length > 1) {
409
- ev.emit('chats.update', [chat]);
417
+ ev.emit('chats.update', [chat])
410
418
  }
411
- };
412
- export default processMessage;
413
- //# sourceMappingURL=process-message.js.map
419
+ }
420
+
421
+ module.exports = {
422
+ cleanMessage,
423
+ isRealMessage,
424
+ shouldIncrementChatUnread,
425
+ getChatId,
426
+ decryptPollVote,
427
+ processMessage
428
+ }