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