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