ruby-baileys 0.0.0-stage → 1.5.17

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 (296) hide show
  1. package/EXPERIMENTAL.md +350 -0
  2. package/LICENSE +23 -0
  3. package/NOTICE.md +14 -0
  4. package/README.md +6265 -2
  5. package/WAProto/GenerateStatics.sh +3 -0
  6. package/WAProto/WAProto.proto +5479 -0
  7. package/WAProto/fix-imports.js +81 -0
  8. package/WAProto/index.d.ts +16877 -0
  9. package/WAProto/index.js +122159 -0
  10. package/assets/ruby_aspirant.jpg +0 -0
  11. package/assets/ruby_aspirant_4k.jpg +88 -0
  12. package/assets/ruby_aspirant_full.jpg +0 -0
  13. package/assets/ruby_aspirant_render.png +1 -0
  14. package/assets/ruby_aspirants_hd.jpg +0 -0
  15. package/assets/thumb.jpg +0 -0
  16. package/engine-requirements.js +14 -0
  17. package/index.cjs +29 -0
  18. package/index.d.ts +2 -0
  19. package/package.json +178 -4
  20. package/src/Defaults/index.d.ts +153 -0
  21. package/src/Defaults/index.js +165 -0
  22. package/src/MessageBuilder/bot-signature.d.ts +22 -0
  23. package/src/MessageBuilder/bot-signature.js +123 -0
  24. package/src/MessageBuilder/extras.d.ts +396 -0
  25. package/src/MessageBuilder/extras.js +1229 -0
  26. package/src/MessageBuilder/index.d.ts +210 -0
  27. package/src/MessageBuilder/index.js +3521 -0
  28. package/src/MessageBuilder/metaai.d.ts +438 -0
  29. package/src/MessageBuilder/metaai.js +891 -0
  30. package/src/Signal/Group/ciphertext-message.d.ts +10 -0
  31. package/src/Signal/Group/ciphertext-message.js +12 -0
  32. package/src/Signal/Group/group-session-builder.d.ts +8 -0
  33. package/src/Signal/Group/group-session-builder.js +28 -0
  34. package/src/Signal/Group/group_cipher.d.ts +11 -0
  35. package/src/Signal/Group/group_cipher.js +79 -0
  36. package/src/Signal/Group/index.d.ts +12 -0
  37. package/src/Signal/Group/index.js +12 -0
  38. package/src/Signal/Group/keyhelper.d.ts +7 -0
  39. package/src/Signal/Group/keyhelper.js +18 -0
  40. package/src/Signal/Group/sender-chain-key.d.ts +14 -0
  41. package/src/Signal/Group/sender-chain-key.js +26 -0
  42. package/src/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  43. package/src/Signal/Group/sender-key-distribution-message.js +63 -0
  44. package/src/Signal/Group/sender-key-message.d.ts +19 -0
  45. package/src/Signal/Group/sender-key-message.js +66 -0
  46. package/src/Signal/Group/sender-key-name.d.ts +12 -0
  47. package/src/Signal/Group/sender-key-name.js +48 -0
  48. package/src/Signal/Group/sender-key-record.d.ts +13 -0
  49. package/src/Signal/Group/sender-key-record.js +41 -0
  50. package/src/Signal/Group/sender-key-state.d.ts +17 -0
  51. package/src/Signal/Group/sender-key-state.js +84 -0
  52. package/src/Signal/Group/sender-message-key.d.ts +12 -0
  53. package/src/Signal/Group/sender-message-key.js +26 -0
  54. package/src/Signal/libsignal.d.ts +55 -0
  55. package/src/Signal/libsignal.js +429 -0
  56. package/src/Signal/lid-mapping.d.ts +21 -0
  57. package/src/Signal/lid-mapping.js +275 -0
  58. package/src/Socket/Client/index.d.ts +3 -0
  59. package/src/Socket/Client/index.js +3 -0
  60. package/src/Socket/Client/types.d.ts +6 -0
  61. package/src/Socket/Client/types.js +10 -0
  62. package/src/Socket/Client/websocket.d.ts +13 -0
  63. package/src/Socket/Client/websocket.js +54 -0
  64. package/src/Socket/business.d.ts +432 -0
  65. package/src/Socket/business.js +380 -0
  66. package/src/Socket/chats.d.ts +248 -0
  67. package/src/Socket/chats.js +1485 -0
  68. package/src/Socket/communities.d.ts +599 -0
  69. package/src/Socket/communities.js +422 -0
  70. package/src/Socket/groups.d.ts +299 -0
  71. package/src/Socket/groups.js +340 -0
  72. package/src/Socket/index.d.ts +582 -0
  73. package/src/Socket/index.js +48 -0
  74. package/src/Socket/messages-recv.d.ts +371 -0
  75. package/src/Socket/messages-recv.js +1803 -0
  76. package/src/Socket/messages-send.d.ts +391 -0
  77. package/src/Socket/messages-send.js +1575 -0
  78. package/src/Socket/mex.d.ts +2 -0
  79. package/src/Socket/mex.js +45 -0
  80. package/src/Socket/newsletter.d.ts +469 -0
  81. package/src/Socket/newsletter.js +643 -0
  82. package/src/Socket/socket.d.ts +78 -0
  83. package/src/Socket/socket.js +1088 -0
  84. package/src/Store/index.d.ts +4 -0
  85. package/src/Store/index.js +4 -0
  86. package/src/Store/make-in-memory-store.d.ts +63 -0
  87. package/src/Store/make-in-memory-store.js +398 -0
  88. package/src/Store/make-ordered-dictionary.d.ts +13 -0
  89. package/src/Store/make-ordered-dictionary.js +79 -0
  90. package/src/Store/object-repository.d.ts +11 -0
  91. package/src/Store/object-repository.js +24 -0
  92. package/src/Types/Auth.d.ts +2 -0
  93. package/src/Types/Auth.js +2 -0
  94. package/src/Types/Bussines.d.ts +2 -0
  95. package/src/Types/Bussines.js +2 -0
  96. package/src/Types/Call.d.ts +2 -0
  97. package/src/Types/Call.js +2 -0
  98. package/src/Types/Chat.d.ts +3 -0
  99. package/src/Types/Chat.js +25 -0
  100. package/src/Types/Contact.d.ts +2 -0
  101. package/src/Types/Contact.js +2 -0
  102. package/src/Types/Events.d.ts +2 -0
  103. package/src/Types/Events.js +1 -0
  104. package/src/Types/GroupMetadata.d.ts +6 -0
  105. package/src/Types/GroupMetadata.js +7 -0
  106. package/src/Types/Label.d.ts +3 -0
  107. package/src/Types/Label.js +25 -0
  108. package/src/Types/LabelAssociation.d.ts +3 -0
  109. package/src/Types/LabelAssociation.js +7 -0
  110. package/src/Types/Message.d.ts +14 -0
  111. package/src/Types/Message.js +24 -0
  112. package/src/Types/Mex.d.ts +3 -0
  113. package/src/Types/Mex.js +96 -0
  114. package/src/Types/Product.d.ts +2 -0
  115. package/src/Types/Product.js +2 -0
  116. package/src/Types/Signal.d.ts +2 -0
  117. package/src/Types/Signal.js +1 -0
  118. package/src/Types/Socket.d.ts +2 -0
  119. package/src/Types/Socket.js +1 -0
  120. package/src/Types/State.d.ts +6 -0
  121. package/src/Types/State.js +55 -0
  122. package/src/Types/USync.d.ts +2 -0
  123. package/src/Types/USync.js +1 -0
  124. package/src/Types/index.d.ts +14 -0
  125. package/src/Types/index.js +26 -0
  126. package/src/Utils/auth-store.d.ts +30 -0
  127. package/src/Utils/auth-store.js +77 -0
  128. package/src/Utils/auth-utils.d.ts +59 -0
  129. package/src/Utils/auth-utils.js +274 -0
  130. package/src/Utils/browser-utils.d.ts +10 -0
  131. package/src/Utils/browser-utils.js +29 -0
  132. package/src/Utils/business.d.ts +50 -0
  133. package/src/Utils/business.js +227 -0
  134. package/src/Utils/chat-utils.d.ts +409 -0
  135. package/src/Utils/chat-utils.js +847 -0
  136. package/src/Utils/companion-reg-client-utils.d.ts +5 -0
  137. package/src/Utils/companion-reg-client-utils.js +40 -0
  138. package/src/Utils/crypto.d.ts +40 -0
  139. package/src/Utils/crypto.js +111 -0
  140. package/src/Utils/decode-wa-message.d.ts +100 -0
  141. package/src/Utils/decode-wa-message.js +374 -0
  142. package/src/Utils/event-buffer.d.ts +23 -0
  143. package/src/Utils/event-buffer.js +625 -0
  144. package/src/Utils/generics.d.ts +64 -0
  145. package/src/Utils/generics.js +376 -0
  146. package/src/Utils/group-metadata-cache.d.ts +5 -0
  147. package/src/Utils/group-metadata-cache.js +26 -0
  148. package/src/Utils/history.d.ts +76 -0
  149. package/src/Utils/history.js +132 -0
  150. package/src/Utils/html-app.d.ts +19 -0
  151. package/src/Utils/html-app.js +97 -0
  152. package/src/Utils/html-multiplayer.d.ts +10 -0
  153. package/src/Utils/html-multiplayer.js +95 -0
  154. package/src/Utils/identity-change-handler.d.ts +14 -0
  155. package/src/Utils/identity-change-handler.js +49 -0
  156. package/src/Utils/index.d.ts +45 -0
  157. package/src/Utils/index.js +45 -0
  158. package/src/Utils/link-preview-metadata.d.ts +47 -0
  159. package/src/Utils/link-preview-metadata.js +89 -0
  160. package/src/Utils/link-preview.d.ts +13 -0
  161. package/src/Utils/link-preview.js +80 -0
  162. package/src/Utils/logger.d.ts +3 -0
  163. package/src/Utils/logger.js +3 -0
  164. package/src/Utils/lt-hash.d.ts +7 -0
  165. package/src/Utils/lt-hash.js +4 -0
  166. package/src/Utils/make-mutex.d.ts +7 -0
  167. package/src/Utils/make-mutex.js +33 -0
  168. package/src/Utils/message-retry-manager.d.ts +80 -0
  169. package/src/Utils/message-retry-manager.js +256 -0
  170. package/src/Utils/messages-media.d.ts +137 -0
  171. package/src/Utils/messages-media.js +815 -0
  172. package/src/Utils/messages.d.ts +63 -0
  173. package/src/Utils/messages.js +2149 -0
  174. package/src/Utils/modern-messages.d.ts +150 -0
  175. package/src/Utils/modern-messages.js +496 -0
  176. package/src/Utils/native-flow.d.ts +11 -0
  177. package/src/Utils/native-flow.js +116 -0
  178. package/src/Utils/newsletter-status.d.ts +158 -0
  179. package/src/Utils/newsletter-status.js +651 -0
  180. package/src/Utils/noise-handler.d.ts +21 -0
  181. package/src/Utils/noise-handler.js +201 -0
  182. package/src/Utils/offline-node-processor.d.ts +10 -0
  183. package/src/Utils/offline-node-processor.js +34 -0
  184. package/src/Utils/optional-media.d.ts +3 -0
  185. package/src/Utils/optional-media.js +46 -0
  186. package/src/Utils/payment-messages.d.ts +66 -0
  187. package/src/Utils/payment-messages.js +161 -0
  188. package/src/Utils/pre-key-manager.d.ts +26 -0
  189. package/src/Utils/pre-key-manager.js +96 -0
  190. package/src/Utils/process-message.d.ts +61 -0
  191. package/src/Utils/process-message.js +689 -0
  192. package/src/Utils/reporting-utils.d.ts +13 -0
  193. package/src/Utils/reporting-utils.js +257 -0
  194. package/src/Utils/scheduled-message.d.ts +51 -0
  195. package/src/Utils/scheduled-message.js +113 -0
  196. package/src/Utils/sender-key-memory.d.ts +20 -0
  197. package/src/Utils/sender-key-memory.js +52 -0
  198. package/src/Utils/signal.d.ts +83 -0
  199. package/src/Utils/signal.js +194 -0
  200. package/src/Utils/stanza-ack.d.ts +17 -0
  201. package/src/Utils/stanza-ack.js +31 -0
  202. package/src/Utils/status-stickers.d.ts +127 -0
  203. package/src/Utils/status-stickers.js +261 -0
  204. package/src/Utils/sync-action-utils.d.ts +3 -0
  205. package/src/Utils/sync-action-utils.js +45 -0
  206. package/src/Utils/tc-token-utils.d.ts +30 -0
  207. package/src/Utils/tc-token-utils.js +156 -0
  208. package/src/Utils/ttl-cache.d.ts +29 -0
  209. package/src/Utils/ttl-cache.js +121 -0
  210. package/src/Utils/use-mongo-auth-state.d.ts +22 -0
  211. package/src/Utils/use-mongo-auth-state.js +68 -0
  212. package/src/Utils/use-multi-file-auth-state.d.ts +12 -0
  213. package/src/Utils/use-multi-file-auth-state.js +107 -0
  214. package/src/Utils/use-mysql-auth-state.d.ts +20 -0
  215. package/src/Utils/use-mysql-auth-state.js +80 -0
  216. package/src/Utils/use-postgres-auth-state.d.ts +20 -0
  217. package/src/Utils/use-postgres-auth-state.js +80 -0
  218. package/src/Utils/use-redis-auth-state.d.ts +20 -0
  219. package/src/Utils/use-redis-auth-state.js +90 -0
  220. package/src/Utils/use-single-file-auth-state.d.ts +11 -0
  221. package/src/Utils/use-single-file-auth-state.js +109 -0
  222. package/src/Utils/use-sqlite-auth-state.d.ts +13 -0
  223. package/src/Utils/use-sqlite-auth-state.js +121 -0
  224. package/src/Utils/useNekoDBAuth.d.ts +19 -0
  225. package/src/Utils/useNekoDBAuth.js +111 -0
  226. package/src/Utils/username.d.ts +12 -0
  227. package/src/Utils/username.js +59 -0
  228. package/src/Utils/validate-connection.d.ts +44 -0
  229. package/src/Utils/validate-connection.js +208 -0
  230. package/src/Utils/voice-recognition.d.ts +53 -0
  231. package/src/Utils/voice-recognition.js +219 -0
  232. package/src/Voip/audio-feeder.d.ts +25 -0
  233. package/src/Voip/audio-feeder.js +269 -0
  234. package/src/Voip/index.d.ts +89 -0
  235. package/src/Voip/index.js +937 -0
  236. package/src/Voip/relay-transport.d.ts +6 -0
  237. package/src/Voip/relay-transport.js +825 -0
  238. package/src/Voip/signaling.d.ts +12 -0
  239. package/src/Voip/signaling.js +1100 -0
  240. package/src/Voip/types.d.ts +3 -0
  241. package/src/Voip/types.js +13 -0
  242. package/src/Voip/video-feeder.d.ts +25 -0
  243. package/src/Voip/video-feeder.js +269 -0
  244. package/src/Voip/wasm-engine.d.ts +27 -0
  245. package/src/Voip/wasm-engine.js +1308 -0
  246. package/src/Voip/worker-bootstrap.js +1024 -0
  247. package/src/WABinary/constants.d.ts +23 -0
  248. package/src/WABinary/constants.js +1301 -0
  249. package/src/WABinary/decode.d.ts +10 -0
  250. package/src/WABinary/decode.js +262 -0
  251. package/src/WABinary/encode.d.ts +3 -0
  252. package/src/WABinary/encode.js +220 -0
  253. package/src/WABinary/generic-utils.d.ts +77 -0
  254. package/src/WABinary/generic-utils.js +214 -0
  255. package/src/WABinary/index.d.ts +6 -0
  256. package/src/WABinary/index.js +6 -0
  257. package/src/WABinary/jid-utils.d.ts +31 -0
  258. package/src/WABinary/jid-utils.js +98 -0
  259. package/src/WABinary/types.d.ts +2 -0
  260. package/src/WABinary/types.js +1 -0
  261. package/src/WAM/BinaryInfo.d.ts +8 -0
  262. package/src/WAM/BinaryInfo.js +10 -0
  263. package/src/WAM/constants.d.ts +34927 -0
  264. package/src/WAM/constants.js +22853 -0
  265. package/src/WAM/encode.d.ts +2 -0
  266. package/src/WAM/encode.js +149 -0
  267. package/src/WAM/index.d.ts +4 -0
  268. package/src/WAM/index.js +4 -0
  269. package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  270. package/src/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  271. package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  272. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +52 -0
  273. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  274. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  275. package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  276. package/src/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  277. package/src/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  278. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  279. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  280. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  281. package/src/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  282. package/src/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  283. package/src/WAUSync/Protocols/index.d.ts +6 -0
  284. package/src/WAUSync/Protocols/index.js +6 -0
  285. package/src/WAUSync/USyncQuery.d.ts +21 -0
  286. package/src/WAUSync/USyncQuery.js +94 -0
  287. package/src/WAUSync/USyncUser.d.ts +17 -0
  288. package/src/WAUSync/USyncUser.js +31 -0
  289. package/src/WAUSync/index.d.ts +4 -0
  290. package/src/WAUSync/index.js +4 -0
  291. package/src/assets/wasm/README.md +76 -0
  292. package/src/assets/wasm/loader.js +5 -0
  293. package/src/assets/wasm/whatsapp.wasm +0 -0
  294. package/src/assets/wasm/worker-modules.js +273 -0
  295. package/src/index.d.ts +49 -0
  296. package/src/index.js +54 -0
@@ -0,0 +1,689 @@
1
+ /* Elaina Baileys maintained distribution. Upstream notices and license are preserved in LICENSE and NOTICE.md. */
2
+ import { Boom } from '@hapi/boom';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { WAMessageStubType } from '../Types/index.js';
5
+ import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
6
+ import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, isLidUser, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
7
+ import { aesDecryptGCM, hmacSign } from './crypto.js';
8
+ import { getKeyAuthor, toNumber } from './generics.js';
9
+ import { downloadAndProcessHistorySyncNotification } from './history.js';
10
+ import { buildMergedTcTokenIndexWrite, resolveTcTokenJid } from './tc-token-utils.js';
11
+ const REAL_MSG_STUB_TYPES = new Set([
12
+ WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
13
+ WAMessageStubType.CALL_MISSED_GROUP_VOICE,
14
+ WAMessageStubType.CALL_MISSED_VIDEO,
15
+ WAMessageStubType.CALL_MISSED_VOICE
16
+ ]);
17
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
18
+ async function storeTcTokensFromHistorySync(chats, signalRepository, keyStore, logger) {
19
+ const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
20
+ const candidates = [];
21
+ for (const chat of chats) {
22
+ const ts = chat.tcTokenTimestamp ? toNumber(chat.tcTokenTimestamp) : 0;
23
+ if (chat.tcToken?.length && ts > 0) {
24
+ const jid = jidNormalizedUser(chat.id);
25
+ const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
26
+ candidates.push({
27
+ storageJid,
28
+ token: Buffer.from(chat.tcToken),
29
+ ts,
30
+ senderTs: chat.tcTokenSenderTimestamp ? toNumber(chat.tcTokenSenderTimestamp) : undefined
31
+ });
32
+ }
33
+ }
34
+ if (!candidates.length) {
35
+ return;
36
+ }
37
+ const jids = candidates.map(c => c.storageJid);
38
+ const existing = await keyStore.get('tctoken', jids);
39
+ const entries = {};
40
+ for (const c of candidates) {
41
+ const existingEntry = existing[c.storageJid];
42
+ const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
43
+ if (existingTs > 0 && existingTs >= c.ts) {
44
+ continue;
45
+ }
46
+ entries[c.storageJid] = {
47
+ ...existingEntry,
48
+ token: c.token,
49
+ timestamp: String(c.ts),
50
+ ...(c.senderTs !== undefined ? { senderTimestamp: c.senderTs } : {})
51
+ };
52
+ }
53
+ if (Object.keys(entries).length) {
54
+ logger?.debug({ count: Object.keys(entries).length }, 'storing tctokens from history sync');
55
+ try {
56
+
57
+ const indexWrite = await buildMergedTcTokenIndexWrite(keyStore, Object.keys(entries));
58
+ await keyStore.set({ tctoken: { ...entries, ...indexWrite } });
59
+ }
60
+ catch (err) {
61
+ logger?.warn({ err }, 'failed to store tctokens from history sync');
62
+ }
63
+ }
64
+ }
65
+
66
+ export const cleanMessage = (message, meId, meLid) => {
67
+
68
+ if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
69
+ message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
70
+ }
71
+ else {
72
+ message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
73
+ }
74
+ if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
75
+ message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
76
+ }
77
+ else {
78
+ message.key.participant = jidNormalizedUser(message.key.participant);
79
+ }
80
+ const content = normalizeMessageContent(message.message);
81
+
82
+ if (content?.reactionMessage) {
83
+ normaliseKey(content.reactionMessage.key);
84
+ }
85
+ if (content?.pollUpdateMessage) {
86
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
87
+ }
88
+ function normaliseKey(msgKey) {
89
+
90
+ if (!message.key.fromMe) {
91
+
92
+ msgKey.fromMe = !msgKey.fromMe
93
+ ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
94
+ areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
95
+ :
96
+
97
+ false;
98
+
99
+ msgKey.remoteJid = message.key.remoteJid;
100
+
101
+ msgKey.participant = msgKey.participant || message.key.participant;
102
+ }
103
+ }
104
+ };
105
+
106
+ export const isRealMessage = (message) => {
107
+ const normalizedContent = normalizeMessageContent(message.message);
108
+ const hasSomeContent = !!getContentType(normalizedContent);
109
+ return ((!!normalizedContent ||
110
+ REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
111
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
112
+ hasSomeContent &&
113
+ !normalizedContent?.protocolMessage &&
114
+ !normalizedContent?.reactionMessage &&
115
+ !normalizedContent?.pollUpdateMessage);
116
+ };
117
+ export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
118
+
119
+ export const getChatId = ({ remoteJid, participant, fromMe }) => {
120
+ if (!remoteJid) {
121
+ throw new Boom('Cannot derive chat id: message key is missing remoteJid', {
122
+ data: { remoteJid, participant, fromMe }
123
+ });
124
+ }
125
+ if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
126
+ if (!participant) {
127
+ throw new Boom('Cannot derive chat id: broadcast message key is missing participant', {
128
+ data: { remoteJid, fromMe }
129
+ });
130
+ }
131
+ return participant;
132
+ }
133
+ return remoteJid;
134
+ };
135
+
136
+ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
137
+ const sign = Buffer.concat([
138
+ toBinary(pollMsgId),
139
+ toBinary(pollCreatorJid),
140
+ toBinary(voterJid),
141
+ toBinary('Poll Vote'),
142
+ new Uint8Array([1])
143
+ ]);
144
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
145
+ const decKey = hmacSign(sign, key0, 'sha256');
146
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
147
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
148
+ return proto.Message.PollVoteMessage.decode(decrypted);
149
+ function toBinary(txt) {
150
+ return Buffer.from(txt);
151
+ }
152
+ }
153
+
154
+ export function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
155
+ const sign = Buffer.concat([
156
+ toBinary(eventMsgId),
157
+ toBinary(eventCreatorJid),
158
+ toBinary(responderJid),
159
+ toBinary('Event Response'),
160
+ new Uint8Array([1])
161
+ ]);
162
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256');
163
+ const decKey = hmacSign(sign, key0, 'sha256');
164
+ const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
165
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
166
+ return proto.Message.EventResponseMessage.decode(decrypted);
167
+ function toBinary(txt) {
168
+ return Buffer.from(txt);
169
+ }
170
+ }
171
+ export function decryptMessageEdit({ encPayload, encIv }, { originalSenderJid, originalMsgId, editEncKey, editorJid }) {
172
+ const sign = Buffer.concat([
173
+ toBinary(originalMsgId),
174
+ toBinary(originalSenderJid),
175
+ toBinary(editorJid),
176
+ toBinary('Message Edit'),
177
+ new Uint8Array([1])
178
+ ]);
179
+ const key0 = hmacSign(editEncKey, new Uint8Array(32), 'sha256');
180
+ const decKey = hmacSign(sign, key0, 'sha256');
181
+ const aad = Buffer.alloc(0);
182
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
183
+ return proto.Message.decode(decrypted);
184
+ function toBinary(txt) {
185
+ return Buffer.from(txt);
186
+ }
187
+ }
188
+ const resolveMessageEditAuthor = async (key, meId, lidMapping) => {
189
+ if (!key) {
190
+ return '';
191
+ }
192
+ const rawJid = key.fromMe
193
+ ? key.participantAlt || key.participant || meId
194
+ : key.participantAlt || key.participant || key.remoteJidAlt || key.remoteJid;
195
+ const normalized = jidNormalizedUser(rawJid);
196
+ if (!normalized) {
197
+ return '';
198
+ }
199
+ if (!isLidUser(normalized)) {
200
+ return normalized;
201
+ }
202
+ const pn = await lidMapping.getPNForLID(normalized);
203
+ return jidNormalizedUser(pn);
204
+ };
205
+ const buildEditUpdate = (args) => {
206
+ const editedInner = decryptMessageEdit({ encPayload: args.encPayload, encIv: args.encIv }, {
207
+ editEncKey: args.editEncKey,
208
+ originalSenderJid: args.originalSenderJid,
209
+ originalMsgId: args.originalMsgId,
210
+ editorJid: args.editorJid
211
+ });
212
+ const editProtocol = editedInner.protocolMessage;
213
+ const innerEdited = editProtocol?.editedMessage;
214
+ if (!innerEdited) {
215
+ args.logger?.warn({ targetKey: args.targetKey }, 'decrypted MESSAGE_EDIT plaintext had no protocolMessage.editedMessage — skipping update');
216
+ return null;
217
+ }
218
+ return {
219
+ key: { ...args.targetKey },
220
+ update: {
221
+ message: {
222
+ editedMessage: {
223
+ message: innerEdited
224
+ }
225
+ },
226
+ messageTimestamp: editProtocol?.timestampMs
227
+ ? Math.floor(toNumber(editProtocol.timestampMs) / 1000)
228
+ : args.fallbackTimestamp
229
+ }
230
+ };
231
+ };
232
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
233
+ const meId = creds.me.id;
234
+ const { accountSettings } = creds;
235
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) };
236
+ const isRealMsg = isRealMessage(message);
237
+ if (isRealMsg) {
238
+ chat.messages = [{ message }];
239
+ chat.conversationTimestamp = toNumber(message.messageTimestamp);
240
+
241
+ if (shouldIncrementChatUnread(message)) {
242
+ chat.unreadCount = (chat.unreadCount || 0) + 1;
243
+ }
244
+ }
245
+ const content = normalizeMessageContent(message.message);
246
+
247
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
248
+ chat.archived = false;
249
+ chat.readOnly = false;
250
+ }
251
+ const protocolMsg = content?.protocolMessage;
252
+ if (protocolMsg) {
253
+
254
+ const SELF_ONLY_TYPES = new Set([
255
+ proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION,
256
+ proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE,
257
+ proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC,
258
+ proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
259
+ ]);
260
+ if (protocolMsg.type !== null &&
261
+ protocolMsg.type !== undefined &&
262
+ SELF_ONLY_TYPES.has(protocolMsg.type) &&
263
+ !message.key.fromMe) {
264
+ 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');
265
+ return;
266
+ }
267
+ switch (protocolMsg.type) {
268
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
269
+ const histNotification = protocolMsg.historySyncNotification;
270
+ const process = shouldProcessHistoryMsg;
271
+ const isLatest = !creds.processedHistoryMessages?.length;
272
+ logger?.info({
273
+ histNotification,
274
+ process,
275
+ id: message.key.id,
276
+ isLatest
277
+ }, 'got history notification');
278
+ if (process) {
279
+
280
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
281
+ ev.emit('creds.update', {
282
+ processedHistoryMessages: [
283
+ ...(creds.processedHistoryMessages || []),
284
+ { key: message.key, messageTimestamp: message.messageTimestamp }
285
+ ]
286
+ });
287
+ }
288
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options, logger);
289
+ if (data.lidPnMappings?.length) {
290
+ logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
291
+ await signalRepository.lidMapping
292
+ .storeLIDPNMappings(data.lidPnMappings)
293
+ .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
294
+ }
295
+ await storeTcTokensFromHistorySync(data.chats, signalRepository, keyStore, logger);
296
+ ev.emit('messaging-history.set', {
297
+ ...data,
298
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
299
+ chunkOrder: histNotification.chunkOrder,
300
+ peerDataRequestSessionId: histNotification.peerDataRequestSessionId
301
+ });
302
+ }
303
+ break;
304
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
305
+ const keys = protocolMsg.appStateSyncKeyShare.keys;
306
+ if (keys?.length) {
307
+ let newAppStateSyncKeyId = '';
308
+ await keyStore.transaction(async () => {
309
+ const newKeys = [];
310
+ for (const { keyData, keyId } of keys) {
311
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64');
312
+ newKeys.push(strKeyId);
313
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
314
+ newAppStateSyncKeyId = strKeyId;
315
+ }
316
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
317
+ }, meId);
318
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
319
+ }
320
+ else {
321
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
322
+ }
323
+ break;
324
+ case proto.Message.ProtocolMessage.Type.REVOKE:
325
+ ev.emit('messages.update', [
326
+ {
327
+ key: {
328
+ ...message.key,
329
+ id: protocolMsg.key.id
330
+ },
331
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
332
+ }
333
+ ]);
334
+ break;
335
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
336
+ Object.assign(chat, {
337
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
338
+ ephemeralExpiration: protocolMsg.ephemeralExpiration || null
339
+ });
340
+ break;
341
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
342
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
343
+ if (response) {
344
+
345
+ const peerDataOperationResult = response.peerDataOperationResult || [];
346
+ for (const result of peerDataOperationResult) {
347
+ const retryResponse = result?.placeholderMessageResendResponse;
348
+
349
+ if (!retryResponse?.webMessageInfoBytes) {
350
+ continue;
351
+ }
352
+
353
+ try {
354
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
355
+ const msgId = webMessageInfo.key?.id;
356
+
357
+ const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
358
+
359
+ if (msgId) {
360
+ await placeholderResendCache?.del(msgId);
361
+ }
362
+ let finalMsg;
363
+
364
+ if (cachedData && typeof cachedData === 'object') {
365
+
366
+ cachedData.message = webMessageInfo.message;
367
+
368
+ if (webMessageInfo.messageTimestamp) {
369
+ cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
370
+ }
371
+ finalMsg = cachedData;
372
+ }
373
+ else {
374
+ finalMsg = webMessageInfo;
375
+ }
376
+ logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
377
+ ev.emit('messages.upsert', {
378
+ messages: [finalMsg],
379
+ type: 'notify',
380
+ requestId: response.stanzaId
381
+ });
382
+ }
383
+ catch (err) {
384
+ logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
385
+ }
386
+ }
387
+ }
388
+ break;
389
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
390
+ ev.emit('messages.update', [
391
+ {
392
+
393
+ key: { ...message.key, id: protocolMsg.key?.id },
394
+ update: {
395
+ message: {
396
+ editedMessage: {
397
+ message: protocolMsg.editedMessage
398
+ }
399
+ },
400
+ messageTimestamp: protocolMsg.timestampMs
401
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
402
+ : message.messageTimestamp
403
+ }
404
+ }
405
+ ]);
406
+ break;
407
+ case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
408
+ const labelAssociationMsg = protocolMsg.memberLabel;
409
+ if (labelAssociationMsg?.label) {
410
+ ev.emit('group.member-tag.update', {
411
+ groupId: chat.id,
412
+ label: labelAssociationMsg.label,
413
+ participant: message.key.participant,
414
+ participantAlt: message.key.participantAlt,
415
+ messageTimestamp: Number(message.messageTimestamp)
416
+ });
417
+ }
418
+ break;
419
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
420
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
421
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
422
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
423
+ const pairs = [];
424
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
425
+ const lid = latestLid || assignedLid;
426
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
427
+ }
428
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
429
+ if (pairs.length) {
430
+ for (const { pn, lid } of pairs) {
431
+ await signalRepository.migrateSession(pn, lid);
432
+ }
433
+ }
434
+ }
435
+ }
436
+ else if (content?.reactionMessage) {
437
+ const reaction = {
438
+ ...content.reactionMessage,
439
+ key: message.key
440
+ };
441
+ ev.emit('messages.reaction', [
442
+ {
443
+ reaction,
444
+ key: content.reactionMessage?.key
445
+ }
446
+ ]);
447
+ }
448
+ else if (content?.encEventResponseMessage) {
449
+ const encEventResponse = content.encEventResponseMessage;
450
+ const creationMsgKey = encEventResponse.eventCreationMessageKey;
451
+
452
+ const eventMsg = await getMessage(creationMsgKey);
453
+ if (eventMsg) {
454
+ try {
455
+ const meIdNormalised = jidNormalizedUser(meId);
456
+
457
+ const eventCreatorKey = creationMsgKey.participant || creationMsgKey.remoteJid;
458
+ const eventCreatorPn = isLidUser(eventCreatorKey)
459
+ ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
460
+ : eventCreatorKey;
461
+ const eventCreatorJid = getKeyAuthor({ remoteJid: jidNormalizedUser(eventCreatorPn), fromMe: meIdNormalised === eventCreatorPn }, meIdNormalised);
462
+ const responderJid = getKeyAuthor(message.key, meIdNormalised);
463
+ const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
464
+ if (!eventEncKey) {
465
+ logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
466
+ }
467
+ else {
468
+ const responseMsg = decryptEventResponse(encEventResponse, {
469
+ eventEncKey,
470
+ eventCreatorJid,
471
+ eventMsgId: creationMsgKey.id,
472
+ responderJid
473
+ });
474
+ const eventResponse = {
475
+ eventResponseMessageKey: message.key,
476
+ senderTimestampMs: responseMsg.timestampMs,
477
+ response: responseMsg
478
+ };
479
+ ev.emit('messages.update', [
480
+ {
481
+ key: creationMsgKey,
482
+ update: {
483
+ eventResponses: [eventResponse]
484
+ }
485
+ }
486
+ ]);
487
+ }
488
+ }
489
+ catch (err) {
490
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
491
+ }
492
+ }
493
+ else {
494
+ logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
495
+ }
496
+ }
497
+ else if (content?.secretEncryptedMessage &&
498
+ content.secretEncryptedMessage.secretEncType === proto.Message.SecretEncryptedMessage.SecretEncType.MESSAGE_EDIT) {
499
+ const secEnc = content.secretEncryptedMessage;
500
+ const targetKey = secEnc.targetMessageKey;
501
+ const targetId = typeof targetKey?.id === 'string' ? targetKey.id.trim() : '';
502
+ const targetRemoteJid = targetKey?.remoteJid || targetKey?.remoteJidAlt;
503
+ if (!targetKey || !targetId || !targetRemoteJid) {
504
+ logger?.warn({ targetKey }, 'message edit: incomplete targetMessageKey — cannot decrypt');
505
+ return;
506
+ }
507
+ const lookupTargetKey = {
508
+ ...targetKey,
509
+ remoteJid: targetKey.remoteJid || targetKey.remoteJidAlt,
510
+ participant: targetKey.participant || targetKey.participantAlt
511
+ };
512
+ const targetMsg = await getMessage(lookupTargetKey);
513
+ if (!targetMsg) {
514
+ logger?.warn({ targetKey }, 'original message not found in store, cannot decrypt secretEncryptedMessage edit');
515
+ return;
516
+ }
517
+ try {
518
+ const meIdNormalised = jidNormalizedUser(meId);
519
+ const editEncKey = targetMsg?.messageContextInfo?.messageSecret;
520
+ if (!editEncKey?.length) {
521
+ logger?.warn({ targetKey }, 'message edit: missing messageSecret on original message — cannot decrypt');
522
+ return;
523
+ }
524
+ const originalSenderJid = await resolveMessageEditAuthor(targetKey, meIdNormalised, signalRepository.lidMapping);
525
+ if (!originalSenderJid) {
526
+ logger?.warn({ targetKey }, 'message edit: original sender JID unavailable — cannot decrypt');
527
+ return;
528
+ }
529
+ const editorJid = await resolveMessageEditAuthor(message.key, meIdNormalised, signalRepository.lidMapping);
530
+ if (!editorJid) {
531
+ logger?.warn({ key: message.key, targetKey }, 'message edit: editor JID unavailable — cannot decrypt');
532
+ return;
533
+ }
534
+ if (!secEnc.encPayload?.length || !secEnc.encIv?.length) {
535
+ logger?.warn({ targetKey }, 'message edit: encrypted payload or IV missing — cannot decrypt');
536
+ return;
537
+ }
538
+ const update = buildEditUpdate({
539
+ editEncKey,
540
+ encPayload: secEnc.encPayload,
541
+ encIv: secEnc.encIv,
542
+ originalSenderJid,
543
+ originalMsgId: targetId,
544
+ editorJid,
545
+ targetKey,
546
+ fallbackTimestamp: toNumber(message.messageTimestamp),
547
+ logger
548
+ });
549
+ if (update) {
550
+ ev.emit('messages.update', [update]);
551
+ }
552
+ }
553
+ catch (err) {
554
+ logger?.warn({ err, targetKey }, 'failed to decrypt secretEncryptedMessage MESSAGE_EDIT');
555
+ }
556
+ }
557
+ else if (message.messageStubType) {
558
+ const jid = message.key?.remoteJid;
559
+
560
+ let participants;
561
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
562
+ id: jid,
563
+ author: message.key.participant,
564
+ authorPn: message.key.participantAlt,
565
+ authorUsername: message.key.participantUsername,
566
+ participants,
567
+ action
568
+ });
569
+ const emitGroupUpdate = (update) => {
570
+ ev.emit('groups.update', [
571
+ {
572
+ id: jid,
573
+ ...update,
574
+ author: message.key.participant ?? undefined,
575
+ authorPn: message.key.participantAlt,
576
+ authorUsername: message.key.participantUsername
577
+ }
578
+ ]);
579
+ };
580
+ const emitGroupRequestJoin = (participant, action, method) => {
581
+ ev.emit('group.join-request', {
582
+ id: jid,
583
+ author: message.key.participant,
584
+ authorPn: message.key.participantAlt,
585
+ authorUsername: message.key.participantUsername,
586
+ participant: participant.lid,
587
+ participantPn: participant.pn,
588
+ action,
589
+ method: method
590
+ });
591
+ };
592
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber));
593
+ const readStubJson = (index) => {
594
+ const raw = message.messageStubParameters?.[index];
595
+ if (typeof raw !== 'string') {
596
+ return undefined;
597
+ }
598
+ try {
599
+ return JSON.parse(raw);
600
+ }
601
+ catch (error) {
602
+ logger?.warn?.({ jid, stubType: message.messageStubType, raw }, 'group stub parameter is not JSON, skipping it');
603
+ return undefined;
604
+ }
605
+ };
606
+ const readStubParticipants = () => {
607
+ const raw = message.messageStubParameters;
608
+ if (!Array.isArray(raw)) {
609
+ logger?.warn?.({ jid, stubType: message.messageStubType }, 'group stub carries no parameters, treating it as an empty participant list');
610
+ return [];
611
+ }
612
+ return raw.map((_, index) => readStubJson(index)).filter(entry => entry !== undefined);
613
+ };
614
+ switch (message.messageStubType) {
615
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
616
+ participants = readStubParticipants();
617
+ emitParticipantsUpdate('modify');
618
+ break;
619
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
620
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
621
+ participants = readStubParticipants();
622
+ emitParticipantsUpdate('remove');
623
+
624
+ if (participantsIncludesMe()) {
625
+ chat.readOnly = true;
626
+ }
627
+ break;
628
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
629
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
630
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
631
+ participants = readStubParticipants();
632
+ if (participantsIncludesMe()) {
633
+ chat.readOnly = false;
634
+ }
635
+ emitParticipantsUpdate('add');
636
+ break;
637
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
638
+ participants = readStubParticipants();
639
+ emitParticipantsUpdate('demote');
640
+ break;
641
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
642
+ participants = readStubParticipants();
643
+ emitParticipantsUpdate('promote');
644
+ break;
645
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
646
+ const announceValue = message.messageStubParameters?.[0];
647
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
648
+ break;
649
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
650
+ const restrictValue = message.messageStubParameters?.[0];
651
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
652
+ break;
653
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
654
+ const name = message.messageStubParameters?.[0];
655
+ chat.name = name;
656
+ emitGroupUpdate({ subject: name });
657
+ break;
658
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
659
+ const description = message.messageStubParameters?.[0];
660
+ chat.description = description;
661
+ emitGroupUpdate({ desc: description });
662
+ break;
663
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
664
+ const code = message.messageStubParameters?.[0];
665
+ emitGroupUpdate({ inviteCode: code });
666
+ break;
667
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
668
+ const memberAddValue = message.messageStubParameters?.[0];
669
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
670
+ break;
671
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
672
+ const approvalMode = message.messageStubParameters?.[0];
673
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
674
+ break;
675
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
676
+ const participant = readStubJson(0);
677
+ const action = message.messageStubParameters?.[1];
678
+ const method = message.messageStubParameters?.[2];
679
+ if (participant) {
680
+ emitGroupRequestJoin(participant, action, method);
681
+ }
682
+ break;
683
+ }
684
+ }
685
+ if (Object.keys(chat).length > 1) {
686
+ ev.emit('chats.update', [chat]);
687
+ }
688
+ };
689
+ export default processMessage;