@periskope/baileys 6.7.15-alpha.6 → 6.7.16-alpha.1

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 (149) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +35 -1267
  3. package/WAProto/WAProto.proto +1299 -286
  4. package/WAProto/index.d.ts +16106 -2739
  5. package/WAProto/index.js +128593 -73944
  6. package/engine-requirements.js +10 -0
  7. package/lib/Defaults/baileys-version.json +3 -3
  8. package/lib/Defaults/index.d.ts +51 -53
  9. package/lib/Defaults/index.js +106 -107
  10. package/lib/Signal/libsignal.d.ts +3 -3
  11. package/lib/Signal/libsignal.js +161 -152
  12. package/lib/Socket/Client/index.d.ts +2 -2
  13. package/lib/Socket/Client/index.js +18 -18
  14. package/lib/Socket/Client/types.d.ts +15 -17
  15. package/lib/Socket/Client/types.js +13 -13
  16. package/lib/Socket/Client/websocket.d.ts +12 -12
  17. package/lib/Socket/Client/websocket.js +62 -62
  18. package/lib/Socket/business.d.ts +145 -149
  19. package/lib/Socket/business.js +260 -260
  20. package/lib/Socket/chats.d.ts +84 -85
  21. package/lib/Socket/chats.js +879 -850
  22. package/lib/Socket/groups.d.ts +123 -124
  23. package/lib/Socket/groups.js +314 -314
  24. package/lib/Socket/index.d.ts +145 -149
  25. package/lib/Socket/index.js +10 -10
  26. package/lib/Socket/messages-recv.d.ts +134 -136
  27. package/lib/Socket/messages-recv.js +925 -917
  28. package/lib/Socket/messages-send.d.ts +129 -130
  29. package/lib/Socket/messages-send.js +683 -673
  30. package/lib/Socket/socket.d.ts +43 -45
  31. package/lib/Socket/socket.js +622 -622
  32. package/lib/Socket/usync.d.ts +36 -38
  33. package/lib/Socket/usync.js +70 -70
  34. package/lib/Types/Auth.d.ts +103 -105
  35. package/lib/Types/Auth.js +2 -2
  36. package/lib/Types/Call.d.ts +13 -13
  37. package/lib/Types/Call.js +2 -2
  38. package/lib/Types/Chat.d.ts +112 -108
  39. package/lib/Types/Chat.js +4 -4
  40. package/lib/Types/Contact.d.ts +19 -19
  41. package/lib/Types/Contact.js +2 -2
  42. package/lib/Types/Events.d.ts +175 -175
  43. package/lib/Types/Events.js +2 -2
  44. package/lib/Types/GroupMetadata.d.ts +56 -56
  45. package/lib/Types/GroupMetadata.js +2 -2
  46. package/lib/Types/Label.d.ts +46 -46
  47. package/lib/Types/Label.js +27 -27
  48. package/lib/Types/LabelAssociation.d.ts +29 -29
  49. package/lib/Types/LabelAssociation.js +9 -9
  50. package/lib/Types/Message.d.ts +267 -271
  51. package/lib/Types/Message.js +9 -9
  52. package/lib/Types/Product.d.ts +78 -78
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.d.ts +57 -57
  55. package/lib/Types/Signal.js +2 -2
  56. package/lib/Types/Socket.d.ts +121 -118
  57. package/lib/Types/Socket.js +2 -2
  58. package/lib/Types/State.d.ts +27 -27
  59. package/lib/Types/State.js +2 -2
  60. package/lib/Types/USync.d.ts +25 -25
  61. package/lib/Types/USync.js +2 -2
  62. package/lib/Types/index.d.ts +63 -63
  63. package/lib/Types/index.js +41 -41
  64. package/lib/Utils/auth-utils.d.ts +18 -18
  65. package/lib/Utils/auth-utils.js +200 -200
  66. package/lib/Utils/baileys-event-stream.d.ts +16 -16
  67. package/lib/Utils/baileys-event-stream.js +63 -63
  68. package/lib/Utils/business.d.ts +22 -22
  69. package/lib/Utils/business.js +234 -234
  70. package/lib/Utils/chat-utils.d.ts +70 -72
  71. package/lib/Utils/chat-utils.js +745 -745
  72. package/lib/Utils/crypto.d.ts +40 -42
  73. package/lib/Utils/crypto.js +193 -181
  74. package/lib/Utils/decode-wa-message.d.ts +36 -36
  75. package/lib/Utils/decode-wa-message.js +205 -205
  76. package/lib/Utils/event-buffer.d.ts +35 -35
  77. package/lib/Utils/event-buffer.js +520 -520
  78. package/lib/Utils/generics.d.ts +90 -94
  79. package/lib/Utils/generics.js +398 -433
  80. package/lib/Utils/history.d.ts +19 -19
  81. package/lib/Utils/history.js +94 -94
  82. package/lib/Utils/index.d.ts +17 -17
  83. package/lib/Utils/index.js +33 -33
  84. package/lib/Utils/link-preview.d.ts +21 -21
  85. package/lib/Utils/link-preview.js +129 -119
  86. package/lib/Utils/logger.d.ts +11 -11
  87. package/lib/Utils/logger.js +7 -7
  88. package/lib/Utils/lt-hash.d.ts +12 -12
  89. package/lib/Utils/lt-hash.js +51 -51
  90. package/lib/Utils/make-mutex.d.ts +7 -7
  91. package/lib/Utils/make-mutex.js +44 -44
  92. package/lib/Utils/messages-media.d.ts +105 -109
  93. package/lib/Utils/messages-media.js +704 -694
  94. package/lib/Utils/messages.d.ts +75 -78
  95. package/lib/Utils/messages.js +761 -762
  96. package/lib/Utils/noise-handler.d.ts +19 -21
  97. package/lib/Utils/noise-handler.js +150 -150
  98. package/lib/Utils/process-message.d.ts +41 -42
  99. package/lib/Utils/process-message.js +385 -376
  100. package/lib/Utils/signal.d.ts +33 -33
  101. package/lib/Utils/signal.js +153 -153
  102. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -12
  103. package/lib/Utils/use-multi-file-auth-state.js +125 -94
  104. package/lib/Utils/validate-connection.d.ts +10 -10
  105. package/lib/Utils/validate-connection.js +175 -175
  106. package/lib/WABinary/constants.d.ts +27 -27
  107. package/lib/WABinary/constants.js +40 -40
  108. package/lib/WABinary/decode.d.ts +6 -8
  109. package/lib/WABinary/decode.js +264 -254
  110. package/lib/WABinary/encode.d.ts +2 -4
  111. package/lib/WABinary/encode.js +244 -234
  112. package/lib/WABinary/generic-utils.d.ts +14 -16
  113. package/lib/WABinary/generic-utils.js +110 -110
  114. package/lib/WABinary/index.d.ts +5 -5
  115. package/lib/WABinary/index.js +21 -21
  116. package/lib/WABinary/jid-utils.d.ts +33 -31
  117. package/lib/WABinary/jid-utils.js +66 -62
  118. package/lib/WABinary/types.d.ts +18 -18
  119. package/lib/WABinary/types.js +2 -2
  120. package/lib/WAM/BinaryInfo.d.ts +8 -18
  121. package/lib/WAM/BinaryInfo.js +13 -13
  122. package/lib/WAM/constants.d.ts +39 -39
  123. package/lib/WAM/constants.js +15350 -15350
  124. package/lib/WAM/encode.d.ts +2 -4
  125. package/lib/WAM/encode.js +155 -155
  126. package/lib/WAM/index.d.ts +3 -3
  127. package/lib/WAM/index.js +19 -19
  128. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  129. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -32
  130. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -22
  131. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -57
  132. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -12
  133. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -30
  134. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -12
  135. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -42
  136. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  137. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  138. package/lib/WAUSync/Protocols/index.d.ts +4 -4
  139. package/lib/WAUSync/Protocols/index.js +20 -20
  140. package/lib/WAUSync/USyncQuery.d.ts +26 -26
  141. package/lib/WAUSync/USyncQuery.js +79 -79
  142. package/lib/WAUSync/USyncUser.d.ts +12 -10
  143. package/lib/WAUSync/USyncUser.js +26 -22
  144. package/lib/WAUSync/index.d.ts +3 -3
  145. package/lib/WAUSync/index.js +19 -19
  146. package/lib/index.d.ts +11 -12
  147. package/lib/index.js +30 -31
  148. package/package.json +20 -26
  149. package/WAProto/GenerateStatics.sh +0 -4
@@ -1,376 +1,385 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptPollVote = exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
- const WAProto_1 = require("../../WAProto");
5
- const Types_1 = require("../Types");
6
- const messages_1 = require("../Utils/messages");
7
- const WABinary_1 = require("../WABinary");
8
- const crypto_1 = require("./crypto");
9
- const generics_1 = require("./generics");
10
- const history_1 = require("./history");
11
- const REAL_MSG_STUB_TYPES = new Set([
12
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
13
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
14
- Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
15
- Types_1.WAMessageStubType.CALL_MISSED_VOICE
16
- ]);
17
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
18
- Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
19
- ]);
20
- /** Cleans a received message to further processing */
21
- const cleanMessage = (message, meId) => {
22
- // ensure remoteJid and participant doesn't have device or agent in it
23
- message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
24
- message.key.participant = message.key.participant ? (0, WABinary_1.jidNormalizedUser)(message.key.participant) : undefined;
25
- const content = (0, messages_1.normalizeMessageContent)(message.message);
26
- // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
27
- if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
28
- normaliseKey(content.reactionMessage.key);
29
- }
30
- if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
31
- normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
32
- }
33
- function normaliseKey(msgKey) {
34
- // if the reaction is from another user
35
- // we've to correctly map the key to this user's perspective
36
- if (!message.key.fromMe) {
37
- // if the sender believed the message being reacted to is not from them
38
- // we've to correct the key to be from them, or some other participant
39
- msgKey.fromMe = !msgKey.fromMe
40
- ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
41
- // if the message being reacted to, was from them
42
- // fromMe automatically becomes false
43
- : false;
44
- // set the remoteJid to being the same as the chat the message came from
45
- msgKey.remoteJid = message.key.remoteJid;
46
- // set participant of the message
47
- msgKey.participant = msgKey.participant || message.key.participant;
48
- }
49
- }
50
- };
51
- exports.cleanMessage = cleanMessage;
52
- const isRealMessage = (message, meId) => {
53
- var _a;
54
- const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
55
- const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
56
- return (!!normalizedContent
57
- || REAL_MSG_STUB_TYPES.has(message.messageStubType)
58
- || (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
59
- && ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
60
- && hasSomeContent
61
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
62
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
63
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
64
- };
65
- exports.isRealMessage = isRealMessage;
66
- const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType);
67
- exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
68
- /**
69
- * Get the ID of the chat from the given key.
70
- * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
71
- */
72
- const getChatId = ({ remoteJid, participant, fromMe }) => {
73
- if ((0, WABinary_1.isJidBroadcast)(remoteJid)
74
- && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
75
- && !fromMe) {
76
- return participant;
77
- }
78
- return remoteJid;
79
- };
80
- exports.getChatId = getChatId;
81
- /**
82
- * Decrypt a poll vote
83
- * @param vote encrypted vote
84
- * @param ctx additional info about the poll required for decryption
85
- * @returns list of SHA256 options
86
- */
87
- function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
88
- if (typeof pollEncKey === 'string') {
89
- pollEncKey = Uint8Array.from(atob(pollEncKey), (c) => c.charCodeAt(0));
90
- }
91
- const sign = Buffer.concat([
92
- toBinary(pollMsgId),
93
- toBinary(pollCreatorJid),
94
- toBinary(voterJid),
95
- toBinary('Poll Vote'),
96
- new Uint8Array([1])
97
- ]);
98
- const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
99
- const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
100
- const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
101
- const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
102
- return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
103
- function toBinary(txt) {
104
- return Buffer.from(txt);
105
- }
106
- }
107
- exports.decryptPollVote = decryptPollVote;
108
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
109
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
110
- const meId = creds.me.id;
111
- const { accountSettings } = creds;
112
- const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
113
- const isRealMsg = (0, exports.isRealMessage)(message, meId);
114
- if (isRealMsg) {
115
- chat.messages = [{ message }];
116
- chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
117
- // only increment unread count if not CIPHERTEXT and from another person
118
- if ((0, exports.shouldIncrementChatUnread)(message)) {
119
- chat.unreadCount = (chat.unreadCount || 0) + 1;
120
- }
121
- }
122
- const content = (0, messages_1.normalizeMessageContent)(message.message);
123
- // unarchive chat if it's a real message, or someone reacted to our message
124
- // and we've the unarchive chats setting on
125
- 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))
126
- && (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
127
- chat.archived = false;
128
- chat.readOnly = false;
129
- }
130
- const protocolMsg = content === null || content === void 0 ? void 0 : content.protocolMessage;
131
- if (protocolMsg) {
132
- switch (protocolMsg.type) {
133
- case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
134
- const histNotification = protocolMsg.historySyncNotification;
135
- const process = shouldProcessHistoryMsg;
136
- const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
137
- logger === null || logger === void 0 ? void 0 : logger.info({
138
- histNotification,
139
- process,
140
- id: message.key.id,
141
- isLatest,
142
- }, 'got history notification');
143
- if (process) {
144
- if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
145
- ev.emit('creds.update', {
146
- processedHistoryMessages: [
147
- ...(creds.processedHistoryMessages || []),
148
- { key: message.key, messageTimestamp: message.messageTimestamp }
149
- ]
150
- });
151
- }
152
- const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
153
- ev.emit('messaging-history.set', {
154
- ...data,
155
- isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
156
- ? isLatest
157
- : undefined,
158
- peerDataRequestSessionId: histNotification.peerDataRequestSessionId
159
- });
160
- }
161
- break;
162
- case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
163
- const keys = protocolMsg.appStateSyncKeyShare.keys;
164
- if (keys === null || keys === void 0 ? void 0 : keys.length) {
165
- let newAppStateSyncKeyId = '';
166
- await keyStore.transaction(async () => {
167
- const newKeys = [];
168
- for (const { keyData, keyId } of keys) {
169
- const strKeyId = Buffer.from(keyId.keyId).toString('base64');
170
- newKeys.push(strKeyId);
171
- await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
172
- newAppStateSyncKeyId = strKeyId;
173
- }
174
- logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
175
- });
176
- ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
177
- }
178
- else {
179
- logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
180
- }
181
- break;
182
- case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
183
- ev.emit('messages.update', [
184
- {
185
- key: {
186
- ...message.key,
187
- id: protocolMsg.key.id
188
- },
189
- update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
190
- }
191
- ]);
192
- break;
193
- case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
194
- Object.assign(chat, {
195
- ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
196
- ephemeralExpiration: protocolMsg.ephemeralExpiration || null
197
- });
198
- break;
199
- case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
200
- const response = protocolMsg.peerDataOperationRequestResponseMessage;
201
- if (response) {
202
- placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
203
- // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
204
- const { peerDataOperationResult } = response;
205
- for (const result of peerDataOperationResult) {
206
- const { placeholderMessageResendResponse: retryResponse } = result;
207
- //eslint-disable-next-line max-depth
208
- if (retryResponse) {
209
- const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
210
- // wait till another upsert event is available, don't want it to be part of the PDO response message
211
- setTimeout(() => {
212
- ev.emit('messages.upsert', {
213
- messages: [webMessageInfo],
214
- type: 'notify',
215
- requestId: response.stanzaId
216
- });
217
- }, 500);
218
- }
219
- }
220
- }
221
- case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
222
- ev.emit('messages.update', [
223
- {
224
- // flip the sender / fromMe properties because they're in the perspective of the sender
225
- key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
226
- update: {
227
- message: {
228
- editedMessage: {
229
- message: protocolMsg.editedMessage
230
- }
231
- },
232
- messageTimestamp: protocolMsg.timestampMs
233
- ? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
234
- : message.messageTimestamp
235
- }
236
- }
237
- ]);
238
- break;
239
- }
240
- }
241
- else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
242
- const reaction = {
243
- ...content.reactionMessage,
244
- key: message.key,
245
- };
246
- ev.emit('messages.reaction', [{
247
- reaction,
248
- key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
249
- }]);
250
- }
251
- else if (message.messageStubType) {
252
- const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
253
- //let actor = whatsappID (message.participant)
254
- let participants;
255
- const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
256
- const emitGroupUpdate = (update) => {
257
- var _a;
258
- ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
259
- };
260
- const emitGroupRequestJoin = (participant, action, method) => {
261
- ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
262
- };
263
- const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
264
- switch (message.messageStubType) {
265
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
266
- participants = message.messageStubParameters || [];
267
- emitParticipantsUpdate('modify');
268
- break;
269
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
270
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
271
- participants = message.messageStubParameters || [];
272
- emitParticipantsUpdate('remove');
273
- // mark the chat read only if you left the group
274
- if (participantsIncludesMe()) {
275
- chat.readOnly = true;
276
- }
277
- break;
278
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
279
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
280
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
281
- participants = message.messageStubParameters || [];
282
- if (participantsIncludesMe()) {
283
- chat.readOnly = false;
284
- }
285
- emitParticipantsUpdate('add');
286
- break;
287
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
288
- participants = message.messageStubParameters || [];
289
- emitParticipantsUpdate('demote');
290
- break;
291
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
292
- participants = message.messageStubParameters || [];
293
- emitParticipantsUpdate('promote');
294
- break;
295
- case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
296
- const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
297
- emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
298
- break;
299
- case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
300
- const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
301
- emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
302
- break;
303
- case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
304
- const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
305
- chat.name = name;
306
- emitGroupUpdate({ subject: name });
307
- break;
308
- case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
309
- const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
310
- chat.description = description;
311
- emitGroupUpdate({ desc: description });
312
- break;
313
- case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
314
- const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
315
- emitGroupUpdate({ inviteCode: code });
316
- break;
317
- case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
318
- const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
319
- emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
320
- break;
321
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
322
- const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
323
- emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
324
- break;
325
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
326
- const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
327
- const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
328
- const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
329
- emitGroupRequestJoin(participant, action, method);
330
- break;
331
- }
332
- }
333
- else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
334
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
335
- // we need to fetch the poll creation message to get the poll enc key
336
- const pollMsg = await getMessage(creationMsgKey);
337
- if (pollMsg) {
338
- const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
339
- const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
340
- const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
341
- const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
342
- try {
343
- const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
344
- pollEncKey,
345
- pollCreatorJid,
346
- pollMsgId: creationMsgKey.id,
347
- voterJid,
348
- });
349
- ev.emit('messages.update', [
350
- {
351
- key: creationMsgKey,
352
- update: {
353
- pollUpdates: [
354
- {
355
- pollUpdateMessageKey: message.key,
356
- vote: voteMsg,
357
- senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
358
- }
359
- ]
360
- }
361
- }
362
- ]);
363
- }
364
- catch (err) {
365
- logger === null || logger === void 0 ? void 0 : logger.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
366
- }
367
- }
368
- else {
369
- logger === null || logger === void 0 ? void 0 : logger.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update');
370
- }
371
- }
372
- if (Object.keys(chat).length > 1) {
373
- ev.emit('chats.update', [chat]);
374
- }
375
- };
376
- exports.default = processMessage;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
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");
12
+ 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
20
+ ]);
21
+ /** Cleans a received message to further processing */
22
+ const cleanMessage = (message, meId) => {
23
+ // ensure remoteJid and participant doesn't have device or agent in it
24
+ message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
25
+ message.key.participant = message.key.participant ? (0, WABinary_1.jidNormalizedUser)(message.key.participant) : undefined;
26
+ const content = (0, messages_1.normalizeMessageContent)(message.message);
27
+ // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
28
+ if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
29
+ normaliseKey(content.reactionMessage.key);
30
+ }
31
+ if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
32
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
33
+ }
34
+ function normaliseKey(msgKey) {
35
+ // if the reaction is from another user
36
+ // we've to correctly map the key to this user's perspective
37
+ if (!message.key.fromMe) {
38
+ // if the sender believed the message being reacted to is not from them
39
+ // we've to correct the key to be from them, or some other participant
40
+ msgKey.fromMe = !msgKey.fromMe
41
+ ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
42
+ // if the message being reacted to, was from them
43
+ // fromMe automatically becomes false
44
+ : false;
45
+ // set the remoteJid to being the same as the chat the message came from
46
+ msgKey.remoteJid = message.key.remoteJid;
47
+ // set participant of the message
48
+ msgKey.participant = msgKey.participant || message.key.participant;
49
+ }
50
+ }
51
+ };
52
+ exports.cleanMessage = cleanMessage;
53
+ const isRealMessage = (message, meId) => {
54
+ var _a;
55
+ const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
56
+ const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
57
+ return (!!normalizedContent
58
+ || REAL_MSG_STUB_TYPES.has(message.messageStubType)
59
+ || (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
60
+ && ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
61
+ && hasSomeContent
62
+ && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
63
+ && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
64
+ && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
65
+ };
66
+ exports.isRealMessage = isRealMessage;
67
+ const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType);
68
+ exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
69
+ /**
70
+ * Get the ID of the chat from the given key.
71
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
72
+ */
73
+ const getChatId = ({ remoteJid, participant, fromMe }) => {
74
+ if ((0, WABinary_1.isJidBroadcast)(remoteJid)
75
+ && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
76
+ && !fromMe) {
77
+ return participant;
78
+ }
79
+ return remoteJid;
80
+ };
81
+ exports.getChatId = getChatId;
82
+ /**
83
+ * Decrypt a poll vote
84
+ * @param vote encrypted vote
85
+ * @param ctx additional info about the poll required for decryption
86
+ * @returns list of SHA256 options
87
+ */
88
+ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
89
+ if (typeof pollEncKey === 'string') {
90
+ pollEncKey = Uint8Array.from(atob(pollEncKey), (c) => c.charCodeAt(0));
91
+ }
92
+ const sign = Buffer.concat([
93
+ toBinary(pollMsgId),
94
+ toBinary(pollCreatorJid),
95
+ toBinary(voterJid),
96
+ toBinary('Poll Vote'),
97
+ new Uint8Array([1])
98
+ ]);
99
+ const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
100
+ const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
101
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
102
+ const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
103
+ return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
104
+ function toBinary(txt) {
105
+ return Buffer.from(txt);
106
+ }
107
+ }
108
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options }) => {
109
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
110
+ const meId = creds.me.id;
111
+ const { accountSettings } = creds;
112
+ const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
113
+ const isRealMsg = (0, exports.isRealMessage)(message, meId);
114
+ if (isRealMsg) {
115
+ chat.messages = [{ message }];
116
+ chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
117
+ // only increment unread count if not CIPHERTEXT and from another person
118
+ if ((0, exports.shouldIncrementChatUnread)(message)) {
119
+ chat.unreadCount = (chat.unreadCount || 0) + 1;
120
+ }
121
+ }
122
+ const content = (0, messages_1.normalizeMessageContent)(message.message);
123
+ // unarchive chat if it's a real message, or someone reacted to our message
124
+ // and we've the unarchive chats setting on
125
+ 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))
126
+ && (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
127
+ chat.archived = false;
128
+ chat.readOnly = false;
129
+ }
130
+ const protocolMsg = content === null || content === void 0 ? void 0 : content.protocolMessage;
131
+ if (protocolMsg) {
132
+ switch (protocolMsg.type) {
133
+ case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
134
+ const histNotification = protocolMsg.historySyncNotification;
135
+ const process = shouldProcessHistoryMsg;
136
+ const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
137
+ logger === null || logger === void 0 ? void 0 : logger.info({
138
+ histNotification,
139
+ process,
140
+ id: message.key.id,
141
+ isLatest,
142
+ }, 'got history notification');
143
+ if (process) {
144
+ if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
145
+ ev.emit('creds.update', {
146
+ processedHistoryMessages: [
147
+ ...(creds.processedHistoryMessages || []),
148
+ { key: message.key, messageTimestamp: message.messageTimestamp }
149
+ ]
150
+ });
151
+ }
152
+ const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
153
+ ev.emit('messaging-history.set', {
154
+ ...data,
155
+ isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
156
+ ? isLatest
157
+ : undefined,
158
+ peerDataRequestSessionId: histNotification.peerDataRequestSessionId
159
+ });
160
+ }
161
+ break;
162
+ case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
163
+ const keys = protocolMsg.appStateSyncKeyShare.keys;
164
+ if (keys === null || keys === void 0 ? void 0 : keys.length) {
165
+ let newAppStateSyncKeyId = '';
166
+ await keyStore.transaction(async () => {
167
+ const newKeys = [];
168
+ for (const { keyData, keyId } of keys) {
169
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64');
170
+ newKeys.push(strKeyId);
171
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
172
+ newAppStateSyncKeyId = strKeyId;
173
+ }
174
+ logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
175
+ });
176
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
177
+ }
178
+ else {
179
+ logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
180
+ }
181
+ break;
182
+ case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
183
+ ev.emit('messages.update', [
184
+ {
185
+ key: {
186
+ ...message.key,
187
+ id: protocolMsg.key.id
188
+ },
189
+ update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
190
+ }
191
+ ]);
192
+ break;
193
+ case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
194
+ Object.assign(chat, {
195
+ ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
196
+ ephemeralExpiration: protocolMsg.ephemeralExpiration || null
197
+ });
198
+ break;
199
+ case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
200
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
201
+ if (response) {
202
+ placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
203
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
204
+ const { peerDataOperationResult } = response;
205
+ for (const result of peerDataOperationResult) {
206
+ const { placeholderMessageResendResponse: retryResponse } = result;
207
+ //eslint-disable-next-line max-depth
208
+ if (retryResponse) {
209
+ const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
210
+ // wait till another upsert event is available, don't want it to be part of the PDO response message
211
+ setTimeout(() => {
212
+ ev.emit('messages.upsert', {
213
+ messages: [webMessageInfo],
214
+ type: 'notify',
215
+ requestId: response.stanzaId
216
+ });
217
+ }, 500);
218
+ }
219
+ }
220
+ }
221
+ case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
222
+ ev.emit('messages.update', [
223
+ {
224
+ // flip the sender / fromMe properties because they're in the perspective of the sender
225
+ key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
226
+ update: {
227
+ message: {
228
+ editedMessage: {
229
+ message: protocolMsg.editedMessage
230
+ }
231
+ },
232
+ messageTimestamp: protocolMsg.timestampMs
233
+ ? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
234
+ : message.messageTimestamp
235
+ }
236
+ }
237
+ ]);
238
+ break;
239
+ }
240
+ }
241
+ else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
242
+ const reaction = {
243
+ ...content.reactionMessage,
244
+ key: message.key,
245
+ };
246
+ ev.emit('messages.reaction', [{
247
+ reaction,
248
+ key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
249
+ }]);
250
+ }
251
+ else if (message.messageStubType) {
252
+ const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
253
+ //let actor = whatsappID (message.participant)
254
+ let participants;
255
+ const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
256
+ const emitGroupUpdate = (update) => {
257
+ var _a;
258
+ ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
259
+ };
260
+ const emitGroupRequestJoin = (participant, action, method) => {
261
+ ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
262
+ };
263
+ const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
264
+ switch (message.messageStubType) {
265
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
266
+ participants = message.messageStubParameters || [];
267
+ emitParticipantsUpdate('modify');
268
+ break;
269
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
270
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
271
+ participants = message.messageStubParameters || [];
272
+ emitParticipantsUpdate('remove');
273
+ // mark the chat read only if you left the group
274
+ if (participantsIncludesMe()) {
275
+ chat.readOnly = true;
276
+ }
277
+ break;
278
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
279
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
280
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
281
+ participants = message.messageStubParameters || [];
282
+ if (participantsIncludesMe()) {
283
+ chat.readOnly = false;
284
+ }
285
+ emitParticipantsUpdate('add');
286
+ break;
287
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
288
+ participants = message.messageStubParameters || [];
289
+ emitParticipantsUpdate('demote');
290
+ break;
291
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
292
+ participants = message.messageStubParameters || [];
293
+ emitParticipantsUpdate('promote');
294
+ break;
295
+ case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
296
+ const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
297
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
298
+ break;
299
+ case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
300
+ const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
301
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
302
+ break;
303
+ case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
304
+ const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
305
+ chat.name = name;
306
+ emitGroupUpdate({ subject: name });
307
+ break;
308
+ case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
309
+ const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
310
+ chat.description = description;
311
+ emitGroupUpdate({ desc: description });
312
+ break;
313
+ case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
314
+ const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
315
+ emitGroupUpdate({ inviteCode: code });
316
+ break;
317
+ case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
318
+ const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
319
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
320
+ break;
321
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
322
+ const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
323
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
324
+ break;
325
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
326
+ const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
327
+ const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
328
+ const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
329
+ emitGroupRequestJoin(participant, action, method);
330
+ break;
331
+ }
332
+ } /* else if(content?.pollUpdateMessage) {
333
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
334
+ // we need to fetch the poll creation message to get the poll enc key
335
+ // TODO: make standalone, remove getMessage reference
336
+ // TODO: Remove entirely
337
+ const pollMsg = await getMessage(creationMsgKey)
338
+ if(pollMsg) {
339
+ const meIdNormalised = jidNormalizedUser(meId)
340
+ const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
341
+ const voterJid = getKeyAuthor(message.key, meIdNormalised)
342
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
343
+
344
+ try {
345
+ const voteMsg = decryptPollVote(
346
+ content.pollUpdateMessage.vote!,
347
+ {
348
+ pollEncKey,
349
+ pollCreatorJid,
350
+ pollMsgId: creationMsgKey.id!,
351
+ voterJid,
352
+ }
353
+ )
354
+ ev.emit('messages.update', [
355
+ {
356
+ key: creationMsgKey,
357
+ update: {
358
+ pollUpdates: [
359
+ {
360
+ pollUpdateMessageKey: message.key,
361
+ vote: voteMsg,
362
+ senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
363
+ }
364
+ ]
365
+ }
366
+ }
367
+ ])
368
+ } catch(err) {
369
+ logger?.warn(
370
+ { err, creationMsgKey },
371
+ 'failed to decrypt poll vote'
372
+ )
373
+ }
374
+ } else {
375
+ logger?.warn(
376
+ { creationMsgKey },
377
+ 'poll creation message not found, cannot decrypt update'
378
+ )
379
+ }
380
+ } */
381
+ if (Object.keys(chat).length > 1) {
382
+ ev.emit('chats.update', [chat]);
383
+ }
384
+ };
385
+ exports.default = processMessage;