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