@vinzsocket/baileys 2.8.35 → 3.0.10

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 (410) hide show
  1. package/WAProto/GenerateStatics.sh +2 -2
  2. package/WAProto/WAProto.proto +1339 -493
  3. package/WAProto/fix-imports.js +75 -19
  4. package/WAProto/index.d.ts +5274 -1945
  5. package/WAProto/index.js +81079 -20694
  6. package/lib/Defaults/index.d.ts +75 -0
  7. package/lib/Defaults/index.d.ts.map +1 -0
  8. package/lib/Defaults/index.js +122 -110
  9. package/lib/Defaults/index.js.map +1 -0
  10. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.js +11 -18
  13. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  14. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.js +27 -35
  17. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  18. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  19. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  20. package/lib/Signal/Group/group_cipher.js +75 -95
  21. package/lib/Signal/Group/group_cipher.js.map +1 -0
  22. package/lib/Signal/Group/index.d.ts +12 -0
  23. package/lib/Signal/Group/index.d.ts.map +1 -0
  24. package/lib/Signal/Group/index.js +12 -79
  25. package/lib/Signal/Group/index.js.map +1 -0
  26. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  27. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  28. package/lib/Signal/Group/keyhelper.js +14 -25
  29. package/lib/Signal/Group/keyhelper.js.map +1 -0
  30. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  31. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.js +24 -37
  33. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  34. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  35. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.js +62 -61
  37. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  38. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  39. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.js +64 -68
  41. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  42. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  43. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.js +41 -47
  45. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  46. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  47. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.js +36 -50
  49. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  50. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  51. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.js +76 -96
  53. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  54. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  55. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.js +25 -34
  57. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  58. package/lib/Signal/libsignal.d.ts +5 -0
  59. package/lib/Signal/libsignal.d.ts.map +1 -0
  60. package/lib/Signal/libsignal.js +415 -402
  61. package/lib/Signal/libsignal.js.map +1 -0
  62. package/lib/Signal/lid-mapping.d.ts +23 -0
  63. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  64. package/lib/Signal/lid-mapping.js +273 -111
  65. package/lib/Signal/lid-mapping.js.map +1 -0
  66. package/lib/Socket/Client/index.d.ts +3 -0
  67. package/lib/Socket/Client/index.d.ts.map +1 -0
  68. package/lib/Socket/Client/index.js +3 -27
  69. package/lib/Socket/Client/index.js.map +1 -0
  70. package/lib/Socket/Client/types.d.ts +16 -0
  71. package/lib/Socket/Client/types.d.ts.map +1 -0
  72. package/lib/Socket/Client/types.js +10 -17
  73. package/lib/Socket/Client/types.js.map +1 -0
  74. package/lib/Socket/Client/websocket.d.ts +13 -0
  75. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  76. package/lib/Socket/Client/websocket.js +53 -57
  77. package/lib/Socket/Client/websocket.js.map +1 -0
  78. package/lib/Socket/business.d.ts +217 -0
  79. package/lib/Socket/business.d.ts.map +1 -0
  80. package/lib/Socket/business.js +374 -363
  81. package/lib/Socket/business.js.map +1 -0
  82. package/lib/Socket/chats.d.ts +124 -0
  83. package/lib/Socket/chats.d.ts.map +1 -0
  84. package/lib/Socket/chats.js +1162 -1041
  85. package/lib/Socket/chats.js.map +1 -0
  86. package/lib/Socket/communities.d.ts +273 -0
  87. package/lib/Socket/communities.d.ts.map +1 -0
  88. package/lib/Socket/communities.js +418 -469
  89. package/lib/Socket/communities.js.map +1 -0
  90. package/lib/Socket/groups.d.ts +161 -0
  91. package/lib/Socket/groups.d.ts.map +1 -0
  92. package/lib/Socket/groups.js +337 -393
  93. package/lib/Socket/groups.js.map +1 -0
  94. package/lib/Socket/index.d.ts +260 -0
  95. package/lib/Socket/index.d.ts.map +1 -0
  96. package/lib/Socket/index.js +10 -20
  97. package/lib/Socket/index.js.map +1 -0
  98. package/lib/Socket/messages-recv.d.ts +203 -0
  99. package/lib/Socket/messages-recv.d.ts.map +1 -0
  100. package/lib/Socket/messages-recv.js +1738 -1394
  101. package/lib/Socket/messages-recv.js.map +1 -0
  102. package/lib/Socket/messages-send.d.ts +199 -0
  103. package/lib/Socket/messages-send.d.ts.map +1 -0
  104. package/lib/Socket/messages-send.js +1101 -1245
  105. package/lib/Socket/messages-send.js.map +1 -0
  106. package/lib/Socket/mex.d.ts +3 -0
  107. package/lib/Socket/mex.d.ts.map +1 -0
  108. package/lib/Socket/mex.js +38 -51
  109. package/lib/Socket/mex.js.map +1 -0
  110. package/lib/Socket/newsletter.d.ts +170 -0
  111. package/lib/Socket/newsletter.d.ts.map +1 -0
  112. package/lib/Socket/newsletter.js +175 -225
  113. package/lib/Socket/newsletter.js.map +1 -0
  114. package/lib/Socket/socket.d.ts +59 -0
  115. package/lib/Socket/socket.d.ts.map +1 -0
  116. package/lib/Socket/socket.js +930 -914
  117. package/lib/Socket/socket.js.map +1 -0
  118. package/lib/Types/Auth.d.ts +117 -0
  119. package/lib/Types/Auth.d.ts.map +1 -0
  120. package/lib/Types/Auth.js +2 -5
  121. package/lib/Types/Auth.js.map +1 -0
  122. package/lib/Types/Bussines.d.ts +25 -0
  123. package/lib/Types/Bussines.d.ts.map +1 -0
  124. package/lib/Types/Bussines.js +2 -5
  125. package/lib/Types/Bussines.js.map +1 -0
  126. package/lib/Types/Call.d.ts +15 -0
  127. package/lib/Types/Call.d.ts.map +1 -0
  128. package/lib/Types/Call.js +2 -5
  129. package/lib/Types/Call.js.map +1 -0
  130. package/lib/Types/Chat.d.ts +124 -0
  131. package/lib/Types/Chat.d.ts.map +1 -0
  132. package/lib/Types/Chat.js +7 -7
  133. package/lib/Types/Chat.js.map +1 -0
  134. package/lib/Types/Contact.d.ts +26 -0
  135. package/lib/Types/Contact.d.ts.map +1 -0
  136. package/lib/Types/Contact.js +2 -5
  137. package/lib/Types/Contact.js.map +1 -0
  138. package/lib/Types/Events.d.ts +256 -0
  139. package/lib/Types/Events.d.ts.map +1 -0
  140. package/lib/Types/Events.js +2 -3
  141. package/lib/Types/Events.js.map +1 -0
  142. package/lib/Types/GroupMetadata.d.ts +71 -0
  143. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  144. package/lib/Types/GroupMetadata.js +2 -5
  145. package/lib/Types/GroupMetadata.js.map +1 -0
  146. package/lib/Types/Label.d.ts +47 -0
  147. package/lib/Types/Label.d.ts.map +1 -0
  148. package/lib/Types/Label.js +22 -28
  149. package/lib/Types/Label.js.map +1 -0
  150. package/lib/Types/LabelAssociation.d.ts +30 -0
  151. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  152. package/lib/Types/LabelAssociation.js +4 -10
  153. package/lib/Types/LabelAssociation.js.map +1 -0
  154. package/lib/Types/Message.d.ts +320 -0
  155. package/lib/Types/Message.d.ts.map +1 -0
  156. package/lib/Types/Message.js +8 -20
  157. package/lib/Types/Message.js.map +1 -0
  158. package/lib/Types/Mex.d.ts +141 -0
  159. package/lib/Types/Mex.d.ts.map +1 -0
  160. package/lib/Types/Mex.js +37 -0
  161. package/lib/Types/Mex.js.map +1 -0
  162. package/lib/Types/Product.d.ts +79 -0
  163. package/lib/Types/Product.d.ts.map +1 -0
  164. package/lib/Types/Product.js +2 -5
  165. package/lib/Types/Product.js.map +1 -0
  166. package/lib/Types/Signal.d.ts +87 -0
  167. package/lib/Types/Signal.d.ts.map +1 -0
  168. package/lib/Types/Signal.js +2 -3
  169. package/lib/Types/Signal.js.map +1 -0
  170. package/lib/Types/Socket.d.ts +136 -0
  171. package/lib/Types/Socket.d.ts.map +1 -0
  172. package/lib/Types/Socket.js +3 -4
  173. package/lib/Types/Socket.js.map +1 -0
  174. package/lib/Types/State.d.ts +97 -0
  175. package/lib/Types/State.d.ts.map +1 -0
  176. package/lib/Types/State.js +54 -17
  177. package/lib/Types/State.js.map +1 -0
  178. package/lib/Types/USync.d.ts +26 -0
  179. package/lib/Types/USync.d.ts.map +1 -0
  180. package/lib/Types/USync.js +2 -3
  181. package/lib/Types/USync.js.map +1 -0
  182. package/lib/Types/index.d.ts +65 -0
  183. package/lib/Types/index.d.ts.map +1 -0
  184. package/lib/Types/index.js +24 -165
  185. package/lib/Types/index.js.map +1 -0
  186. package/lib/Utils/auth-utils.d.ts +24 -0
  187. package/lib/Utils/auth-utils.d.ts.map +1 -0
  188. package/lib/Utils/auth-utils.js +272 -461
  189. package/lib/Utils/auth-utils.js.map +1 -0
  190. package/lib/Utils/browser-utils.d.ts +4 -0
  191. package/lib/Utils/browser-utils.d.ts.map +1 -0
  192. package/lib/Utils/browser-utils.js +28 -0
  193. package/lib/Utils/browser-utils.js.map +1 -0
  194. package/lib/Utils/business.d.ts +23 -0
  195. package/lib/Utils/business.d.ts.map +1 -0
  196. package/lib/Utils/business.js +207 -223
  197. package/lib/Utils/business.js.map +1 -0
  198. package/lib/Utils/chat-utils.d.ts +100 -0
  199. package/lib/Utils/chat-utils.d.ts.map +1 -0
  200. package/lib/Utils/chat-utils.js +828 -803
  201. package/lib/Utils/chat-utils.js.map +1 -0
  202. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  203. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  204. package/lib/Utils/companion-reg-client-utils.js +35 -0
  205. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  206. package/lib/Utils/crypto.d.ts +37 -0
  207. package/lib/Utils/crypto.d.ts.map +1 -0
  208. package/lib/Utils/crypto.js +87 -144
  209. package/lib/Utils/crypto.js.map +1 -0
  210. package/lib/Utils/decode-wa-message.d.ts +66 -0
  211. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  212. package/lib/Utils/decode-wa-message.js +291 -262
  213. package/lib/Utils/decode-wa-message.js.map +1 -0
  214. package/lib/Utils/event-buffer.d.ts +36 -0
  215. package/lib/Utils/event-buffer.d.ts.map +1 -0
  216. package/lib/Utils/event-buffer.js +598 -560
  217. package/lib/Utils/event-buffer.js.map +1 -0
  218. package/lib/Utils/generics.d.ts +91 -0
  219. package/lib/Utils/generics.d.ts.map +1 -0
  220. package/lib/Utils/generics.js +329 -363
  221. package/lib/Utils/generics.js.map +1 -0
  222. package/lib/Utils/history.d.ts +24 -0
  223. package/lib/Utils/history.d.ts.map +1 -0
  224. package/lib/Utils/history.js +129 -96
  225. package/lib/Utils/history.js.map +1 -0
  226. package/lib/Utils/identity-change-handler.d.ts +44 -0
  227. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  228. package/lib/Utils/identity-change-handler.js +50 -0
  229. package/lib/Utils/identity-change-handler.js.map +1 -0
  230. package/lib/Utils/index.d.ts +22 -0
  231. package/lib/Utils/index.d.ts.map +1 -0
  232. package/lib/Utils/index.js +22 -236
  233. package/lib/Utils/index.js.map +1 -0
  234. package/lib/Utils/link-preview.d.ts +21 -0
  235. package/lib/Utils/link-preview.d.ts.map +1 -0
  236. package/lib/Utils/link-preview.js +69 -86
  237. package/lib/Utils/link-preview.js.map +1 -0
  238. package/lib/Utils/logger.d.ts +12 -0
  239. package/lib/Utils/logger.d.ts.map +1 -0
  240. package/lib/Utils/logger.js +3 -11
  241. package/lib/Utils/logger.js.map +1 -0
  242. package/lib/Utils/lt-hash.d.ts +8 -0
  243. package/lib/Utils/lt-hash.d.ts.map +1 -0
  244. package/lib/Utils/lt-hash.js +2 -52
  245. package/lib/Utils/lt-hash.js.map +1 -0
  246. package/lib/Utils/make-mutex.d.ts +9 -0
  247. package/lib/Utils/make-mutex.d.ts.map +1 -0
  248. package/lib/Utils/make-mutex.js +30 -43
  249. package/lib/Utils/make-mutex.js.map +1 -0
  250. package/lib/Utils/message-retry-manager.d.ts +115 -0
  251. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  252. package/lib/Utils/message-retry-manager.js +259 -162
  253. package/lib/Utils/message-retry-manager.js.map +1 -0
  254. package/lib/Utils/messages-media.d.ts +133 -0
  255. package/lib/Utils/messages-media.d.ts.map +1 -0
  256. package/lib/Utils/messages-media.js +732 -711
  257. package/lib/Utils/messages-media.js.map +1 -0
  258. package/lib/Utils/messages.d.ts +91 -0
  259. package/lib/Utils/messages.d.ts.map +1 -0
  260. package/lib/Utils/messages.js +817 -803
  261. package/lib/Utils/messages.js.map +1 -0
  262. package/lib/Utils/noise-handler.d.ts +20 -0
  263. package/lib/Utils/noise-handler.d.ts.map +1 -0
  264. package/lib/Utils/noise-handler.js +195 -168
  265. package/lib/Utils/noise-handler.js.map +1 -0
  266. package/lib/Utils/offline-node-processor.d.ts +17 -0
  267. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  268. package/lib/Utils/offline-node-processor.js +40 -0
  269. package/lib/Utils/offline-node-processor.js.map +1 -0
  270. package/lib/Utils/pre-key-manager.d.ts +28 -0
  271. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  272. package/lib/Utils/pre-key-manager.js +106 -0
  273. package/lib/Utils/pre-key-manager.js.map +1 -0
  274. package/lib/Utils/process-message.d.ts +60 -0
  275. package/lib/Utils/process-message.d.ts.map +1 -0
  276. package/lib/Utils/process-message.js +601 -424
  277. package/lib/Utils/process-message.js.map +1 -0
  278. package/lib/Utils/reporting-utils.d.ts +11 -0
  279. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  280. package/lib/Utils/reporting-utils.js +258 -0
  281. package/lib/Utils/reporting-utils.js.map +1 -0
  282. package/lib/Utils/signal.d.ts +47 -0
  283. package/lib/Utils/signal.d.ts.map +1 -0
  284. package/lib/Utils/signal.js +180 -206
  285. package/lib/Utils/signal.js.map +1 -0
  286. package/lib/Utils/stanza-ack.d.ts +11 -0
  287. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  288. package/lib/Utils/stanza-ack.js +38 -0
  289. package/lib/Utils/stanza-ack.js.map +1 -0
  290. package/lib/Utils/sync-action-utils.d.ts +19 -0
  291. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  292. package/lib/Utils/sync-action-utils.js +49 -0
  293. package/lib/Utils/sync-action-utils.js.map +1 -0
  294. package/lib/Utils/tc-token-utils.d.ts +37 -0
  295. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  296. package/lib/Utils/tc-token-utils.js +163 -0
  297. package/lib/Utils/tc-token-utils.js.map +1 -0
  298. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  299. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  300. package/lib/Utils/use-multi-file-auth-state.js +98 -101
  301. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  302. package/lib/Utils/validate-connection.d.ts +11 -0
  303. package/lib/Utils/validate-connection.d.ts.map +1 -0
  304. package/lib/Utils/validate-connection.js +191 -188
  305. package/lib/Utils/validate-connection.js.map +1 -0
  306. package/lib/WABinary/constants.d.ts +28 -0
  307. package/lib/WABinary/constants.d.ts.map +1 -0
  308. package/lib/WABinary/constants.js +1295 -36
  309. package/lib/WABinary/constants.js.map +1 -0
  310. package/lib/WABinary/decode.d.ts +7 -0
  311. package/lib/WABinary/decode.d.ts.map +1 -0
  312. package/lib/WABinary/decode.js +254 -232
  313. package/lib/WABinary/decode.js.map +1 -0
  314. package/lib/WABinary/encode.d.ts +3 -0
  315. package/lib/WABinary/encode.d.ts.map +1 -0
  316. package/lib/WABinary/encode.js +208 -210
  317. package/lib/WABinary/encode.js.map +1 -0
  318. package/lib/WABinary/generic-utils.d.ts +15 -0
  319. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  320. package/lib/WABinary/generic-utils.js +97 -106
  321. package/lib/WABinary/generic-utils.js.map +1 -0
  322. package/lib/WABinary/index.d.ts +6 -0
  323. package/lib/WABinary/index.d.ts.map +1 -0
  324. package/lib/WABinary/index.js +6 -60
  325. package/lib/WABinary/index.js.map +1 -0
  326. package/lib/WABinary/jid-utils.d.ts +48 -0
  327. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  328. package/lib/WABinary/jid-utils.js +83 -70
  329. package/lib/WABinary/jid-utils.js.map +1 -0
  330. package/lib/WABinary/types.d.ts +19 -0
  331. package/lib/WABinary/types.d.ts.map +1 -0
  332. package/lib/WABinary/types.js +2 -4
  333. package/lib/WABinary/types.js.map +1 -0
  334. package/lib/WAM/BinaryInfo.d.ts +9 -0
  335. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  336. package/lib/WAM/BinaryInfo.js +9 -16
  337. package/lib/WAM/BinaryInfo.js.map +1 -0
  338. package/lib/WAM/constants.d.ts +40 -0
  339. package/lib/WAM/constants.d.ts.map +1 -0
  340. package/lib/WAM/constants.js +22853 -13001
  341. package/lib/WAM/constants.js.map +1 -0
  342. package/lib/WAM/encode.d.ts +3 -0
  343. package/lib/WAM/encode.d.ts.map +1 -0
  344. package/lib/WAM/encode.js +133 -133
  345. package/lib/WAM/encode.js.map +1 -0
  346. package/lib/WAM/index.d.ts +4 -0
  347. package/lib/WAM/index.d.ts.map +1 -0
  348. package/lib/WAM/index.js +4 -38
  349. package/lib/WAM/index.js.map +1 -0
  350. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  351. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  352. package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -34
  353. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  354. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  355. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  356. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -61
  357. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  358. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  359. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  360. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -32
  361. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  362. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  363. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  364. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +35 -40
  365. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  366. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  367. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  368. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -29
  369. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  370. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  371. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  372. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +47 -64
  373. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  374. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  375. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  376. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +27 -26
  377. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  378. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  379. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  380. package/lib/WAUSync/Protocols/index.js +6 -60
  381. package/lib/WAUSync/Protocols/index.js.map +1 -0
  382. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  383. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  384. package/lib/WAUSync/USyncQuery.js +94 -97
  385. package/lib/WAUSync/USyncQuery.js.map +1 -0
  386. package/lib/WAUSync/USyncUser.d.ts +17 -0
  387. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  388. package/lib/WAUSync/USyncUser.js +30 -29
  389. package/lib/WAUSync/USyncUser.js.map +1 -0
  390. package/lib/WAUSync/index.d.ts +4 -0
  391. package/lib/WAUSync/index.d.ts.map +1 -0
  392. package/lib/WAUSync/index.js +4 -38
  393. package/lib/WAUSync/index.js.map +1 -0
  394. package/lib/index.d.ts +12 -0
  395. package/lib/index.d.ts.map +1 -0
  396. package/lib/index.js +11 -114
  397. package/lib/index.js.map +1 -0
  398. package/package.json +47 -20
  399. package/README.md +0 -1315
  400. package/lib/Signal/Group/queue-job.js +0 -61
  401. package/lib/Store/index.js +0 -49
  402. package/lib/Store/make-cache-manager-store.js +0 -106
  403. package/lib/Store/make-in-memory-store.js +0 -497
  404. package/lib/Store/make-ordered-dictionary.js +0 -83
  405. package/lib/Store/object-repository.js +0 -32
  406. package/lib/Types/Newsletter.js +0 -37
  407. package/lib/Utils/baileys-event-stream.js +0 -74
  408. package/lib/Utils/extended-messages.js +0 -285
  409. package/lib/Utils/lid-resolver.js +0 -81
  410. package/lib/Utils/mention.js +0 -137
@@ -1,72 +1,141 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.cleanMessage = void 0;
7
- exports.decryptPollVote = decryptPollVote;
8
- exports.shouldIncrementChatUnread = exports.isRealMessage = exports.getChatId = exports.default = void 0;
9
- var _index = require("../../WAProto/index.js");
10
- var _index2 = require("../Types/index.js");
11
- var _messages = require("../Utils/messages.js");
12
- var _index3 = require("../WABinary/index.js");
13
- var _crypto = require("./crypto.js");
14
- var _generics = require("./generics.js");
15
- var _history = require("./history.js");
16
- const REAL_MSG_STUB_TYPES = new Set([_index2.WAMessageStubType.CALL_MISSED_GROUP_VIDEO, _index2.WAMessageStubType.CALL_MISSED_GROUP_VOICE, _index2.WAMessageStubType.CALL_MISSED_VIDEO, _index2.WAMessageStubType.CALL_MISSED_VOICE]);
17
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([_index2.WAMessageStubType.GROUP_PARTICIPANT_ADD]);
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { WAMessageStubType } from '../Types/index.js';
4
+ import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
5
+ import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, isLidUser, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
+ import { aesDecryptGCM, hmacSign } from './crypto.js';
7
+ import { getKeyAuthor, toNumber } from './generics.js';
8
+ import { downloadAndProcessHistorySyncNotification } from './history.js';
9
+ import { buildMergedTcTokenIndexWrite, resolveTcTokenJid } from './tc-token-utils.js';
10
+ const REAL_MSG_STUB_TYPES = new Set([
11
+ WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
12
+ WAMessageStubType.CALL_MISSED_GROUP_VOICE,
13
+ WAMessageStubType.CALL_MISSED_VIDEO,
14
+ WAMessageStubType.CALL_MISSED_VOICE
15
+ ]);
16
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
17
+ async function storeTcTokensFromHistorySync(chats, signalRepository, keyStore, logger) {
18
+ const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
19
+ const candidates = [];
20
+ for (const chat of chats) {
21
+ const ts = chat.tcTokenTimestamp ? toNumber(chat.tcTokenTimestamp) : 0;
22
+ if (chat.tcToken?.length && ts > 0) {
23
+ const jid = jidNormalizedUser(chat.id);
24
+ const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
25
+ candidates.push({
26
+ storageJid,
27
+ token: Buffer.from(chat.tcToken),
28
+ ts,
29
+ senderTs: chat.tcTokenSenderTimestamp ? toNumber(chat.tcTokenSenderTimestamp) : undefined
30
+ });
31
+ }
32
+ }
33
+ if (!candidates.length) {
34
+ return;
35
+ }
36
+ const jids = candidates.map(c => c.storageJid);
37
+ const existing = await keyStore.get('tctoken', jids);
38
+ const entries = {};
39
+ for (const c of candidates) {
40
+ const existingEntry = existing[c.storageJid];
41
+ const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
42
+ if (existingTs > 0 && existingTs >= c.ts) {
43
+ continue;
44
+ }
45
+ entries[c.storageJid] = {
46
+ ...existingEntry,
47
+ token: c.token,
48
+ timestamp: String(c.ts),
49
+ ...(c.senderTs !== undefined ? { senderTimestamp: c.senderTs } : {})
50
+ };
51
+ }
52
+ if (Object.keys(entries).length) {
53
+ logger?.debug({ count: Object.keys(entries).length }, 'storing tctokens from history sync');
54
+ try {
55
+ // Include updated __index so cross-session pruning picks these JIDs up.
56
+ const indexWrite = await buildMergedTcTokenIndexWrite(keyStore, Object.keys(entries));
57
+ await keyStore.set({ tctoken: { ...entries, ...indexWrite } });
58
+ }
59
+ catch (err) {
60
+ logger?.warn({ err }, 'failed to store tctokens from history sync');
61
+ }
62
+ }
63
+ }
18
64
  /** Cleans a received message to further processing */
19
- const cleanMessage = (message, meId) => {
20
- // ensure remoteJid and participant doesn't have device or agent in it
21
- message.key.remoteJid = (0, _index3.jidNormalizedUser)(message.key.remoteJid);
22
- message.key.participant = message.key.participant ? (0, _index3.jidNormalizedUser)(message.key.participant) : undefined;
23
- const content = (0, _messages.normalizeMessageContent)(message.message);
24
- // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
25
- if (content?.reactionMessage) {
26
- normaliseKey(content.reactionMessage.key);
27
- }
28
- if (content?.pollUpdateMessage) {
29
- normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
30
- }
31
- function normaliseKey(msgKey) {
32
- // if the reaction is from another user
33
- // we've to correctly map the key to this user's perspective
34
- if (!message.key.fromMe) {
35
- // if the sender believed the message being reacted to is not from them
36
- // we've to correct the key to be from them, or some other participant
37
- msgKey.fromMe = !msgKey.fromMe ? (0, _index3.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId) :
38
- // if the message being reacted to, was from them
39
- // fromMe automatically becomes false
40
- false;
41
- // set the remoteJid to being the same as the chat the message came from
42
- msgKey.remoteJid = message.key.remoteJid;
43
- // set participant of the message
44
- msgKey.participant = msgKey.participant || message.key.participant;
65
+ export const cleanMessage = (message, meId, meLid) => {
66
+ // ensure remoteJid and participant doesn't have device or agent in it
67
+ if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
68
+ message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
69
+ }
70
+ else {
71
+ message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
72
+ }
73
+ if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
74
+ message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
75
+ }
76
+ else {
77
+ message.key.participant = jidNormalizedUser(message.key.participant);
78
+ }
79
+ const content = normalizeMessageContent(message.message);
80
+ // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
81
+ if (content?.reactionMessage) {
82
+ normaliseKey(content.reactionMessage.key);
83
+ }
84
+ if (content?.pollUpdateMessage) {
85
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
86
+ }
87
+ function normaliseKey(msgKey) {
88
+ // if the reaction is from another user
89
+ // we've to correctly map the key to this user's perspective
90
+ if (!message.key.fromMe) {
91
+ // if the sender believed the message being reacted to is not from them
92
+ // we've to correct the key to be from them, or some other participant
93
+ msgKey.fromMe = !msgKey.fromMe
94
+ ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
95
+ areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
96
+ : // if the message being reacted to, was from them
97
+ // fromMe automatically becomes false
98
+ false;
99
+ // set the remoteJid to being the same as the chat the message came from
100
+ // TODO: investigate inconsistencies
101
+ msgKey.remoteJid = message.key.remoteJid;
102
+ // set participant of the message
103
+ msgKey.participant = msgKey.participant || message.key.participant;
104
+ }
45
105
  }
46
- }
47
106
  };
48
- exports.cleanMessage = cleanMessage;
49
- const isRealMessage = (message, meId) => {
50
- const normalizedContent = (0, _messages.normalizeMessageContent)(message.message);
51
- const hasSomeContent = !!(0, _messages.getContentType)(normalizedContent);
52
- return (!!normalizedContent || REAL_MSG_STUB_TYPES.has(message.messageStubType) || REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) && message.messageStubParameters?.some(p => (0, _index3.areJidsSameUser)(meId, p))) && hasSomeContent && !normalizedContent?.protocolMessage && !normalizedContent?.reactionMessage && !normalizedContent?.pollUpdateMessage;
107
+ // TODO: target:audit AUDIT THIS FUNCTION AGAIN
108
+ export const isRealMessage = (message) => {
109
+ const normalizedContent = normalizeMessageContent(message.message);
110
+ const hasSomeContent = !!getContentType(normalizedContent);
111
+ return ((!!normalizedContent ||
112
+ REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
113
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
114
+ hasSomeContent &&
115
+ !normalizedContent?.protocolMessage &&
116
+ !normalizedContent?.reactionMessage &&
117
+ !normalizedContent?.pollUpdateMessage);
53
118
  };
54
- exports.isRealMessage = isRealMessage;
55
- const shouldIncrementChatUnread = message => !message.key.fromMe && !message.messageStubType;
119
+ export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
56
120
  /**
57
121
  * Get the ID of the chat from the given key.
58
122
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
59
123
  */
60
- exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
61
- const getChatId = ({
62
- remoteJid,
63
- participant,
64
- fromMe
65
- }) => {
66
- if ((0, _index3.isJidBroadcast)(remoteJid) && !(0, _index3.isJidStatusBroadcast)(remoteJid) && !fromMe) {
67
- return participant;
68
- }
69
- return remoteJid;
124
+ export const getChatId = ({ remoteJid, participant, fromMe }) => {
125
+ if (!remoteJid) {
126
+ throw new Boom('Cannot derive chat id: message key is missing remoteJid', {
127
+ data: { remoteJid, participant, fromMe }
128
+ });
129
+ }
130
+ if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
131
+ if (!participant) {
132
+ throw new Boom('Cannot derive chat id: broadcast message key is missing participant', {
133
+ data: { remoteJid, fromMe }
134
+ });
135
+ }
136
+ return participant;
137
+ }
138
+ return remoteJid;
70
139
  };
71
140
  /**
72
141
  * Decrypt a poll vote
@@ -74,380 +143,488 @@ const getChatId = ({
74
143
  * @param ctx additional info about the poll required for decryption
75
144
  * @returns list of SHA256 options
76
145
  */
77
- exports.getChatId = getChatId;
78
- function decryptPollVote({
79
- encPayload,
80
- encIv
81
- }, {
82
- pollCreatorJid,
83
- pollMsgId,
84
- pollEncKey,
85
- voterJid
86
- }) {
87
- const sign = Buffer.concat([toBinary(pollMsgId), toBinary(pollCreatorJid), toBinary(voterJid), toBinary('Poll Vote'), new Uint8Array([1])]);
88
- const key0 = (0, _crypto.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
89
- const decKey = (0, _crypto.hmacSign)(sign, key0, 'sha256');
90
- const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
91
- const decrypted = (0, _crypto.aesDecryptGCM)(encPayload, decKey, encIv, aad);
92
- return _index.proto.Message.PollVoteMessage.decode(decrypted);
93
- function toBinary(txt) {
94
- return Buffer.from(txt);
95
- }
146
+ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
147
+ const sign = Buffer.concat([
148
+ toBinary(pollMsgId),
149
+ toBinary(pollCreatorJid),
150
+ toBinary(voterJid),
151
+ toBinary('Poll Vote'),
152
+ new Uint8Array([1])
153
+ ]);
154
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
155
+ const decKey = hmacSign(sign, key0, 'sha256');
156
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
157
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
158
+ return proto.Message.PollVoteMessage.decode(decrypted);
159
+ function toBinary(txt) {
160
+ return Buffer.from(txt);
161
+ }
162
+ }
163
+ /**
164
+ * Decrypt an event response
165
+ * @param response encrypted event response
166
+ * @param ctx additional info about the event required for decryption
167
+ * @returns event response message
168
+ */
169
+ export function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
170
+ const sign = Buffer.concat([
171
+ toBinary(eventMsgId),
172
+ toBinary(eventCreatorJid),
173
+ toBinary(responderJid),
174
+ toBinary('Event Response'),
175
+ new Uint8Array([1])
176
+ ]);
177
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256');
178
+ const decKey = hmacSign(sign, key0, 'sha256');
179
+ const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
180
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
181
+ return proto.Message.EventResponseMessage.decode(decrypted);
182
+ function toBinary(txt) {
183
+ return Buffer.from(txt);
184
+ }
96
185
  }
97
- const processMessage = async (message, {
98
- shouldProcessHistoryMsg,
99
- placeholderResendCache,
100
- ev,
101
- creds,
102
- signalRepository,
103
- keyStore,
104
- logger,
105
- options
106
- }) => {
107
- const meId = creds.me.id;
108
- const {
109
- accountSettings
110
- } = creds;
111
- const chat = {
112
- id: (0, _index3.jidNormalizedUser)(getChatId(message.key))
113
- };
114
- const isRealMsg = isRealMessage(message, meId);
115
- if (isRealMsg) {
116
- chat.messages = [{
117
- message
118
- }];
119
- chat.conversationTimestamp = (0, _generics.toNumber)(message.messageTimestamp);
120
- // only increment unread count if not CIPHERTEXT and from another person
121
- if (shouldIncrementChatUnread(message)) {
122
- chat.unreadCount = (chat.unreadCount || 0) + 1;
186
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
187
+ const meId = creds.me.id;
188
+ const { accountSettings } = creds;
189
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) };
190
+ const isRealMsg = isRealMessage(message);
191
+ if (isRealMsg) {
192
+ chat.messages = [{ message }];
193
+ chat.conversationTimestamp = toNumber(message.messageTimestamp);
194
+ // only increment unread count if not CIPHERTEXT and from another person
195
+ if (shouldIncrementChatUnread(message)) {
196
+ chat.unreadCount = (chat.unreadCount || 0) + 1;
197
+ }
123
198
  }
124
- }
125
- const content = (0, _messages.normalizeMessageContent)(message.message);
126
- // unarchive chat if it's a real message, or someone reacted to our message
127
- // and we've the unarchive chats setting on
128
- if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
129
- chat.archived = false;
130
- chat.readOnly = false;
131
- }
132
- const protocolMsg = content?.protocolMessage;
133
- if (protocolMsg) {
134
- switch (protocolMsg.type) {
135
- case _index.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
136
- const histNotification = protocolMsg.historySyncNotification;
137
- const process = shouldProcessHistoryMsg;
138
- const isLatest = !creds.processedHistoryMessages?.length;
139
- logger?.info({
140
- histNotification,
141
- process,
142
- id: message.key.id,
143
- isLatest
144
- }, 'got history notification');
145
- if (process) {
146
- if (histNotification.syncType !== _index.proto.HistorySync.HistorySyncType.ON_DEMAND) {
147
- ev.emit('creds.update', {
148
- processedHistoryMessages: [...(creds.processedHistoryMessages || []), {
149
- key: message.key,
150
- messageTimestamp: message.messageTimestamp
151
- }]
152
- });
153
- }
154
- const data = await (0, _history.downloadAndProcessHistorySyncNotification)(histNotification, options);
155
- ev.emit('messaging-history.set', {
156
- ...data,
157
- isLatest: histNotification.syncType !== _index.proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
158
- peerDataRequestSessionId: histNotification.peerDataRequestSessionId
159
- });
199
+ const content = normalizeMessageContent(message.message);
200
+ // unarchive chat if it's a real message, or someone reacted to our message
201
+ // and we've the unarchive chats setting on
202
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
203
+ chat.archived = false;
204
+ chat.readOnly = false;
205
+ }
206
+ const protocolMsg = content?.protocolMessage;
207
+ if (protocolMsg) {
208
+ // Mirror whatsmeow's `handleProtocolMessage` guard, but applied only to
209
+ // the protocol message types that originate from our own device — an
210
+ // attacker could otherwise spoof any of these to manipulate local state.
211
+ //
212
+ // Self-only types (drop if `!fromMe`):
213
+ // - HISTORY_SYNC_NOTIFICATION (our phone driving history sync)
214
+ // - APP_STATE_SYNC_KEY_SHARE (key share between our devices)
215
+ // - LID_MIGRATION_MAPPING_SYNC (server-initiated via our phone)
216
+ // - PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE (response from our phone to our PDO request)
217
+ //
218
+ // Cross-user types (must NOT be dropped — legitimately arrive from others):
219
+ // - REVOKE
220
+ // - MESSAGE_EDIT
221
+ // - EPHEMERAL_SETTING
222
+ // - GROUP_MEMBER_LABEL_CHANGE
223
+ //
224
+ // See https://github.com/tulir/whatsmeow/blob/8d3700152a/message.go#L842-L845
225
+ // for the reference architecture — whatsmeow's `handleProtocolMessage`
226
+ // only contains self-only types because edits are unwrapped from
227
+ // `EditedMessage` BEFORE this dispatch and revokes aren't routed here.
228
+ const SELF_ONLY_TYPES = new Set([
229
+ proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION,
230
+ proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE,
231
+ proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC,
232
+ proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
233
+ ]);
234
+ if (protocolMsg.type !== null &&
235
+ protocolMsg.type !== undefined &&
236
+ SELF_ONLY_TYPES.has(protocolMsg.type) &&
237
+ !message.key.fromMe) {
238
+ logger?.warn({ msgId: message.key.id, type: protocolMsg.type, from: message.key.participant || message.key.remoteJid }, 'dropping spoofed self-only protocolMessage from non-self origin');
239
+ return;
160
240
  }
161
- break;
162
- case _index.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
163
- const keys = protocolMsg.appStateSyncKeyShare.keys;
164
- if (keys?.length) {
165
- let newAppStateSyncKeyId = '';
166
- await keyStore.transaction(async () => {
167
- const newKeys = [];
168
- for (const {
169
- keyData,
170
- keyId
171
- } of keys) {
172
- const strKeyId = Buffer.from(keyId.keyId).toString('base64');
173
- newKeys.push(strKeyId);
174
- await keyStore.set({
175
- 'app-state-sync-key': {
176
- [strKeyId]: keyData
241
+ switch (protocolMsg.type) {
242
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
243
+ const histNotification = protocolMsg.historySyncNotification;
244
+ const process = shouldProcessHistoryMsg;
245
+ const isLatest = !creds.processedHistoryMessages?.length;
246
+ logger?.info({
247
+ histNotification,
248
+ process,
249
+ id: message.key.id,
250
+ isLatest
251
+ }, 'got history notification');
252
+ if (process) {
253
+ // TODO: investigate
254
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
255
+ ev.emit('creds.update', {
256
+ processedHistoryMessages: [
257
+ ...(creds.processedHistoryMessages || []),
258
+ { key: message.key, messageTimestamp: message.messageTimestamp }
259
+ ]
260
+ });
261
+ }
262
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options, logger);
263
+ if (data.lidPnMappings?.length) {
264
+ logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
265
+ await signalRepository.lidMapping
266
+ .storeLIDPNMappings(data.lidPnMappings)
267
+ .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
268
+ }
269
+ await storeTcTokensFromHistorySync(data.chats, signalRepository, keyStore, logger);
270
+ ev.emit('messaging-history.set', {
271
+ ...data,
272
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
273
+ chunkOrder: histNotification.chunkOrder,
274
+ peerDataRequestSessionId: histNotification.peerDataRequestSessionId
275
+ });
276
+ }
277
+ break;
278
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
279
+ const keys = protocolMsg.appStateSyncKeyShare.keys;
280
+ if (keys?.length) {
281
+ let newAppStateSyncKeyId = '';
282
+ await keyStore.transaction(async () => {
283
+ const newKeys = [];
284
+ for (const { keyData, keyId } of keys) {
285
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64');
286
+ newKeys.push(strKeyId);
287
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
288
+ newAppStateSyncKeyId = strKeyId;
289
+ }
290
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
291
+ }, meId);
292
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
293
+ }
294
+ else {
295
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
296
+ }
297
+ break;
298
+ case proto.Message.ProtocolMessage.Type.REVOKE:
299
+ ev.emit('messages.update', [
300
+ {
301
+ key: {
302
+ ...message.key,
303
+ id: protocolMsg.key.id
304
+ },
305
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
306
+ }
307
+ ]);
308
+ break;
309
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
310
+ Object.assign(chat, {
311
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
312
+ ephemeralExpiration: protocolMsg.ephemeralExpiration || null
313
+ });
314
+ break;
315
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
316
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
317
+ if (response) {
318
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
319
+ const peerDataOperationResult = response.peerDataOperationResult || [];
320
+ for (const result of peerDataOperationResult) {
321
+ const retryResponse = result?.placeholderMessageResendResponse;
322
+ //eslint-disable-next-line max-depth
323
+ if (!retryResponse?.webMessageInfoBytes) {
324
+ continue;
325
+ }
326
+ //eslint-disable-next-line max-depth
327
+ try {
328
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
329
+ const msgId = webMessageInfo.key?.id;
330
+ // Retrieve cached original message data (preserves LID details,
331
+ // timestamps, etc. that the phone may omit in its PDO response)
332
+ const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
333
+ //eslint-disable-next-line max-depth
334
+ if (msgId) {
335
+ await placeholderResendCache?.del(msgId);
336
+ }
337
+ let finalMsg;
338
+ //eslint-disable-next-line max-depth
339
+ if (cachedData && typeof cachedData === 'object') {
340
+ // Apply decoded message content onto cached metadata (preserves LID etc.)
341
+ cachedData.message = webMessageInfo.message;
342
+ //eslint-disable-next-line max-depth
343
+ if (webMessageInfo.messageTimestamp) {
344
+ cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
345
+ }
346
+ finalMsg = cachedData;
347
+ }
348
+ else {
349
+ finalMsg = webMessageInfo;
350
+ }
351
+ logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
352
+ ev.emit('messages.upsert', {
353
+ messages: [finalMsg],
354
+ type: 'notify',
355
+ requestId: response.stanzaId
356
+ });
357
+ }
358
+ catch (err) {
359
+ logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
360
+ }
361
+ }
362
+ }
363
+ break;
364
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
365
+ ev.emit('messages.update', [
366
+ {
367
+ // flip the sender / fromMe properties because they're in the perspective of the sender
368
+ key: { ...message.key, id: protocolMsg.key?.id },
369
+ update: {
370
+ message: {
371
+ editedMessage: {
372
+ message: protocolMsg.editedMessage
373
+ }
374
+ },
375
+ messageTimestamp: protocolMsg.timestampMs
376
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
377
+ : message.messageTimestamp
378
+ }
379
+ }
380
+ ]);
381
+ break;
382
+ case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
383
+ const labelAssociationMsg = protocolMsg.memberLabel;
384
+ if (labelAssociationMsg?.label) {
385
+ ev.emit('group.member-tag.update', {
386
+ groupId: chat.id,
387
+ label: labelAssociationMsg.label,
388
+ participant: message.key.participant,
389
+ participantAlt: message.key.participantAlt,
390
+ messageTimestamp: Number(message.messageTimestamp)
391
+ });
392
+ }
393
+ break;
394
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
395
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
396
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
397
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
398
+ const pairs = [];
399
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
400
+ const lid = latestLid || assignedLid;
401
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
402
+ }
403
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
404
+ if (pairs.length) {
405
+ for (const { pn, lid } of pairs) {
406
+ await signalRepository.migrateSession(pn, lid);
407
+ }
177
408
  }
178
- });
179
- newAppStateSyncKeyId = strKeyId;
180
- }
181
- logger?.info({
182
- newAppStateSyncKeyId,
183
- newKeys
184
- }, 'injecting new app state sync keys');
185
- }, meId);
186
- ev.emit('creds.update', {
187
- myAppStateKeyId: newAppStateSyncKeyId
188
- });
189
- } else {
190
- logger?.info({
191
- protocolMsg
192
- }, 'recv app state sync with 0 keys');
193
409
  }
194
- break;
195
- case _index.proto.Message.ProtocolMessage.Type.REVOKE:
196
- ev.emit('messages.update', [{
197
- key: {
198
- ...message.key,
199
- id: protocolMsg.key.id
200
- },
201
- update: {
202
- message: null,
203
- messageStubType: _index2.WAMessageStubType.REVOKE,
410
+ }
411
+ else if (content?.reactionMessage) {
412
+ const reaction = {
413
+ ...content.reactionMessage,
204
414
  key: message.key
205
- }
206
- }]);
207
- break;
208
- case _index.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
209
- Object.assign(chat, {
210
- ephemeralSettingTimestamp: (0, _generics.toNumber)(message.messageTimestamp),
211
- ephemeralExpiration: protocolMsg.ephemeralExpiration || null
212
- });
213
- break;
214
- case _index.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
215
- const response = protocolMsg.peerDataOperationRequestResponseMessage;
216
- if (response) {
217
- placeholderResendCache?.del(response.stanzaId);
218
- // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
219
- const {
220
- peerDataOperationResult
221
- } = response;
222
- for (const result of peerDataOperationResult) {
223
- const {
224
- placeholderMessageResendResponse: retryResponse
225
- } = result;
226
- //eslint-disable-next-line max-depth
227
- if (retryResponse) {
228
- const webMessageInfo = _index.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
229
- // wait till another upsert event is available, don't want it to be part of the PDO response message
230
- setTimeout(() => {
231
- ev.emit('messages.upsert', {
232
- messages: [webMessageInfo],
233
- type: 'notify',
234
- requestId: response.stanzaId
235
- });
236
- }, 500);
415
+ };
416
+ ev.emit('messages.reaction', [
417
+ {
418
+ reaction,
419
+ key: content.reactionMessage?.key
420
+ }
421
+ ]);
422
+ }
423
+ else if (content?.encEventResponseMessage) {
424
+ const encEventResponse = content.encEventResponseMessage;
425
+ const creationMsgKey = encEventResponse.eventCreationMessageKey;
426
+ // we need to fetch the event creation message to get the event enc key
427
+ const eventMsg = await getMessage(creationMsgKey);
428
+ if (eventMsg) {
429
+ try {
430
+ const meIdNormalised = jidNormalizedUser(meId);
431
+ // all jids need to be PN
432
+ const eventCreatorKey = creationMsgKey.participant || creationMsgKey.remoteJid;
433
+ const eventCreatorPn = isLidUser(eventCreatorKey)
434
+ ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
435
+ : eventCreatorKey;
436
+ const eventCreatorJid = getKeyAuthor({ remoteJid: jidNormalizedUser(eventCreatorPn), fromMe: meIdNormalised === eventCreatorPn }, meIdNormalised);
437
+ const responderJid = getKeyAuthor(message.key, meIdNormalised);
438
+ const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
439
+ if (!eventEncKey) {
440
+ logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
441
+ }
442
+ else {
443
+ const responseMsg = decryptEventResponse(encEventResponse, {
444
+ eventEncKey,
445
+ eventCreatorJid,
446
+ eventMsgId: creationMsgKey.id,
447
+ responderJid
448
+ });
449
+ const eventResponse = {
450
+ eventResponseMessageKey: message.key,
451
+ senderTimestampMs: responseMsg.timestampMs,
452
+ response: responseMsg
453
+ };
454
+ ev.emit('messages.update', [
455
+ {
456
+ key: creationMsgKey,
457
+ update: {
458
+ eventResponses: [eventResponse]
459
+ }
460
+ }
461
+ ]);
462
+ }
463
+ }
464
+ catch (err) {
465
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
237
466
  }
238
- }
239
467
  }
240
- break;
241
- case _index.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
242
- ev.emit('messages.update', [{
243
- // flip the sender / fromMe properties because they're in the perspective of the sender
244
- key: {
245
- ...message.key,
246
- id: protocolMsg.key?.id
247
- },
248
- update: {
249
- message: {
250
- editedMessage: {
251
- message: protocolMsg.editedMessage
252
- }
253
- },
254
- messageTimestamp: protocolMsg.timestampMs ? Math.floor((0, _generics.toNumber)(protocolMsg.timestampMs) / 1000) : message.messageTimestamp
255
- }
256
- }]);
257
- break;
258
- case _index.proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
259
- const lidMappingStore = signalRepository.getLIDMappingStore();
260
- const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
261
- const {
262
- pnToLidMappings,
263
- chatDbMigrationTimestamp
264
- } = _index.proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
265
- logger?.debug({
266
- pnToLidMappings,
267
- chatDbMigrationTimestamp
268
- }, 'got lid mappings and chat db migration timestamp');
269
- const pairs = [];
270
- for (const {
271
- pn,
272
- latestLid,
273
- assignedLid
274
- } of pnToLidMappings) {
275
- const lid = latestLid || assignedLid;
276
- pairs.push({
277
- lid: `${lid}@lid`,
278
- pn: `${pn}@s.whatsapp.net`
279
- });
468
+ else {
469
+ logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
280
470
  }
281
- await lidMappingStore.storeLIDPNMappings(pairs);
282
471
  }
283
- } else if (content?.reactionMessage) {
284
- const reaction = {
285
- ...content.reactionMessage,
286
- key: message.key
287
- };
288
- ev.emit('messages.reaction', [{
289
- reaction,
290
- key: content.reactionMessage?.key
291
- }]);
292
- } else if (message.messageStubType) {
293
- const jid = message.key?.remoteJid;
294
- //let actor = whatsappID (message.participant)
295
- let participants;
296
- const emitParticipantsUpdate = action => ev.emit('group-participants.update', {
297
- id: jid,
298
- author: message.participant,
299
- participants,
300
- action
301
- });
302
- const emitGroupUpdate = update => {
303
- ev.emit('groups.update', [{
304
- id: jid,
305
- ...update,
306
- author: message.participant ?? undefined
307
- }]);
308
- };
309
- const emitGroupRequestJoin = (participant, action, method) => {
310
- ev.emit('group.join-request', {
311
- id: jid,
312
- author: message.participant,
313
- participant,
314
- action,
315
- method: method
316
- });
317
- };
318
- const participantsIncludesMe = () => participants.find(jid => (0, _index3.areJidsSameUser)(meId, jid));
319
- switch (message.messageStubType) {
320
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
321
- participants = message.messageStubParameters || [];
322
- emitParticipantsUpdate('modify');
323
- break;
324
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
325
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
326
- participants = message.messageStubParameters || [];
327
- emitParticipantsUpdate('remove');
328
- // mark the chat read only if you left the group
329
- if (participantsIncludesMe()) {
330
- chat.readOnly = true;
472
+ else if (message.messageStubType) {
473
+ const jid = message.key?.remoteJid;
474
+ //let actor = whatsappID (message.participant)
475
+ let participants;
476
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
477
+ id: jid,
478
+ author: message.key.participant,
479
+ authorPn: message.key.participantAlt,
480
+ authorUsername: message.key.participantUsername,
481
+ participants,
482
+ action
483
+ });
484
+ const emitGroupUpdate = (update) => {
485
+ ev.emit('groups.update', [
486
+ {
487
+ id: jid,
488
+ ...update,
489
+ author: message.key.participant ?? undefined,
490
+ authorPn: message.key.participantAlt,
491
+ authorUsername: message.key.participantUsername
492
+ }
493
+ ]);
494
+ };
495
+ const emitGroupRequestJoin = (participant, action, method) => {
496
+ ev.emit('group.join-request', {
497
+ id: jid,
498
+ author: message.key.participant,
499
+ authorPn: message.key.participantAlt,
500
+ authorUsername: message.key.participantUsername,
501
+ participant: participant.lid,
502
+ participantPn: participant.pn,
503
+ action,
504
+ method: method
505
+ });
506
+ };
507
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
508
+ switch (message.messageStubType) {
509
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
510
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
511
+ emitParticipantsUpdate('modify');
512
+ break;
513
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
514
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
515
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
516
+ emitParticipantsUpdate('remove');
517
+ // mark the chat read only if you left the group
518
+ if (participantsIncludesMe()) {
519
+ chat.readOnly = true;
520
+ }
521
+ break;
522
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
523
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
524
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
525
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
526
+ if (participantsIncludesMe()) {
527
+ chat.readOnly = false;
528
+ }
529
+ emitParticipantsUpdate('add');
530
+ break;
531
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
532
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
533
+ emitParticipantsUpdate('demote');
534
+ break;
535
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
536
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
537
+ emitParticipantsUpdate('promote');
538
+ break;
539
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
540
+ const announceValue = message.messageStubParameters?.[0];
541
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
542
+ break;
543
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
544
+ const restrictValue = message.messageStubParameters?.[0];
545
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
546
+ break;
547
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
548
+ const name = message.messageStubParameters?.[0];
549
+ chat.name = name;
550
+ emitGroupUpdate({ subject: name });
551
+ break;
552
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
553
+ const description = message.messageStubParameters?.[0];
554
+ chat.description = description;
555
+ emitGroupUpdate({ desc: description });
556
+ break;
557
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
558
+ const code = message.messageStubParameters?.[0];
559
+ emitGroupUpdate({ inviteCode: code });
560
+ break;
561
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
562
+ const memberAddValue = message.messageStubParameters?.[0];
563
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
564
+ break;
565
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
566
+ const approvalMode = message.messageStubParameters?.[0];
567
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
568
+ break;
569
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
570
+ const participant = JSON.parse(message.messageStubParameters?.[0]);
571
+ const action = message.messageStubParameters?.[1];
572
+ const method = message.messageStubParameters?.[2];
573
+ emitGroupRequestJoin(participant, action, method);
574
+ break;
331
575
  }
332
- break;
333
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_ADD:
334
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
335
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
336
- participants = message.messageStubParameters || [];
337
- if (participantsIncludesMe()) {
338
- chat.readOnly = false;
576
+ } /* else if(content?.pollUpdateMessage) {
577
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
578
+ // we need to fetch the poll creation message to get the poll enc key
579
+ // TODO: make standalone, remove getMessage reference
580
+ // TODO: Remove entirely
581
+ const pollMsg = await getMessage(creationMsgKey)
582
+ if(pollMsg) {
583
+ const meIdNormalised = jidNormalizedUser(meId)
584
+ const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
585
+ const voterJid = getKeyAuthor(message.key, meIdNormalised)
586
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
587
+
588
+ try {
589
+ const voteMsg = decryptPollVote(
590
+ content.pollUpdateMessage.vote!,
591
+ {
592
+ pollEncKey,
593
+ pollCreatorJid,
594
+ pollMsgId: creationMsgKey.id!,
595
+ voterJid,
596
+ }
597
+ )
598
+ ev.emit('messages.update', [
599
+ {
600
+ key: creationMsgKey,
601
+ update: {
602
+ pollUpdates: [
603
+ {
604
+ pollUpdateMessageKey: message.key,
605
+ vote: voteMsg,
606
+ senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
607
+ }
608
+ ]
609
+ }
610
+ }
611
+ ])
612
+ } catch(err) {
613
+ logger?.warn(
614
+ { err, creationMsgKey },
615
+ 'failed to decrypt poll vote'
616
+ )
617
+ }
618
+ } else {
619
+ logger?.warn(
620
+ { creationMsgKey },
621
+ 'poll creation message not found, cannot decrypt update'
622
+ )
339
623
  }
340
- emitParticipantsUpdate('add');
341
- break;
342
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
343
- participants = message.messageStubParameters || [];
344
- emitParticipantsUpdate('demote');
345
- break;
346
- case _index2.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
347
- participants = message.messageStubParameters || [];
348
- emitParticipantsUpdate('promote');
349
- break;
350
- case _index2.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
351
- const announceValue = message.messageStubParameters?.[0];
352
- emitGroupUpdate({
353
- announce: announceValue === 'true' || announceValue === 'on'
354
- });
355
- break;
356
- case _index2.WAMessageStubType.GROUP_CHANGE_RESTRICT:
357
- const restrictValue = message.messageStubParameters?.[0];
358
- emitGroupUpdate({
359
- restrict: restrictValue === 'true' || restrictValue === 'on'
360
- });
361
- break;
362
- case _index2.WAMessageStubType.GROUP_CHANGE_SUBJECT:
363
- const name = message.messageStubParameters?.[0];
364
- chat.name = name;
365
- emitGroupUpdate({
366
- subject: name
367
- });
368
- break;
369
- case _index2.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
370
- const description = message.messageStubParameters?.[0];
371
- chat.description = description;
372
- emitGroupUpdate({
373
- desc: description
374
- });
375
- break;
376
- case _index2.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
377
- const code = message.messageStubParameters?.[0];
378
- emitGroupUpdate({
379
- inviteCode: code
380
- });
381
- break;
382
- case _index2.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
383
- const memberAddValue = message.messageStubParameters?.[0];
384
- emitGroupUpdate({
385
- memberAddMode: memberAddValue === 'all_member_add'
386
- });
387
- break;
388
- case _index2.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
389
- const approvalMode = message.messageStubParameters?.[0];
390
- emitGroupUpdate({
391
- joinApprovalMode: approvalMode === 'on'
392
- });
393
- break;
394
- case _index2.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
395
- const participant = message.messageStubParameters?.[0];
396
- const action = message.messageStubParameters?.[1];
397
- const method = message.messageStubParameters?.[2];
398
- emitGroupRequestJoin(participant, action, method);
399
- break;
624
+ } */
625
+ if (Object.keys(chat).length > 1) {
626
+ ev.emit('chats.update', [chat]);
400
627
  }
401
- } /* else if(content?.pollUpdateMessage) {
402
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
403
- // we need to fetch the poll creation message to get the poll enc key
404
- // TODO: make standalone, remove getMessage reference
405
- // TODO: Remove entirely
406
- const pollMsg = await getMessage(creationMsgKey)
407
- if(pollMsg) {
408
- const meIdNormalised = jidNormalizedUser(meId)
409
- const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
410
- const voterJid = getKeyAuthor(message.key, meIdNormalised)
411
- const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
412
- try {
413
- const voteMsg = decryptPollVote(
414
- content.pollUpdateMessage.vote!,
415
- {
416
- pollEncKey,
417
- pollCreatorJid,
418
- pollMsgId: creationMsgKey.id!,
419
- voterJid,
420
- }
421
- )
422
- ev.emit('messages.update', [
423
- {
424
- key: creationMsgKey,
425
- update: {
426
- pollUpdates: [
427
- {
428
- pollUpdateMessageKey: message.key,
429
- vote: voteMsg,
430
- senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
431
- }
432
- ]
433
- }
434
- }
435
- ])
436
- } catch(err) {
437
- logger?.warn(
438
- { err, creationMsgKey },
439
- 'failed to decrypt poll vote'
440
- )
441
- }
442
- } else {
443
- logger?.warn(
444
- { creationMsgKey },
445
- 'poll creation message not found, cannot decrypt update'
446
- )
447
- }
448
- } */
449
- if (Object.keys(chat).length > 1) {
450
- ev.emit('chats.update', [chat]);
451
- }
452
628
  };
453
- var _default = exports.default = processMessage; //# sourceMappingURL=process-message.js.map
629
+ export default processMessage;
630
+ //# sourceMappingURL=process-message.js.map