@d0v3riz/baileys 6.7.22 → 6.7.23
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 -2
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +4136 -4138
- package/lib/Defaults/index.d.ts +3 -2
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +36 -40
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +4 -3
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +3 -2
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +14 -16
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +2 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +8 -44
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +5 -5
- package/lib/Signal/Group/queue-job.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +7 -9
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +6 -9
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +10 -12
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +2 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +9 -12
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +3 -2
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +6 -9
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +5 -7
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +3 -2
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +22 -55
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +2 -1
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +2 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +14 -26
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +66 -64
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +32 -37
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +21 -19
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +176 -141
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +219 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +37 -35
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +56 -63
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +102 -70
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +16 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +51 -49
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +180 -173
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +48 -46
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +75 -84
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +2 -1
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +12 -16
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +46 -44
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +23 -27
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +13 -12
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +135 -115
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +15 -14
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +9 -11
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +4 -3
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +10 -7
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +2 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +11 -10
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +3 -2
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +1 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +9 -7
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +1 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +5 -7
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +2 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +8 -7
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +15 -14
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -31
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +3 -2
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +25 -34
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +2 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/baileys-event-stream.js.map +1 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +61 -70
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +8 -7
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +130 -137
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +2 -1
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +37 -86
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +5 -4
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +38 -44
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +37 -50
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +9 -8
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +87 -114
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +4 -3
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +32 -40
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +18 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +18 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -3
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +10 -47
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +8 -6
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +9 -8
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +5 -9
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +11 -10
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +141 -203
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +7 -6
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +190 -199
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +22 -26
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +95 -104
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +5 -4
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +47 -52
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -26
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +52 -58
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +1 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +9 -11
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +13 -51
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +5 -41
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +4 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +30 -38
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +21 -35
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -1
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +1 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +4 -6
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +12 -14
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +19 -21
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +4 -3
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +18 -20
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +9 -8
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -30
- package/lib/index.js.map +1 -0
- package/package.json +26 -26
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const generics_1 = require("./generics");
|
|
10
|
-
const lt_hash_1 = require("./lt-hash");
|
|
11
|
-
const messages_media_1 = require("./messages-media");
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
4
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidNormalizedUser } from '../WABinary/index.js';
|
|
5
|
+
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto.js';
|
|
6
|
+
import { toNumber } from './generics.js';
|
|
7
|
+
import { LT_HASH_ANTI_TAMPERING } from './lt-hash.js';
|
|
8
|
+
import { downloadContentFromMessage } from './messages-media.js';
|
|
12
9
|
const mutationKeys = async (keydata) => {
|
|
13
|
-
const expanded = await
|
|
10
|
+
const expanded = await hkdf(keydata, 160, { info: 'WhatsApp Mutation Keys' });
|
|
14
11
|
return {
|
|
15
12
|
indexKey: expanded.slice(0, 32),
|
|
16
13
|
valueEncryptionKey: expanded.slice(32, 64),
|
|
@@ -23,10 +20,10 @@ const generateMac = (operation, data, keyId, key) => {
|
|
|
23
20
|
const getKeyData = () => {
|
|
24
21
|
let r;
|
|
25
22
|
switch (operation) {
|
|
26
|
-
case
|
|
23
|
+
case proto.SyncdMutation.SyncdOperation.SET:
|
|
27
24
|
r = 0x01;
|
|
28
25
|
break;
|
|
29
|
-
case
|
|
26
|
+
case proto.SyncdMutation.SyncdOperation.REMOVE:
|
|
30
27
|
r = 0x02;
|
|
31
28
|
break;
|
|
32
29
|
}
|
|
@@ -37,7 +34,7 @@ const generateMac = (operation, data, keyId, key) => {
|
|
|
37
34
|
const last = Buffer.alloc(8); // 8 bytes
|
|
38
35
|
last.set([keyData.length], last.length - 1);
|
|
39
36
|
const total = Buffer.concat([keyData, data, last]);
|
|
40
|
-
const hmac =
|
|
37
|
+
const hmac = hmacSign(total, key, 'sha512');
|
|
41
38
|
return hmac.slice(0, 32);
|
|
42
39
|
};
|
|
43
40
|
const to64BitNetworkOrder = (e) => {
|
|
@@ -53,9 +50,9 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
53
50
|
mix: ({ indexMac, valueMac, operation }) => {
|
|
54
51
|
const indexMacBase64 = Buffer.from(indexMac).toString('base64');
|
|
55
52
|
const prevOp = indexValueMap[indexMacBase64];
|
|
56
|
-
if (operation ===
|
|
53
|
+
if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
57
54
|
if (!prevOp) {
|
|
58
|
-
throw new
|
|
55
|
+
throw new Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
|
|
59
56
|
}
|
|
60
57
|
// remove from index value mac, since this mutation is erased
|
|
61
58
|
delete indexValueMap[indexMacBase64];
|
|
@@ -71,7 +68,7 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
71
68
|
},
|
|
72
69
|
finish: async () => {
|
|
73
70
|
const hashArrayBuffer = new Uint8Array(hash).buffer;
|
|
74
|
-
const result = await
|
|
71
|
+
const result = await LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
75
72
|
const buffer = Buffer.from(result);
|
|
76
73
|
return {
|
|
77
74
|
hash: buffer,
|
|
@@ -82,33 +79,32 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
82
79
|
};
|
|
83
80
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
84
81
|
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
85
|
-
return
|
|
82
|
+
return hmacSign(total, key, 'sha256');
|
|
86
83
|
};
|
|
87
84
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
88
85
|
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
89
|
-
return
|
|
86
|
+
return hmacSign(total, key);
|
|
90
87
|
};
|
|
91
|
-
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
92
|
-
|
|
93
|
-
const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
88
|
+
export const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
89
|
+
export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
94
90
|
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
95
91
|
if (!key) {
|
|
96
|
-
throw new
|
|
92
|
+
throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
|
|
97
93
|
}
|
|
98
94
|
const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
|
|
99
95
|
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
100
96
|
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
101
|
-
const dataProto =
|
|
97
|
+
const dataProto = proto.SyncActionData.fromObject({
|
|
102
98
|
index: indexBuffer,
|
|
103
99
|
value: syncAction,
|
|
104
100
|
padding: new Uint8Array(0),
|
|
105
101
|
version: apiVersion
|
|
106
102
|
});
|
|
107
|
-
const encoded =
|
|
103
|
+
const encoded = proto.SyncActionData.encode(dataProto).finish();
|
|
108
104
|
const keyValue = await mutationKeys(key.keyData);
|
|
109
|
-
const encValue =
|
|
105
|
+
const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
|
|
110
106
|
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
111
|
-
const indexMac =
|
|
107
|
+
const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
|
|
112
108
|
// update LT hash
|
|
113
109
|
const generator = makeLtHashGenerator(state);
|
|
114
110
|
generator.mix({ indexMac, valueMac, operation });
|
|
@@ -138,8 +134,7 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
|
|
|
138
134
|
state.indexValueMap[base64Index] = { valueMac };
|
|
139
135
|
return { patch, state };
|
|
140
136
|
};
|
|
141
|
-
|
|
142
|
-
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
137
|
+
export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
143
138
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
144
139
|
// indexKey used to HMAC sign record.index.blob
|
|
145
140
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
@@ -147,7 +142,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
147
142
|
for (const msgMutation of msgMutations) {
|
|
148
143
|
// if it's a syncdmutation, get the operation property
|
|
149
144
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
150
|
-
const operation = 'operation' in msgMutation ? msgMutation.operation :
|
|
145
|
+
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
151
146
|
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
152
147
|
const key = await getKey(record.keyId.id);
|
|
153
148
|
const content = Buffer.from(record.value.blob);
|
|
@@ -156,15 +151,15 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
156
151
|
if (validateMacs) {
|
|
157
152
|
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
158
153
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
159
|
-
throw new
|
|
154
|
+
throw new Boom('HMAC content verification failed');
|
|
160
155
|
}
|
|
161
156
|
}
|
|
162
|
-
const result =
|
|
163
|
-
const syncAction =
|
|
157
|
+
const result = aesDecrypt(encContent, key.valueEncryptionKey);
|
|
158
|
+
const syncAction = proto.SyncActionData.decode(result);
|
|
164
159
|
if (validateMacs) {
|
|
165
|
-
const hmac =
|
|
160
|
+
const hmac = hmacSign(syncAction.index, key.indexKey);
|
|
166
161
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
167
|
-
throw new
|
|
162
|
+
throw new Boom('HMAC index verification failed');
|
|
168
163
|
}
|
|
169
164
|
}
|
|
170
165
|
const indexStr = Buffer.from(syncAction.index).toString();
|
|
@@ -180,7 +175,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
180
175
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
181
176
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
182
177
|
if (!keyEnc) {
|
|
183
|
-
throw new
|
|
178
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
184
179
|
statusCode: 404,
|
|
185
180
|
data: { msgMutations }
|
|
186
181
|
});
|
|
@@ -188,33 +183,31 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
188
183
|
return mutationKeys(keyEnc.keyData);
|
|
189
184
|
}
|
|
190
185
|
};
|
|
191
|
-
|
|
192
|
-
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
186
|
+
export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
193
187
|
if (validateMacs) {
|
|
194
188
|
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
195
189
|
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
196
190
|
if (!mainKeyObj) {
|
|
197
|
-
throw new
|
|
191
|
+
throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
198
192
|
}
|
|
199
193
|
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
200
194
|
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
201
|
-
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs,
|
|
195
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
|
|
202
196
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
203
|
-
throw new
|
|
197
|
+
throw new Boom('Invalid patch mac');
|
|
204
198
|
}
|
|
205
199
|
}
|
|
206
|
-
const result = await
|
|
200
|
+
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
207
201
|
return result;
|
|
208
202
|
};
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
|
|
203
|
+
export const extractSyncdPatches = async (result, options) => {
|
|
204
|
+
const syncNode = getBinaryNodeChild(result, 'sync');
|
|
205
|
+
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection');
|
|
213
206
|
const final = {};
|
|
214
207
|
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
215
|
-
const patchesNode =
|
|
216
|
-
const patches =
|
|
217
|
-
const snapshotNode =
|
|
208
|
+
const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
|
|
209
|
+
const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
|
|
210
|
+
const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
|
|
218
211
|
const syncds = [];
|
|
219
212
|
const name = collectionNode.attrs.name;
|
|
220
213
|
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
|
|
@@ -223,16 +216,16 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
223
216
|
if (!Buffer.isBuffer(snapshotNode)) {
|
|
224
217
|
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
225
218
|
}
|
|
226
|
-
const blobRef =
|
|
227
|
-
const data = await
|
|
228
|
-
snapshot =
|
|
219
|
+
const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
220
|
+
const data = await downloadExternalBlob(blobRef, options);
|
|
221
|
+
snapshot = proto.SyncdSnapshot.decode(data);
|
|
229
222
|
}
|
|
230
223
|
for (let { content } of patches) {
|
|
231
224
|
if (content) {
|
|
232
225
|
if (!Buffer.isBuffer(content)) {
|
|
233
226
|
content = Buffer.from(Object.values(content));
|
|
234
227
|
}
|
|
235
|
-
const syncd =
|
|
228
|
+
const syncd = proto.SyncdPatch.decode(content);
|
|
236
229
|
if (!syncd.version) {
|
|
237
230
|
syncd.version = { version: +collectionNode.attrs.version + 1 };
|
|
238
231
|
}
|
|
@@ -243,31 +236,27 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
243
236
|
}));
|
|
244
237
|
return final;
|
|
245
238
|
};
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
|
|
239
|
+
export const downloadExternalBlob = async (blob, options) => {
|
|
240
|
+
const stream = await downloadContentFromMessage(blob, 'md-app-state', { options });
|
|
249
241
|
const bufferArray = [];
|
|
250
242
|
for await (const chunk of stream) {
|
|
251
243
|
bufferArray.push(chunk);
|
|
252
244
|
}
|
|
253
245
|
return Buffer.concat(bufferArray);
|
|
254
246
|
};
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
|
|
247
|
+
export const downloadExternalPatch = async (blob, options) => {
|
|
248
|
+
const buffer = await downloadExternalBlob(blob, options);
|
|
249
|
+
const syncData = proto.SyncdMutations.decode(buffer);
|
|
259
250
|
return syncData;
|
|
260
251
|
};
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
newState.version = (0, generics_1.toNumber)(snapshot.version.version);
|
|
252
|
+
export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
253
|
+
const newState = newLTHashState();
|
|
254
|
+
newState.version = toNumber(snapshot.version.version);
|
|
265
255
|
const mutationMap = {};
|
|
266
256
|
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
267
|
-
const { hash, indexValueMap } = await
|
|
257
|
+
const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
268
258
|
? mutation => {
|
|
269
|
-
|
|
270
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
259
|
+
const index = mutation.syncAction.index?.toString();
|
|
271
260
|
mutationMap[index] = mutation;
|
|
272
261
|
}
|
|
273
262
|
: () => { }, validateMacs);
|
|
@@ -277,12 +266,12 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
277
266
|
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
278
267
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
279
268
|
if (!keyEnc) {
|
|
280
|
-
throw new
|
|
269
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
281
270
|
}
|
|
282
271
|
const result = await mutationKeys(keyEnc.keyData);
|
|
283
272
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
284
273
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
285
|
-
throw new
|
|
274
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
286
275
|
}
|
|
287
276
|
}
|
|
288
277
|
return {
|
|
@@ -290,9 +279,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
290
279
|
mutationMap
|
|
291
280
|
};
|
|
292
281
|
};
|
|
293
|
-
|
|
294
|
-
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
295
|
-
var _a;
|
|
282
|
+
export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
296
283
|
const newState = {
|
|
297
284
|
...initial,
|
|
298
285
|
indexValueMap: { ...initial.indexValueMap }
|
|
@@ -301,18 +288,17 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
301
288
|
for (const syncd of syncds) {
|
|
302
289
|
const { version, keyId, snapshotMac } = syncd;
|
|
303
290
|
if (syncd.externalMutations) {
|
|
304
|
-
logger
|
|
305
|
-
const ref = await
|
|
306
|
-
logger
|
|
307
|
-
|
|
291
|
+
logger?.trace({ name, version }, 'downloading external patch');
|
|
292
|
+
const ref = await downloadExternalPatch(syncd.externalMutations, options);
|
|
293
|
+
logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
|
|
294
|
+
syncd.mutations?.push(...ref.mutations);
|
|
308
295
|
}
|
|
309
|
-
const patchVersion =
|
|
296
|
+
const patchVersion = toNumber(version.version);
|
|
310
297
|
newState.version = patchVersion;
|
|
311
298
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
312
|
-
const decodeResult = await
|
|
299
|
+
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
313
300
|
? mutation => {
|
|
314
|
-
|
|
315
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
301
|
+
const index = mutation.syncAction.index?.toString();
|
|
316
302
|
mutationMap[index] = mutation;
|
|
317
303
|
}
|
|
318
304
|
: () => { }, true);
|
|
@@ -322,12 +308,12 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
322
308
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
323
309
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
324
310
|
if (!keyEnc) {
|
|
325
|
-
throw new
|
|
311
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
326
312
|
}
|
|
327
313
|
const result = await mutationKeys(keyEnc.keyData);
|
|
328
314
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
329
315
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
330
|
-
throw new
|
|
316
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
331
317
|
}
|
|
332
318
|
}
|
|
333
319
|
// clear memory used up by the mutations
|
|
@@ -335,29 +321,27 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
335
321
|
}
|
|
336
322
|
return { state: newState, mutationMap };
|
|
337
323
|
};
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
|
|
324
|
+
export const chatModificationToAppPatch = (mod, jid) => {
|
|
325
|
+
const OP = proto.SyncdMutation.SyncdOperation;
|
|
341
326
|
const getMessageRange = (lastMessages) => {
|
|
342
327
|
let messageRange;
|
|
343
328
|
if (Array.isArray(lastMessages)) {
|
|
344
329
|
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
345
330
|
messageRange = {
|
|
346
|
-
lastMessageTimestamp: lastMsg
|
|
347
|
-
messages:
|
|
331
|
+
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
332
|
+
messages: lastMessages?.length
|
|
348
333
|
? lastMessages.map(m => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
throw new boom_1.Boom('Incomplete key', { statusCode: 400, data: m });
|
|
334
|
+
if (!m.key?.id || !m.key?.remoteJid) {
|
|
335
|
+
throw new Boom('Incomplete key', { statusCode: 400, data: m });
|
|
352
336
|
}
|
|
353
|
-
if (
|
|
354
|
-
throw new
|
|
337
|
+
if (isJidGroup(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
|
|
338
|
+
throw new Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
|
|
355
339
|
}
|
|
356
|
-
if (!m.messageTimestamp || !
|
|
357
|
-
throw new
|
|
340
|
+
if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
|
|
341
|
+
throw new Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
|
|
358
342
|
}
|
|
359
343
|
if (m.key.participant) {
|
|
360
|
-
m.key.participant =
|
|
344
|
+
m.key.participant = jidNormalizedUser(m.key.participant);
|
|
361
345
|
}
|
|
362
346
|
return m;
|
|
363
347
|
})
|
|
@@ -464,6 +448,17 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
464
448
|
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
465
449
|
};
|
|
466
450
|
}
|
|
451
|
+
else if ('disableLinkPreviews' in mod) {
|
|
452
|
+
patch = {
|
|
453
|
+
syncAction: {
|
|
454
|
+
privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
|
|
455
|
+
},
|
|
456
|
+
index: ['setting_disableLinkPreviews'],
|
|
457
|
+
type: 'regular',
|
|
458
|
+
apiVersion: 8,
|
|
459
|
+
operation: OP.SET
|
|
460
|
+
};
|
|
461
|
+
}
|
|
467
462
|
else if ('star' in mod) {
|
|
468
463
|
const key = mod.star.messages[0];
|
|
469
464
|
patch = {
|
|
@@ -527,7 +522,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
527
522
|
labeled: true
|
|
528
523
|
}
|
|
529
524
|
},
|
|
530
|
-
index: [
|
|
525
|
+
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
531
526
|
type: 'regular',
|
|
532
527
|
apiVersion: 3,
|
|
533
528
|
operation: OP.SET
|
|
@@ -540,7 +535,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
540
535
|
labeled: false
|
|
541
536
|
}
|
|
542
537
|
},
|
|
543
|
-
index: [
|
|
538
|
+
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
544
539
|
type: 'regular',
|
|
545
540
|
apiVersion: 3,
|
|
546
541
|
operation: OP.SET
|
|
@@ -553,7 +548,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
553
548
|
labeled: true
|
|
554
549
|
}
|
|
555
550
|
},
|
|
556
|
-
index: [
|
|
551
|
+
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
557
552
|
type: 'regular',
|
|
558
553
|
apiVersion: 3,
|
|
559
554
|
operation: OP.SET
|
|
@@ -567,7 +562,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
567
562
|
}
|
|
568
563
|
},
|
|
569
564
|
index: [
|
|
570
|
-
|
|
565
|
+
LabelAssociationType.Message,
|
|
571
566
|
mod.removeMessageLabel.labelId,
|
|
572
567
|
jid,
|
|
573
568
|
mod.removeMessageLabel.messageId,
|
|
@@ -580,28 +575,26 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
580
575
|
};
|
|
581
576
|
}
|
|
582
577
|
else {
|
|
583
|
-
throw new
|
|
578
|
+
throw new Boom('not supported');
|
|
584
579
|
}
|
|
585
580
|
patch.syncAction.timestamp = Date.now();
|
|
586
581
|
return patch;
|
|
587
582
|
};
|
|
588
|
-
|
|
589
|
-
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
590
|
-
var _a, _b, _c, _d;
|
|
583
|
+
export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
591
584
|
const isInitialSync = !!initialSyncOpts;
|
|
592
|
-
const accountSettings = initialSyncOpts
|
|
593
|
-
logger
|
|
585
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
586
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
|
|
594
587
|
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
595
|
-
if (action
|
|
588
|
+
if (action?.muteAction) {
|
|
596
589
|
ev.emit('chats.update', [
|
|
597
590
|
{
|
|
598
591
|
id,
|
|
599
|
-
muteEndTime:
|
|
592
|
+
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
600
593
|
conditional: getChatUpdateConditional(id, undefined)
|
|
601
594
|
}
|
|
602
595
|
]);
|
|
603
596
|
}
|
|
604
|
-
else if (
|
|
597
|
+
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
605
598
|
// okay so we've to do some annoying computation here
|
|
606
599
|
// when we're initially syncing the app state
|
|
607
600
|
// there are a few cases we need to handle
|
|
@@ -612,14 +605,14 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
612
605
|
// we compare the timestamp of latest message from the other person to determine this
|
|
613
606
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
614
607
|
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
615
|
-
const archiveAction = action
|
|
608
|
+
const archiveAction = action?.archiveChatAction;
|
|
616
609
|
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
617
610
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
618
611
|
// // this only applies for the initial sync
|
|
619
612
|
// if(isInitialSync && !isArchived) {
|
|
620
613
|
// isArchived = false
|
|
621
614
|
// }
|
|
622
|
-
const msgRange = !
|
|
615
|
+
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
|
|
623
616
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
624
617
|
ev.emit('chats.update', [
|
|
625
618
|
{
|
|
@@ -629,7 +622,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
629
622
|
}
|
|
630
623
|
]);
|
|
631
624
|
}
|
|
632
|
-
else if (action
|
|
625
|
+
else if (action?.markChatAsReadAction) {
|
|
633
626
|
const markReadAction = action.markChatAsReadAction;
|
|
634
627
|
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
635
628
|
// because the chat is read by default
|
|
@@ -638,12 +631,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
638
631
|
ev.emit('chats.update', [
|
|
639
632
|
{
|
|
640
633
|
id,
|
|
641
|
-
unreadCount: isNullUpdate ? null : !!
|
|
642
|
-
conditional: getChatUpdateConditional(id, markReadAction
|
|
634
|
+
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
635
|
+
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
643
636
|
}
|
|
644
637
|
]);
|
|
645
638
|
}
|
|
646
|
-
else if (
|
|
639
|
+
else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
|
|
647
640
|
ev.emit('messages.delete', {
|
|
648
641
|
keys: [
|
|
649
642
|
{
|
|
@@ -654,41 +647,41 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
654
647
|
]
|
|
655
648
|
});
|
|
656
649
|
}
|
|
657
|
-
else if (action
|
|
650
|
+
else if (action?.contactAction) {
|
|
658
651
|
ev.emit('contacts.upsert', [
|
|
659
652
|
{
|
|
660
653
|
id: id,
|
|
661
654
|
name: action.contactAction.fullName,
|
|
662
655
|
lid: action.contactAction.lidJid || undefined,
|
|
663
|
-
jid:
|
|
656
|
+
jid: isJidUser(id) ? id : undefined
|
|
664
657
|
}
|
|
665
658
|
]);
|
|
666
659
|
}
|
|
667
|
-
else if (action
|
|
668
|
-
const name =
|
|
669
|
-
if (name &&
|
|
660
|
+
else if (action?.pushNameSetting) {
|
|
661
|
+
const name = action?.pushNameSetting?.name;
|
|
662
|
+
if (name && me?.name !== name) {
|
|
670
663
|
ev.emit('creds.update', { me: { ...me, name } });
|
|
671
664
|
}
|
|
672
665
|
}
|
|
673
|
-
else if (action
|
|
666
|
+
else if (action?.pinAction) {
|
|
674
667
|
ev.emit('chats.update', [
|
|
675
668
|
{
|
|
676
669
|
id,
|
|
677
|
-
pinned:
|
|
670
|
+
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
678
671
|
conditional: getChatUpdateConditional(id, undefined)
|
|
679
672
|
}
|
|
680
673
|
]);
|
|
681
674
|
}
|
|
682
|
-
else if (action
|
|
675
|
+
else if (action?.unarchiveChatsSetting) {
|
|
683
676
|
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
684
677
|
ev.emit('creds.update', { accountSettings: { unarchiveChats } });
|
|
685
|
-
logger
|
|
678
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
686
679
|
if (accountSettings) {
|
|
687
680
|
accountSettings.unarchiveChats = unarchiveChats;
|
|
688
681
|
}
|
|
689
682
|
}
|
|
690
|
-
else if (
|
|
691
|
-
let starred =
|
|
683
|
+
else if (action?.starAction || type === 'star') {
|
|
684
|
+
let starred = action?.starAction?.starred;
|
|
692
685
|
if (typeof starred !== 'boolean') {
|
|
693
686
|
starred = syncAction.index[syncAction.index.length - 1] === '1';
|
|
694
687
|
}
|
|
@@ -699,32 +692,32 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
699
692
|
}
|
|
700
693
|
]);
|
|
701
694
|
}
|
|
702
|
-
else if (
|
|
695
|
+
else if (action?.deleteChatAction || type === 'deleteChat') {
|
|
703
696
|
if (!isInitialSync) {
|
|
704
697
|
ev.emit('chats.delete', [id]);
|
|
705
698
|
}
|
|
706
699
|
}
|
|
707
|
-
else if (action
|
|
700
|
+
else if (action?.labelEditAction) {
|
|
708
701
|
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
709
702
|
ev.emit('labels.edit', {
|
|
710
|
-
id,
|
|
703
|
+
id: id,
|
|
711
704
|
name: name,
|
|
712
705
|
color: color,
|
|
713
706
|
deleted: deleted,
|
|
714
707
|
predefinedId: predefinedId ? String(predefinedId) : undefined
|
|
715
708
|
});
|
|
716
709
|
}
|
|
717
|
-
else if (action
|
|
710
|
+
else if (action?.labelAssociationAction) {
|
|
718
711
|
ev.emit('labels.association', {
|
|
719
712
|
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
720
|
-
association: type ===
|
|
713
|
+
association: type === LabelAssociationType.Chat
|
|
721
714
|
? {
|
|
722
|
-
type:
|
|
715
|
+
type: LabelAssociationType.Chat,
|
|
723
716
|
chatId: syncAction.index[2],
|
|
724
717
|
labelId: syncAction.index[1]
|
|
725
718
|
}
|
|
726
719
|
: {
|
|
727
|
-
type:
|
|
720
|
+
type: LabelAssociationType.Message,
|
|
728
721
|
chatId: syncAction.index[2],
|
|
729
722
|
messageId: syncAction.index[3],
|
|
730
723
|
labelId: syncAction.index[1]
|
|
@@ -732,7 +725,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
732
725
|
});
|
|
733
726
|
}
|
|
734
727
|
else {
|
|
735
|
-
logger
|
|
728
|
+
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
736
729
|
}
|
|
737
730
|
function getChatUpdateConditional(id, msgRange) {
|
|
738
731
|
return isInitialSync
|
|
@@ -745,9 +738,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
745
738
|
: undefined;
|
|
746
739
|
}
|
|
747
740
|
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
748
|
-
const lastMsgTimestamp = Number(
|
|
749
|
-
const chatLastMsgTimestamp = Number(
|
|
741
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
742
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
750
743
|
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
751
744
|
}
|
|
752
745
|
};
|
|
753
|
-
|
|
746
|
+
//# sourceMappingURL=chat-utils.js.map
|