jagproject 26.3.23 → 26.3.26

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 (209) hide show
  1. package/WAProto/GenerateStatics.sh +3 -4
  2. package/WAProto/WAProto.proto +1215 -511
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +64857 -145167
  6. package/engine-requirements.js +4 -7
  7. package/lib/Defaults/index.d.ts +74 -0
  8. package/lib/Defaults/index.js +49 -35
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/wileys-version.json +2 -2
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  13. package/lib/Signal/Group/group-session-builder.js +5 -3
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +35 -46
  16. package/lib/Signal/Group/index.d.ts +12 -0
  17. package/lib/Signal/Group/index.js +21 -21
  18. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  19. package/lib/Signal/Group/keyhelper.js +2 -2
  20. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  21. package/lib/Signal/Group/sender-chain-key.js +5 -10
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  24. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  25. package/lib/Signal/Group/sender-key-message.js +8 -8
  26. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +7 -16
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +25 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +2 -2
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +358 -54
  35. package/lib/Signal/lid-mapping.d.ts +19 -0
  36. package/lib/Signal/lid-mapping.js +274 -0
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +2 -2
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +1 -0
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +18 -30
  43. package/lib/Socket/business.d.ts +202 -0
  44. package/lib/Socket/business.js +160 -38
  45. package/lib/Socket/chats.d.ts +111 -0
  46. package/lib/Socket/chats.js +497 -314
  47. package/lib/Socket/communities.d.ts +258 -0
  48. package/lib/Socket/communities.js +438 -0
  49. package/lib/Socket/community.js +333 -0
  50. package/lib/Socket/groups.d.ts +150 -0
  51. package/lib/Socket/groups.js +229 -91
  52. package/lib/Socket/index.d.ts +245 -0
  53. package/lib/Socket/index.js +9 -6
  54. package/lib/Socket/messages-recv.d.ts +187 -0
  55. package/lib/Socket/messages-recv.js +1105 -501
  56. package/lib/Socket/messages-send.d.ts +183 -0
  57. package/lib/Socket/messages-send.js +1181 -501
  58. package/lib/Socket/mex.d.ts +3 -0
  59. package/lib/Socket/mex.js +45 -0
  60. package/lib/Socket/newsletter.d.ts +160 -0
  61. package/lib/Socket/newsletter.js +227 -200
  62. package/lib/Socket/socket.d.ts +55 -0
  63. package/lib/Socket/socket.js +507 -206
  64. package/lib/Socket/usync.js +6 -6
  65. package/lib/Store/index.js +17 -5
  66. package/lib/Store/make-cache-manager-store.js +83 -0
  67. package/lib/Store/make-in-memory-store.js +48 -89
  68. package/lib/Store/make-ordered-dictionary.js +1 -1
  69. package/lib/Types/Auth.d.ts +116 -0
  70. package/lib/Types/Bussines.d.ts +25 -0
  71. package/lib/Types/Bussines.js +2 -0
  72. package/lib/Types/Call.d.ts +15 -0
  73. package/lib/Types/Chat.d.ts +123 -0
  74. package/lib/Types/Chat.js +7 -1
  75. package/lib/Types/Contact.d.ts +24 -0
  76. package/lib/Types/Events.d.ts +237 -0
  77. package/lib/Types/Events.js +1 -0
  78. package/lib/Types/GroupMetadata.d.ts +67 -0
  79. package/lib/Types/Label.d.ts +47 -0
  80. package/lib/Types/Label.js +1 -3
  81. package/lib/Types/LabelAssociation.d.ts +30 -0
  82. package/lib/Types/LabelAssociation.js +1 -3
  83. package/lib/Types/Message.d.ts +305 -0
  84. package/lib/Types/Message.js +9 -5
  85. package/lib/Types/MexUpdates.js +11 -0
  86. package/lib/Types/Newsletter.d.ts +135 -0
  87. package/lib/Types/Newsletter.js +36 -11
  88. package/lib/Types/Product.d.ts +79 -0
  89. package/lib/Types/Signal.d.ts +76 -0
  90. package/lib/Types/Signal.js +1 -0
  91. package/lib/Types/Socket.d.ts +133 -0
  92. package/lib/Types/Socket.js +1 -0
  93. package/lib/Types/State.d.ts +39 -0
  94. package/lib/Types/State.js +12 -0
  95. package/lib/Types/USync.d.ts +26 -0
  96. package/lib/Types/USync.js +1 -0
  97. package/lib/Types/index.d.ts +65 -0
  98. package/lib/Types/index.js +14 -14
  99. package/lib/Utils/audioToBuffer.js +31 -0
  100. package/lib/Utils/auth-utils.d.ts +19 -0
  101. package/lib/Utils/auth-utils.js +222 -123
  102. package/lib/Utils/baileys-event-stream.js +60 -0
  103. package/lib/Utils/bridge-runtime.d.ts +1 -0
  104. package/lib/Utils/bridge-runtime.js +14 -0
  105. package/lib/Utils/browser-utils.d.ts +4 -0
  106. package/lib/Utils/browser-utils.js +38 -29
  107. package/lib/Utils/business.d.ts +23 -0
  108. package/lib/Utils/business.js +54 -48
  109. package/lib/Utils/chat-utils.d.ts +70 -0
  110. package/lib/Utils/chat-utils.js +284 -189
  111. package/lib/Utils/crypto.d.ts +37 -0
  112. package/lib/Utils/crypto.js +16 -41
  113. package/lib/Utils/decode-wa-message.d.ts +48 -0
  114. package/lib/Utils/decode-wa-message.js +128 -48
  115. package/lib/Utils/event-buffer.d.ts +34 -0
  116. package/lib/Utils/event-buffer.js +124 -62
  117. package/lib/Utils/generics.d.ts +91 -0
  118. package/lib/Utils/generics.js +154 -138
  119. package/lib/Utils/history.d.ts +22 -0
  120. package/lib/Utils/history.js +77 -34
  121. package/lib/Utils/identity-change-handler.d.ts +37 -0
  122. package/lib/Utils/identity-change-handler.js +54 -0
  123. package/lib/Utils/index.d.ts +22 -0
  124. package/lib/Utils/index.js +32 -19
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +12 -17
  127. package/lib/Utils/logger.d.ts +13 -0
  128. package/lib/Utils/lt-hash.d.ts +8 -0
  129. package/lib/Utils/lt-hash.js +2 -43
  130. package/lib/Utils/make-mutex.d.ts +9 -0
  131. package/lib/Utils/make-mutex.js +21 -27
  132. package/lib/Utils/message-retry-manager.d.ts +110 -0
  133. package/lib/Utils/message-retry-manager.js +143 -45
  134. package/lib/Utils/messages-media.d.ts +130 -0
  135. package/lib/Utils/messages-media.js +429 -502
  136. package/lib/Utils/messages-newsletter.d.ts +84 -0
  137. package/lib/Utils/messages-newsletter.js +295 -0
  138. package/lib/Utils/messages.d.ts +92 -0
  139. package/lib/Utils/messages.js +1025 -674
  140. package/lib/Utils/noise-handler.d.ts +20 -0
  141. package/lib/Utils/noise-handler.js +145 -91
  142. package/lib/Utils/pre-key-manager.d.ts +28 -0
  143. package/lib/Utils/pre-key-manager.js +112 -0
  144. package/lib/Utils/process-message.d.ts +60 -0
  145. package/lib/Utils/process-message.js +316 -184
  146. package/lib/Utils/reporting-utils.d.ts +11 -0
  147. package/lib/Utils/reporting-utils.js +262 -0
  148. package/lib/Utils/resolve-jid.d.ts +43 -0
  149. package/lib/Utils/resolve-jid.js +95 -0
  150. package/lib/Utils/rust-bridge-shim.d.ts +22 -0
  151. package/lib/Utils/rust-bridge-shim.js +70 -0
  152. package/lib/Utils/serial-task-queue.js +29 -0
  153. package/lib/Utils/signal.d.ts +34 -0
  154. package/lib/Utils/signal.js +56 -39
  155. package/lib/Utils/streamToBuffer.js +17 -0
  156. package/lib/Utils/sync-action-utils.d.ts +19 -0
  157. package/lib/Utils/sync-action-utils.js +52 -0
  158. package/lib/Utils/tc-token-utils.d.ts +12 -0
  159. package/lib/Utils/tc-token-utils.js +20 -0
  160. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  161. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  162. package/lib/Utils/use-multi-file-auth-state.js +11 -12
  163. package/lib/Utils/use-single-file-auth-state.js +73 -0
  164. package/lib/Utils/validate-connection.d.ts +11 -0
  165. package/lib/Utils/validate-connection.js +59 -82
  166. package/lib/Utils/wileys-event-stream.js +1 -61
  167. package/lib/WABinary/constants.d.ts +28 -0
  168. package/lib/WABinary/decode.d.ts +7 -0
  169. package/lib/WABinary/decode.js +39 -4
  170. package/lib/WABinary/encode.d.ts +3 -0
  171. package/lib/WABinary/encode.js +17 -11
  172. package/lib/WABinary/generic-utils.d.ts +15 -0
  173. package/lib/WABinary/generic-utils.js +46 -18
  174. package/lib/WABinary/index.d.ts +6 -0
  175. package/lib/WABinary/index.js +9 -5
  176. package/lib/WABinary/jid-utils.d.ts +48 -0
  177. package/lib/WABinary/jid-utils.js +67 -37
  178. package/lib/WABinary/types.d.ts +19 -0
  179. package/lib/WABinary/types.js +34 -0
  180. package/lib/WAM/BinaryInfo.d.ts +9 -0
  181. package/lib/WAM/constants.d.ts +40 -0
  182. package/lib/WAM/constants.js +19183 -11678
  183. package/lib/WAM/encode.d.ts +3 -0
  184. package/lib/WAM/encode.js +15 -17
  185. package/lib/WAM/index.d.ts +4 -0
  186. package/lib/WAM/index.js +3 -3
  187. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
  189. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  190. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
  191. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  192. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
  193. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  194. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
  195. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  196. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
  197. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  198. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  199. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  200. package/lib/WAUSync/Protocols/index.js +6 -4
  201. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  202. package/lib/WAUSync/USyncQuery.js +38 -30
  203. package/lib/WAUSync/USyncUser.d.ts +13 -0
  204. package/lib/WAUSync/index.d.ts +4 -0
  205. package/lib/WAUSync/index.js +3 -3
  206. package/lib/index.d.ts +12 -0
  207. package/lib/index.js +3 -5
  208. package/package.json +7 -4
  209. package/LICENSE +0 -21
@@ -2,46 +2,42 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
4
  exports.decryptPollVote = decryptPollVote;
5
- const WAProto_1 = require("../../WAProto");
6
- const Types_1 = require("../Types");
7
- const messages_1 = require("../Utils/messages");
8
- const WABinary_1 = require("../WABinary");
9
- const crypto_1 = require("./crypto");
10
- const generics_1 = require("./generics");
11
- const history_1 = require("./history");
5
+ exports.decryptEventResponse = decryptEventResponse;
6
+ const index_js_1 = require("../../WAProto/index.js");
7
+ const index_js_2 = require("../Types/index.js");
8
+ const messages_js_1 = require("../Utils/messages.js");
9
+ const index_js_3 = require("../WABinary/index.js");
10
+ const crypto_js_1 = require("./crypto.js");
11
+ const generics_js_1 = require("./generics.js");
12
+ const history_js_1 = require("./history.js");
12
13
  const REAL_MSG_STUB_TYPES = new Set([
13
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
14
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
15
- Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
16
- Types_1.WAMessageStubType.CALL_MISSED_VOICE
17
- ]);
18
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
19
- Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
14
+ index_js_2.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
15
+ index_js_2.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
16
+ index_js_2.WAMessageStubType.CALL_MISSED_VIDEO,
17
+ index_js_2.WAMessageStubType.CALL_MISSED_VOICE
20
18
  ]);
19
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD]);
21
20
  /** Cleans a received message to further processing */
22
- const cleanMessage = (message, meId) => {
21
+ const cleanMessage = (message, meId, meLid) => {
23
22
  // ensure remoteJid and participant doesn't have device or agent in it
24
- // normalize JIDs but catch errors to avoid throwing on invalid LIDs/JIDs
25
- try {
26
- message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
23
+ if ((0, index_js_3.isHostedPnUser)(message.key.remoteJid) || (0, index_js_3.isHostedLidUser)(message.key.remoteJid)) {
24
+ message.key.remoteJid = (0, index_js_3.jidEncode)((0, index_js_3.jidDecode)(message.key?.remoteJid)?.user, (0, index_js_3.isHostedPnUser)(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
27
25
  }
28
- catch (_e) {
29
- // if normalization fails, retain original remoteJid
26
+ else {
27
+ message.key.remoteJid = (0, index_js_3.jidNormalizedUser)(message.key.remoteJid);
30
28
  }
31
- if (message.key.participant) {
32
- try {
33
- message.key.participant = (0, WABinary_1.jidNormalizedUser)(message.key.participant);
34
- }
35
- catch (_e) {
36
- // ignore if can't normalize participant
37
- }
29
+ if ((0, index_js_3.isHostedPnUser)(message.key.participant) || (0, index_js_3.isHostedLidUser)(message.key.participant)) {
30
+ message.key.participant = (0, index_js_3.jidEncode)((0, index_js_3.jidDecode)(message.key.participant)?.user, (0, index_js_3.isHostedPnUser)(message.key.participant) ? 's.whatsapp.net' : 'lid');
31
+ }
32
+ else {
33
+ message.key.participant = (0, index_js_3.jidNormalizedUser)(message.key.participant);
38
34
  }
39
- const content = (0, messages_1.normalizeMessageContent)(message.message);
35
+ const content = (0, messages_js_1.normalizeMessageContent)(message.message);
40
36
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
41
- if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
37
+ if (content?.reactionMessage) {
42
38
  normaliseKey(content.reactionMessage.key);
43
39
  }
44
- if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
40
+ if (content?.pollUpdateMessage) {
45
41
  normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
46
42
  }
47
43
  function normaliseKey(msgKey) {
@@ -51,11 +47,13 @@ const cleanMessage = (message, meId) => {
51
47
  // if the sender believed the message being reacted to is not from them
52
48
  // we've to correct the key to be from them, or some other participant
53
49
  msgKey.fromMe = !msgKey.fromMe
54
- ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
55
- // if the message being reacted to, was from them
56
- // fromMe automatically becomes false
57
- : false;
50
+ ? (0, index_js_3.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId) ||
51
+ (0, index_js_3.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meLid)
52
+ : // if the message being reacted to, was from them
53
+ // fromMe automatically becomes false
54
+ false;
58
55
  // set the remoteJid to being the same as the chat the message came from
56
+ // TODO: investigate inconsistencies
59
57
  msgKey.remoteJid = message.key.remoteJid;
60
58
  // set participant of the message
61
59
  msgKey.participant = msgKey.participant || message.key.participant;
@@ -63,30 +61,27 @@ const cleanMessage = (message, meId) => {
63
61
  }
64
62
  };
65
63
  exports.cleanMessage = cleanMessage;
66
- const isRealMessage = (message, meId) => {
67
- var _a;
68
- const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
69
- const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
70
- return (!!normalizedContent
71
- || REAL_MSG_STUB_TYPES.has(message.messageStubType)
72
- || (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
73
- && ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
74
- && hasSomeContent
75
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
76
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
77
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
64
+ // TODO: target:audit AUDIT THIS FUNCTION AGAIN
65
+ const isRealMessage = (message) => {
66
+ const normalizedContent = (0, messages_js_1.normalizeMessageContent)(message.message);
67
+ const hasSomeContent = !!(0, messages_js_1.getContentType)(normalizedContent);
68
+ return ((!!normalizedContent ||
69
+ REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
70
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
71
+ hasSomeContent &&
72
+ !normalizedContent?.protocolMessage &&
73
+ !normalizedContent?.reactionMessage &&
74
+ !normalizedContent?.pollUpdateMessage);
78
75
  };
79
76
  exports.isRealMessage = isRealMessage;
80
- const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType);
77
+ const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
81
78
  exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
82
79
  /**
83
80
  * Get the ID of the chat from the given key.
84
81
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
85
82
  */
86
83
  const getChatId = ({ remoteJid, participant, fromMe }) => {
87
- if ((0, WABinary_1.isJidBroadcast)(remoteJid)
88
- && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
89
- && !fromMe) {
84
+ if ((0, index_js_3.isJidBroadcast)(remoteJid) && !(0, index_js_3.isJidStatusBroadcast)(remoteJid) && !fromMe) {
90
85
  return participant;
91
86
  }
92
87
  return remoteJid;
@@ -98,7 +93,7 @@ exports.getChatId = getChatId;
98
93
  * @param ctx additional info about the poll required for decryption
99
94
  * @returns list of SHA256 options
100
95
  */
101
- function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
96
+ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
102
97
  const sign = Buffer.concat([
103
98
  toBinary(pollMsgId),
104
99
  toBinary(pollCreatorJid),
@@ -106,71 +101,74 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
106
101
  toBinary('Poll Vote'),
107
102
  new Uint8Array([1])
108
103
  ]);
109
- const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
110
- const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
104
+ const key0 = (0, crypto_js_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
105
+ const decKey = (0, crypto_js_1.hmacSign)(sign, key0, 'sha256');
111
106
  const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
112
- const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
113
- return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
107
+ const decrypted = (0, crypto_js_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
108
+ return index_js_1.proto.Message.PollVoteMessage.decode(decrypted);
109
+ function toBinary(txt) {
110
+ return Buffer.from(txt);
111
+ }
112
+ }
113
+ /**
114
+ * Decrypt an event response
115
+ * @param response encrypted event response
116
+ * @param ctx additional info about the event required for decryption
117
+ * @returns event response message
118
+ */
119
+ function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
120
+ const sign = Buffer.concat([
121
+ toBinary(eventMsgId),
122
+ toBinary(eventCreatorJid),
123
+ toBinary(responderJid),
124
+ toBinary('Event Response'),
125
+ new Uint8Array([1])
126
+ ]);
127
+ const key0 = (0, crypto_js_1.hmacSign)(eventEncKey, new Uint8Array(32), 'sha256');
128
+ const decKey = (0, crypto_js_1.hmacSign)(sign, key0, 'sha256');
129
+ const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
130
+ const decrypted = (0, crypto_js_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
131
+ return index_js_1.proto.Message.EventResponseMessage.decode(decrypted);
114
132
  function toBinary(txt) {
115
133
  return Buffer.from(txt);
116
134
  }
117
135
  }
118
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
119
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
136
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
120
137
  const meId = creds.me.id;
121
138
  const { accountSettings } = creds;
122
- const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
123
- const isRealMsg = (0, exports.isRealMessage)(message, meId);
139
+ const chat = { id: (0, index_js_3.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
140
+ const isRealMsg = (0, exports.isRealMessage)(message);
124
141
  if (isRealMsg) {
125
142
  chat.messages = [{ message }];
126
- chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
143
+ chat.conversationTimestamp = (0, generics_js_1.toNumber)(message.messageTimestamp);
127
144
  // only increment unread count if not CIPHERTEXT and from another person
128
145
  if ((0, exports.shouldIncrementChatUnread)(message)) {
129
146
  chat.unreadCount = (chat.unreadCount || 0) + 1;
130
147
  }
131
148
  }
132
- const content = (0, messages_1.normalizeMessageContent)(message.message);
133
- const senderId = message.key.participant || message.key.remoteJid;
134
- if ((0, WABinary_1.isLidUser)(senderId)) {
135
- const jid = (0, WABinary_1.lidToJid)(senderId);
136
- if (message.key.participant) {
137
- message.key.participant = jid;
138
- }
139
- else {
140
- message.key.remoteJid = jid;
141
- }
142
- }
143
- const mJids = content && content.contextInfo && content.contextInfo.mentionedJid ? content.contextInfo.mentionedJid : [];
144
- for (let i = 0; i < mJids.length; i++) {
145
- if ((0, WABinary_1.isLidUser)(mJids[i])) {
146
- mJids[i] = (0, WABinary_1.lidToJid)(mJids[i]);
147
- }
148
- }
149
- if (content && content.contextInfo && content.contextInfo.participant && (0, WABinary_1.isLidUser)(content.contextInfo.participant)) {
150
- content.contextInfo.participant = (0, WABinary_1.lidToJid)(content.contextInfo.participant);
151
- }
149
+ const content = (0, messages_js_1.normalizeMessageContent)(message.message);
152
150
  // unarchive chat if it's a real message, or someone reacted to our message
153
151
  // and we've the unarchive chats setting on
154
- if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
155
- && (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
152
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
156
153
  chat.archived = false;
157
154
  chat.readOnly = false;
158
155
  }
159
- const protocolMsg = content === null || content === void 0 ? void 0 : content.protocolMessage;
156
+ const protocolMsg = content?.protocolMessage;
160
157
  if (protocolMsg) {
161
158
  switch (protocolMsg.type) {
162
- case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
159
+ case index_js_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
163
160
  const histNotification = protocolMsg.historySyncNotification;
164
161
  const process = shouldProcessHistoryMsg;
165
- const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
166
- logger === null || logger === void 0 ? void 0 : logger.info({
162
+ const isLatest = !creds.processedHistoryMessages?.length;
163
+ logger?.info({
167
164
  histNotification,
168
165
  process,
169
166
  id: message.key.id,
170
- isLatest,
167
+ isLatest
171
168
  }, 'got history notification');
172
169
  if (process) {
173
- if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
170
+ // TODO: investigate
171
+ if (histNotification.syncType !== index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
174
172
  ev.emit('creds.update', {
175
173
  processedHistoryMessages: [
176
174
  ...(creds.processedHistoryMessages || []),
@@ -178,19 +176,23 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
178
176
  ]
179
177
  });
180
178
  }
181
- const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
179
+ const data = await (0, history_js_1.downloadAndProcessHistorySyncNotification)(histNotification, options, logger);
180
+ if (data.lidPnMappings?.length) {
181
+ logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
182
+ await signalRepository.lidMapping
183
+ .storeLIDPNMappings(data.lidPnMappings)
184
+ .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
185
+ }
182
186
  ev.emit('messaging-history.set', {
183
187
  ...data,
184
- isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
185
- ? isLatest
186
- : undefined,
188
+ isLatest: histNotification.syncType !== index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
187
189
  peerDataRequestSessionId: histNotification.peerDataRequestSessionId
188
190
  });
189
191
  }
190
192
  break;
191
- case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
193
+ case index_js_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
192
194
  const keys = protocolMsg.appStateSyncKeyShare.keys;
193
- if (keys === null || keys === void 0 ? void 0 : keys.length) {
195
+ if (keys?.length) {
194
196
  let newAppStateSyncKeyId = '';
195
197
  await keyStore.transaction(async () => {
196
198
  const newKeys = [];
@@ -200,57 +202,85 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
200
202
  await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
201
203
  newAppStateSyncKeyId = strKeyId;
202
204
  }
203
- logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
204
- });
205
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
206
+ }, meId);
205
207
  ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
206
208
  }
207
209
  else {
208
- logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
210
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
209
211
  }
210
212
  break;
211
- case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
213
+ case index_js_1.proto.Message.ProtocolMessage.Type.REVOKE:
212
214
  ev.emit('messages.update', [
213
215
  {
214
216
  key: {
215
217
  ...message.key,
216
218
  id: protocolMsg.key.id
217
219
  },
218
- update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
220
+ update: { message: null, messageStubType: index_js_2.WAMessageStubType.REVOKE, key: message.key }
219
221
  }
220
222
  ]);
221
223
  break;
222
- case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
224
+ case index_js_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
223
225
  Object.assign(chat, {
224
- ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
226
+ ephemeralSettingTimestamp: (0, generics_js_1.toNumber)(message.messageTimestamp),
225
227
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
226
228
  });
227
229
  break;
228
- case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
230
+ case index_js_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
229
231
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
230
232
  if (response) {
231
- placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
232
233
  // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
233
- const { peerDataOperationResult } = response;
234
+ const peerDataOperationResult = response.peerDataOperationResult || [];
234
235
  for (const result of peerDataOperationResult) {
235
- const { placeholderMessageResendResponse: retryResponse } = result;
236
- if (retryResponse) {
237
- const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
238
- // wait till another upsert event is available, don't want it to be part of the PDO response message
239
- setTimeout(() => {
240
- ev.emit('messages.upsert', {
241
- messages: [webMessageInfo],
242
- type: 'notify',
243
- requestId: response.stanzaId
244
- });
245
- }, 500);
236
+ const retryResponse = result?.placeholderMessageResendResponse;
237
+ //eslint-disable-next-line max-depth
238
+ if (!retryResponse?.webMessageInfoBytes) {
239
+ continue;
240
+ }
241
+ //eslint-disable-next-line max-depth
242
+ try {
243
+ const webMessageInfo = index_js_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
244
+ const msgId = webMessageInfo.key?.id;
245
+ // Retrieve cached original message data (preserves LID details,
246
+ // timestamps, etc. that the phone may omit in its PDO response)
247
+ const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
248
+ //eslint-disable-next-line max-depth
249
+ if (msgId) {
250
+ await placeholderResendCache?.del(msgId);
251
+ }
252
+ let finalMsg;
253
+ //eslint-disable-next-line max-depth
254
+ if (cachedData && typeof cachedData === 'object') {
255
+ // Apply decoded message content onto cached metadata (preserves LID etc.)
256
+ cachedData.message = webMessageInfo.message;
257
+ //eslint-disable-next-line max-depth
258
+ if (webMessageInfo.messageTimestamp) {
259
+ cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
260
+ }
261
+ finalMsg = cachedData;
262
+ }
263
+ else {
264
+ finalMsg = webMessageInfo;
265
+ }
266
+ logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
267
+ ev.emit('messages.upsert', {
268
+ messages: [finalMsg],
269
+ type: 'notify',
270
+ requestId: response.stanzaId
271
+ });
272
+ }
273
+ catch (err) {
274
+ logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
246
275
  }
247
276
  }
248
277
  }
249
- case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
278
+ break;
279
+ case index_js_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
250
280
  ev.emit('messages.update', [
251
281
  {
252
282
  // flip the sender / fromMe properties because they're in the perspective of the sender
253
- key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
283
+ key: { ...message.key, id: protocolMsg.key?.id },
254
284
  update: {
255
285
  message: {
256
286
  editedMessage: {
@@ -258,122 +288,220 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
258
288
  }
259
289
  },
260
290
  messageTimestamp: protocolMsg.timestampMs
261
- ? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
291
+ ? Math.floor((0, generics_js_1.toNumber)(protocolMsg.timestampMs) / 1000)
262
292
  : message.messageTimestamp
263
293
  }
264
294
  }
265
295
  ]);
266
296
  break;
297
+ case index_js_1.proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
298
+ const labelAssociationMsg = protocolMsg.memberLabel;
299
+ if (labelAssociationMsg?.label) {
300
+ ev.emit('group.member-tag.update', {
301
+ groupId: chat.id,
302
+ label: labelAssociationMsg.label,
303
+ participant: message.key.participant,
304
+ participantAlt: message.key.participantAlt,
305
+ messageTimestamp: Number(message.messageTimestamp)
306
+ });
307
+ }
308
+ break;
309
+ case index_js_1.proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
310
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
311
+ const { pnToLidMappings, chatDbMigrationTimestamp } = index_js_1.proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
312
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
313
+ const pairs = [];
314
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
315
+ const lid = latestLid || assignedLid;
316
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
317
+ }
318
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
319
+ if (pairs.length) {
320
+ for (const { pn, lid } of pairs) {
321
+ await signalRepository.migrateSession(pn, lid);
322
+ }
323
+ }
267
324
  }
268
325
  }
269
- else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
326
+ else if (content?.reactionMessage) {
270
327
  const reaction = {
271
328
  ...content.reactionMessage,
272
- key: message.key,
329
+ key: message.key
273
330
  };
274
- ev.emit('messages.reaction', [{
331
+ ev.emit('messages.reaction', [
332
+ {
275
333
  reaction,
276
- key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
277
- }]);
334
+ key: content.reactionMessage?.key
335
+ }
336
+ ]);
337
+ }
338
+ else if (content?.encEventResponseMessage) {
339
+ const encEventResponse = content.encEventResponseMessage;
340
+ const creationMsgKey = encEventResponse.eventCreationMessageKey;
341
+ // we need to fetch the event creation message to get the event enc key
342
+ const eventMsg = await getMessage(creationMsgKey);
343
+ if (eventMsg) {
344
+ try {
345
+ const meIdNormalised = (0, index_js_3.jidNormalizedUser)(meId);
346
+ // all jids need to be PN
347
+ const eventCreatorKey = creationMsgKey.participant || creationMsgKey.remoteJid;
348
+ const eventCreatorPn = (0, index_js_3.isLidUser)(eventCreatorKey)
349
+ ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
350
+ : eventCreatorKey;
351
+ const eventCreatorJid = (0, generics_js_1.getKeyAuthor)({ remoteJid: (0, index_js_3.jidNormalizedUser)(eventCreatorPn), fromMe: meIdNormalised === eventCreatorPn }, meIdNormalised);
352
+ const responderJid = (0, generics_js_1.getKeyAuthor)(message.key, meIdNormalised);
353
+ const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
354
+ if (!eventEncKey) {
355
+ logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
356
+ }
357
+ else {
358
+ const responseMsg = decryptEventResponse(encEventResponse, {
359
+ eventEncKey,
360
+ eventCreatorJid,
361
+ eventMsgId: creationMsgKey.id,
362
+ responderJid
363
+ });
364
+ const eventResponse = {
365
+ eventResponseMessageKey: message.key,
366
+ senderTimestampMs: responseMsg.timestampMs,
367
+ response: responseMsg
368
+ };
369
+ ev.emit('messages.update', [
370
+ {
371
+ key: creationMsgKey,
372
+ update: {
373
+ eventResponses: [eventResponse]
374
+ }
375
+ }
376
+ ]);
377
+ }
378
+ }
379
+ catch (err) {
380
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
381
+ }
382
+ }
383
+ else {
384
+ logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
385
+ }
278
386
  }
279
387
  else if (message.messageStubType) {
280
- const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
388
+ const jid = message.key?.remoteJid;
281
389
  //let actor = whatsappID (message.participant)
282
390
  let participants;
283
- const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
391
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
392
+ id: jid,
393
+ author: message.key.participant,
394
+ authorPn: message.key.participantAlt,
395
+ participants,
396
+ action
397
+ });
284
398
  const emitGroupUpdate = (update) => {
285
- var _a;
286
- ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
399
+ ev.emit('groups.update', [
400
+ { id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
401
+ ]);
287
402
  };
288
403
  const emitGroupRequestJoin = (participant, action, method) => {
289
- ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
404
+ ev.emit('group.join-request', {
405
+ id: jid,
406
+ author: message.key.participant,
407
+ authorPn: message.key.participantAlt,
408
+ participant: participant.lid,
409
+ participantPn: participant.pn,
410
+ action,
411
+ method: method
412
+ });
290
413
  };
291
- const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
414
+ const participantsIncludesMe = () => participants.find(jid => (0, index_js_3.areJidsSameUser)(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
292
415
  switch (message.messageStubType) {
293
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
294
- participants = message.messageStubParameters || [];
416
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
417
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
295
418
  emitParticipantsUpdate('modify');
296
419
  break;
297
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
298
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
299
- participants = message.messageStubParameters || [];
420
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
421
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
422
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
300
423
  emitParticipantsUpdate('remove');
301
424
  // mark the chat read only if you left the group
302
425
  if (participantsIncludesMe()) {
303
426
  chat.readOnly = true;
304
427
  }
305
428
  break;
306
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
307
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
308
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
309
- participants = message.messageStubParameters || [];
429
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD:
430
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
431
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
432
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
310
433
  if (participantsIncludesMe()) {
311
434
  chat.readOnly = false;
312
435
  }
313
436
  emitParticipantsUpdate('add');
314
437
  break;
315
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
316
- participants = message.messageStubParameters || [];
438
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
439
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
317
440
  emitParticipantsUpdate('demote');
318
441
  break;
319
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
320
- participants = message.messageStubParameters || [];
442
+ case index_js_2.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
443
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
321
444
  emitParticipantsUpdate('promote');
322
445
  break;
323
- case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
324
- const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
446
+ case index_js_2.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
447
+ const announceValue = message.messageStubParameters?.[0];
325
448
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
326
449
  break;
327
- case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
328
- const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
450
+ case index_js_2.WAMessageStubType.GROUP_CHANGE_RESTRICT:
451
+ const restrictValue = message.messageStubParameters?.[0];
329
452
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
330
453
  break;
331
- case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
332
- const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
454
+ case index_js_2.WAMessageStubType.GROUP_CHANGE_SUBJECT:
455
+ const name = message.messageStubParameters?.[0];
333
456
  chat.name = name;
334
457
  emitGroupUpdate({ subject: name });
335
458
  break;
336
- case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
337
- const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
459
+ case index_js_2.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
460
+ const description = message.messageStubParameters?.[0];
338
461
  chat.description = description;
339
462
  emitGroupUpdate({ desc: description });
340
463
  break;
341
- case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
342
- const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
464
+ case index_js_2.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
465
+ const code = message.messageStubParameters?.[0];
343
466
  emitGroupUpdate({ inviteCode: code });
344
467
  break;
345
- case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
346
- const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
468
+ case index_js_2.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
469
+ const memberAddValue = message.messageStubParameters?.[0];
347
470
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
348
471
  break;
349
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
350
- const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
472
+ case index_js_2.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
473
+ const approvalMode = message.messageStubParameters?.[0];
351
474
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
352
475
  break;
353
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
354
- const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
355
- const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
356
- const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
476
+ case index_js_2.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
477
+ const participant = JSON.parse(message.messageStubParameters?.[0]);
478
+ const action = message.messageStubParameters?.[1];
479
+ const method = message.messageStubParameters?.[2];
357
480
  emitGroupRequestJoin(participant, action, method);
358
481
  break;
359
482
  }
360
- }
361
- else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
362
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
483
+ } /* else if(content?.pollUpdateMessage) {
484
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
363
485
  // we need to fetch the poll creation message to get the poll enc key
364
- const pollMsg = await getMessage(creationMsgKey);
365
- if (pollMsg) {
366
- const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
367
- const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
368
- const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
369
- const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
486
+ // TODO: make standalone, remove getMessage reference
487
+ // TODO: Remove entirely
488
+ const pollMsg = await getMessage(creationMsgKey)
489
+ if(pollMsg) {
490
+ const meIdNormalised = jidNormalizedUser(meId)
491
+ const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
492
+ const voterJid = getKeyAuthor(message.key, meIdNormalised)
493
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
494
+
370
495
  try {
371
- const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
372
- pollEncKey,
373
- pollCreatorJid,
374
- pollMsgId: creationMsgKey.id,
375
- voterJid,
376
- });
496
+ const voteMsg = decryptPollVote(
497
+ content.pollUpdateMessage.vote!,
498
+ {
499
+ pollEncKey,
500
+ pollCreatorJid,
501
+ pollMsgId: creationMsgKey.id!,
502
+ voterJid,
503
+ }
504
+ )
377
505
  ev.emit('messages.update', [
378
506
  {
379
507
  key: creationMsgKey,
@@ -382,21 +510,25 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
382
510
  {
383
511
  pollUpdateMessageKey: message.key,
384
512
  vote: voteMsg,
385
- senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
513
+ senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
386
514
  }
387
515
  ]
388
516
  }
389
517
  }
390
- ]);
391
- }
392
- catch (err) {
393
- logger === null || logger === void 0 ? void 0 : logger.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
518
+ ])
519
+ } catch(err) {
520
+ logger?.warn(
521
+ { err, creationMsgKey },
522
+ 'failed to decrypt poll vote'
523
+ )
394
524
  }
525
+ } else {
526
+ logger?.warn(
527
+ { creationMsgKey },
528
+ 'poll creation message not found, cannot decrypt update'
529
+ )
395
530
  }
396
- else {
397
- logger === null || logger === void 0 ? void 0 : logger.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update');
398
- }
399
- }
531
+ } */
400
532
  if (Object.keys(chat).length > 1) {
401
533
  ev.emit('chats.update', [chat]);
402
534
  }