@hansaka02/baileys 7.3.2 → 7.3.6
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/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +74 -0
- package/lib/Defaults/history.js +19 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +5 -18
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.js +15 -61
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +237 -177
- package/lib/Signal/lid-mapping.js +128 -71
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +25 -16
- package/lib/Socket/business.js +46 -33
- package/lib/Socket/chats.js +286 -170
- package/lib/Socket/community.js +215 -77
- package/lib/Socket/groups.js +77 -61
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +629 -457
- package/lib/Socket/messages-send.js +645 -656
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +166 -245
- package/lib/Socket/socket.js +396 -170
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/Newsletter.js +32 -25
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +212 -375
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +241 -106
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +361 -311
- package/lib/Utils/event-buffer.js +97 -42
- package/lib/Utils/generics.js +90 -207
- package/lib/Utils/history.js +29 -27
- package/lib/Utils/index.js +28 -14
- package/lib/Utils/link-preview.js +24 -62
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +29 -23
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +55 -7
- package/lib/Utils/messages-media.js +434 -247
- package/lib/Utils/messages.js +963 -917
- package/lib/Utils/noise-handler.js +60 -20
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +216 -141
- package/lib/Utils/signal.js +75 -37
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +96 -66
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +62 -34
- package/lib/WABinary/encode.js +57 -36
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +71 -14
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +51 -28
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +12 -17
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- 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 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- 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 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
|
@@ -2,38 +2,72 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const { proto } = require("../../WAProto")
|
|
6
|
+
const { WAMessageStubType } = require("../Types")
|
|
7
|
+
const {
|
|
8
|
+
getDevice,
|
|
9
|
+
getContentType,
|
|
10
|
+
normalizeMessageContent
|
|
11
|
+
} = require("../Utils")
|
|
12
|
+
const {
|
|
13
|
+
areJidsSameUser,
|
|
14
|
+
isHostedLidUser,
|
|
15
|
+
isHostedPnUser,
|
|
16
|
+
isJidBroadcast,
|
|
17
|
+
isJidStatusBroadcast,
|
|
18
|
+
isLidUser,
|
|
19
|
+
jidDecode,
|
|
20
|
+
jidEncode,
|
|
21
|
+
jidNormalizedUser
|
|
22
|
+
} = require("../WABinary")
|
|
23
|
+
const {
|
|
24
|
+
aesDecryptGCM,
|
|
25
|
+
hmacSign
|
|
26
|
+
} = require("./crypto")
|
|
27
|
+
const {
|
|
28
|
+
getKeyAuthor,
|
|
29
|
+
toNumber
|
|
30
|
+
} = require("./generics")
|
|
31
|
+
const { downloadAndProcessHistorySyncNotification } = require("./history")
|
|
12
32
|
|
|
13
33
|
const REAL_MSG_STUB_TYPES = new Set([
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
|
|
35
|
+
WAMessageStubType.CALL_MISSED_GROUP_VOICE,
|
|
36
|
+
WAMessageStubType.CALL_MISSED_VIDEO,
|
|
37
|
+
WAMessageStubType.CALL_MISSED_VOICE
|
|
18
38
|
])
|
|
19
39
|
|
|
20
40
|
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
|
|
21
|
-
|
|
41
|
+
WAMessageStubType.GROUP_PARTICIPANT_ADD
|
|
22
42
|
])
|
|
23
43
|
|
|
24
44
|
/** Cleans a received message to further processing */
|
|
25
|
-
const cleanMessage = (message, meId) => {
|
|
45
|
+
const cleanMessage = (message, meId, meLid) => {
|
|
26
46
|
// ensure remoteJid and participant doesn't have device or agent in it
|
|
27
|
-
message.key.remoteJid
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
|
|
48
|
+
message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid')
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
|
|
55
|
+
message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid')
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
message.key.participant = jidNormalizedUser(message.key.participant)
|
|
59
|
+
}
|
|
60
|
+
const content = normalizeMessageContent(message.message)
|
|
61
|
+
|
|
30
62
|
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
|
31
63
|
if (content?.reactionMessage) {
|
|
32
64
|
normaliseKey(content.reactionMessage.key)
|
|
33
65
|
}
|
|
66
|
+
|
|
34
67
|
if (content?.pollUpdateMessage) {
|
|
35
68
|
normaliseKey(content.pollUpdateMessage.pollCreationMessageKey)
|
|
36
69
|
}
|
|
70
|
+
|
|
37
71
|
function normaliseKey(msgKey) {
|
|
38
72
|
// if the reaction is from another user
|
|
39
73
|
// we've to correctly map the key to this user's perspective
|
|
@@ -41,11 +75,13 @@ const cleanMessage = (message, meId) => {
|
|
|
41
75
|
// if the sender believed the message being reacted to is not from them
|
|
42
76
|
// we've to correct the key to be from them, or some other participant
|
|
43
77
|
msgKey.fromMe = !msgKey.fromMe
|
|
44
|
-
?
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
|
|
78
|
+
? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
|
|
79
|
+
areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
|
|
80
|
+
: // if the message being reacted to, was from them
|
|
81
|
+
// fromMe automatically becomes false
|
|
82
|
+
false
|
|
48
83
|
// set the remoteJid to being the same as the chat the message came from
|
|
84
|
+
// TODO: investigate inconsistencies
|
|
49
85
|
msgKey.remoteJid = message.key.remoteJid
|
|
50
86
|
// set participant of the message
|
|
51
87
|
msgKey.participant = msgKey.participant || message.key.participant
|
|
@@ -53,32 +89,28 @@ const cleanMessage = (message, meId) => {
|
|
|
53
89
|
}
|
|
54
90
|
}
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
92
|
+
// TODO: target:audit AUDIT THIS FUNCTION AGAIN
|
|
93
|
+
const isRealMessage = (message) => {
|
|
94
|
+
const normalizedContent = normalizeMessageContent(message.message)
|
|
95
|
+
const hasSomeContent = !!getContentType(normalizedContent)
|
|
96
|
+
return ((!!normalizedContent ||
|
|
61
97
|
REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
|
|
62
|
-
(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
hasSomeContent &&
|
|
68
|
-
!normalizedContent?.protocolMessage &&
|
|
69
|
-
!normalizedContent?.reactionMessage &&
|
|
70
|
-
!normalizedContent?.pollUpdateMessage
|
|
98
|
+
REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
|
|
99
|
+
hasSomeContent &&
|
|
100
|
+
!normalizedContent?.protocolMessage &&
|
|
101
|
+
!normalizedContent?.reactionMessage &&
|
|
102
|
+
!normalizedContent?.pollUpdateMessage)
|
|
71
103
|
}
|
|
72
104
|
|
|
73
|
-
const shouldIncrementChatUnread = (message) =>
|
|
105
|
+
const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType
|
|
74
106
|
|
|
75
107
|
/**
|
|
76
108
|
* Get the ID of the chat from the given key.
|
|
77
109
|
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
78
110
|
*/
|
|
79
111
|
const getChatId = ({ remoteJid, participant, fromMe }) => {
|
|
80
|
-
if (
|
|
81
|
-
&& !
|
|
112
|
+
if (isJidBroadcast(remoteJid)
|
|
113
|
+
&& !isJidStatusBroadcast(remoteJid)
|
|
82
114
|
&& !fromMe) {
|
|
83
115
|
return participant
|
|
84
116
|
}
|
|
@@ -99,12 +131,12 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
99
131
|
toBinary('Poll Vote'),
|
|
100
132
|
new Uint8Array([1])
|
|
101
133
|
])
|
|
102
|
-
const key0 =
|
|
103
|
-
const decKey =
|
|
134
|
+
const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256')
|
|
135
|
+
const decKey = hmacSign(sign, key0, 'sha256')
|
|
104
136
|
const aad = toBinary(`${pollMsgId}\u0000${voterJid}`)
|
|
105
|
-
const decrypted =
|
|
137
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad)
|
|
106
138
|
|
|
107
|
-
return
|
|
139
|
+
return proto.Message.PollVoteMessage.decode(decrypted)
|
|
108
140
|
|
|
109
141
|
function toBinary(txt) {
|
|
110
142
|
return Buffer.from(txt)
|
|
@@ -125,11 +157,11 @@ function decryptEventEdit({ encPayload, encIv }, { eventCreatorJid, eventMsgId,
|
|
|
125
157
|
new Uint8Array([1])
|
|
126
158
|
])
|
|
127
159
|
|
|
128
|
-
const key0 =
|
|
129
|
-
const decKey =
|
|
130
|
-
const decrypted =
|
|
160
|
+
const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256')
|
|
161
|
+
const decKey = hmacSign(sign, key0, 'sha256')
|
|
162
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, null)
|
|
131
163
|
|
|
132
|
-
return
|
|
164
|
+
return proto.Message.decode(decrypted)
|
|
133
165
|
|
|
134
166
|
function toBinary(txt) {
|
|
135
167
|
return Buffer.from(txt)
|
|
@@ -151,12 +183,12 @@ function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsg
|
|
|
151
183
|
new Uint8Array([1])
|
|
152
184
|
])
|
|
153
185
|
|
|
154
|
-
const key0 =
|
|
155
|
-
const decKey =
|
|
186
|
+
const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256')
|
|
187
|
+
const decKey = hmacSign(sign, key0, 'sha256')
|
|
156
188
|
const aad = toBinary(`${eventMsgId}\u0000${responderJid}`)
|
|
157
|
-
const decrypted =
|
|
189
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad)
|
|
158
190
|
|
|
159
|
-
return
|
|
191
|
+
return proto.Message.EventResponseMessage.decode(decrypted)
|
|
160
192
|
|
|
161
193
|
function toBinary(txt) {
|
|
162
194
|
return Buffer.from(txt)
|
|
@@ -177,11 +209,11 @@ function decryptComment({ encPayload, encIv }, { commentCreatorJid, commentMsgId
|
|
|
177
209
|
new Uint8Array([1])
|
|
178
210
|
])
|
|
179
211
|
|
|
180
|
-
const key0 =
|
|
181
|
-
const decKey =
|
|
182
|
-
const decrypted =
|
|
212
|
+
const key0 = hmacSign(commentEncKey, new Uint8Array(32), 'sha256')
|
|
213
|
+
const decKey = hmacSign(sign, key0, 'sha256')
|
|
214
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, null)
|
|
183
215
|
|
|
184
|
-
return
|
|
216
|
+
return proto.Message.decode(decrypted)
|
|
185
217
|
|
|
186
218
|
function toBinary(txt) {
|
|
187
219
|
return Buffer.from(txt)
|
|
@@ -202,11 +234,11 @@ function decryptReaction({ encPayload, encIv }, { reactionCreatorJid, reactionMs
|
|
|
202
234
|
new Uint8Array([1])
|
|
203
235
|
])
|
|
204
236
|
|
|
205
|
-
const key0 =
|
|
206
|
-
const decKey =
|
|
207
|
-
const decrypted =
|
|
237
|
+
const key0 = hmacSign(reactionEncKey, new Uint8Array(32), 'sha256')
|
|
238
|
+
const decKey = hmacSign(sign, key0, 'sha256')
|
|
239
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, null)
|
|
208
240
|
|
|
209
|
-
return
|
|
241
|
+
return proto.Message.ReactionMessage.decode(decrypted)
|
|
210
242
|
|
|
211
243
|
function toBinary(txt) {
|
|
212
244
|
return Buffer.from(txt)
|
|
@@ -217,17 +249,17 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
217
249
|
const meId = creds.me.id
|
|
218
250
|
const meLid = creds.me.lid
|
|
219
251
|
const { accountSettings } = creds
|
|
220
|
-
const chat = { id:
|
|
221
|
-
const isRealMsg = isRealMessage(message
|
|
252
|
+
const chat = { id: jidNormalizedUser(getChatId(message.key)) }
|
|
253
|
+
const isRealMsg = isRealMessage(message)
|
|
222
254
|
if (isRealMsg) {
|
|
223
255
|
chat.messages = [{ message }]
|
|
224
|
-
chat.conversationTimestamp =
|
|
256
|
+
chat.conversationTimestamp = toNumber(message.messageTimestamp)
|
|
225
257
|
// only increment unread count if not CIPHERTEXT and from another person
|
|
226
258
|
if (shouldIncrementChatUnread(message)) {
|
|
227
259
|
chat.unreadCount = (chat.unreadCount || 0) + 1
|
|
228
260
|
}
|
|
229
261
|
}
|
|
230
|
-
const content =
|
|
262
|
+
const content = normalizeMessageContent(message.message)
|
|
231
263
|
// unarchive chat if it's a real message, or someone reacted to our message
|
|
232
264
|
// and we've the unarchive chats setting on
|
|
233
265
|
if (isRealMsg || content?.reactionMessage?.key?.fromMe
|
|
@@ -238,18 +270,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
238
270
|
const protocolMsg = content?.protocolMessage
|
|
239
271
|
if (protocolMsg) {
|
|
240
272
|
switch (protocolMsg.type) {
|
|
241
|
-
case
|
|
273
|
+
case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
|
|
242
274
|
const histNotification = protocolMsg.historySyncNotification
|
|
243
275
|
const process = shouldProcessHistoryMsg
|
|
244
276
|
const isLatest = !creds.processedHistoryMessages?.length
|
|
277
|
+
|
|
245
278
|
logger?.info({
|
|
246
279
|
histNotification,
|
|
247
280
|
process,
|
|
248
281
|
id: message.key.id,
|
|
249
|
-
isLatest
|
|
282
|
+
isLatest
|
|
250
283
|
}, 'got history notification')
|
|
284
|
+
|
|
251
285
|
if (process) {
|
|
252
|
-
|
|
286
|
+
// TODO: investigate
|
|
287
|
+
if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
253
288
|
ev.emit('creds.update', {
|
|
254
289
|
processedHistoryMessages: [
|
|
255
290
|
...(creds.processedHistoryMessages || []),
|
|
@@ -257,65 +292,77 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
257
292
|
]
|
|
258
293
|
})
|
|
259
294
|
}
|
|
260
|
-
|
|
295
|
+
|
|
296
|
+
const data = await downloadAndProcessHistorySyncNotification(histNotification, options)
|
|
261
297
|
ev.emit('messaging-history.set', {
|
|
262
298
|
...data,
|
|
263
|
-
isLatest: histNotification.syncType !==
|
|
264
|
-
? isLatest
|
|
265
|
-
: undefined,
|
|
299
|
+
isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
|
|
266
300
|
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
267
301
|
})
|
|
268
302
|
}
|
|
269
303
|
break
|
|
270
|
-
case
|
|
304
|
+
case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
271
305
|
const keys = protocolMsg.appStateSyncKeyShare.keys
|
|
306
|
+
|
|
272
307
|
if (keys?.length) {
|
|
273
308
|
let newAppStateSyncKeyId = ''
|
|
309
|
+
|
|
274
310
|
await keyStore.transaction(async () => {
|
|
275
311
|
const newKeys = []
|
|
312
|
+
|
|
276
313
|
for (const { keyData, keyId } of keys) {
|
|
277
314
|
const strKeyId = Buffer.from(keyId.keyId).toString('base64')
|
|
315
|
+
|
|
278
316
|
newKeys.push(strKeyId)
|
|
317
|
+
|
|
279
318
|
await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
|
|
319
|
+
|
|
280
320
|
newAppStateSyncKeyId = strKeyId
|
|
281
321
|
}
|
|
322
|
+
|
|
282
323
|
logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys')
|
|
283
324
|
}, meId)
|
|
284
325
|
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId })
|
|
285
326
|
}
|
|
327
|
+
|
|
286
328
|
else {
|
|
287
329
|
logger?.info({ protocolMsg }, 'recv app state sync with 0 keys')
|
|
288
330
|
}
|
|
289
331
|
break
|
|
290
|
-
case
|
|
332
|
+
case proto.Message.ProtocolMessage.Type.REVOKE:
|
|
291
333
|
ev.emit('messages.update', [
|
|
292
334
|
{
|
|
293
335
|
key: {
|
|
294
336
|
...message.key,
|
|
295
337
|
id: protocolMsg.key.id
|
|
296
338
|
},
|
|
297
|
-
update: { message: null, messageStubType:
|
|
339
|
+
update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
|
|
298
340
|
}
|
|
299
341
|
])
|
|
300
342
|
break
|
|
301
|
-
case
|
|
343
|
+
case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
|
|
302
344
|
Object.assign(chat, {
|
|
303
|
-
ephemeralSettingTimestamp:
|
|
345
|
+
ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
|
|
304
346
|
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
|
|
305
347
|
})
|
|
306
348
|
break
|
|
307
|
-
case
|
|
349
|
+
case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
308
350
|
const response = protocolMsg.peerDataOperationRequestResponseMessage
|
|
351
|
+
|
|
309
352
|
if (response) {
|
|
310
|
-
await
|
|
353
|
+
await placeholderResendCache?.del(response.stanzaId)
|
|
354
|
+
|
|
311
355
|
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
312
356
|
const { peerDataOperationResult } = response
|
|
357
|
+
|
|
313
358
|
for (const result of peerDataOperationResult) {
|
|
314
359
|
const { placeholderMessageResendResponse: retryResponse } = result
|
|
360
|
+
|
|
315
361
|
//eslint-disable-next-line max-depth
|
|
316
362
|
if (retryResponse) {
|
|
317
|
-
const webMessageInfo =
|
|
363
|
+
const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes)
|
|
318
364
|
// wait till another upsert event is available, don't want it to be part of the PDO response message
|
|
365
|
+
// TODO: parse through proper message handling utilities (to add relevant key fields)
|
|
319
366
|
setTimeout(() => {
|
|
320
367
|
ev.emit('messages.upsert', {
|
|
321
368
|
messages: [webMessageInfo],
|
|
@@ -327,7 +374,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
327
374
|
}
|
|
328
375
|
}
|
|
329
376
|
break
|
|
330
|
-
case
|
|
377
|
+
case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
331
378
|
ev.emit('messages.update', [
|
|
332
379
|
{
|
|
333
380
|
// flip the sender / fromMe properties because they're in the perspective of the sender
|
|
@@ -339,15 +386,29 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
339
386
|
}
|
|
340
387
|
},
|
|
341
388
|
messageTimestamp: protocolMsg.timestampMs
|
|
342
|
-
? Math.floor(
|
|
389
|
+
? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
|
|
343
390
|
: message.messageTimestamp
|
|
344
391
|
}
|
|
345
392
|
}
|
|
346
393
|
])
|
|
347
394
|
break
|
|
348
|
-
case
|
|
395
|
+
case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
|
|
396
|
+
const labelAssociationMsg = protocolMsg.memberLabel
|
|
397
|
+
|
|
398
|
+
if (labelAssociationMsg?.label) {
|
|
399
|
+
ev.emit('group.member-tag.update', {
|
|
400
|
+
groupId: chat.id,
|
|
401
|
+
label: labelAssociationMsg.label,
|
|
402
|
+
participant: message.key.participant,
|
|
403
|
+
participantAlt: message.key.participantAlt,
|
|
404
|
+
messageTimestamp: Number(message.messageTimestamp)
|
|
405
|
+
})
|
|
406
|
+
}
|
|
407
|
+
break
|
|
408
|
+
case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
|
|
349
409
|
const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload
|
|
350
|
-
|
|
410
|
+
|
|
411
|
+
const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload)
|
|
351
412
|
|
|
352
413
|
logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp')
|
|
353
414
|
|
|
@@ -359,11 +420,17 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
359
420
|
}
|
|
360
421
|
|
|
361
422
|
await signalRepository.lidMapping.storeLIDPNMappings(pairs)
|
|
423
|
+
|
|
424
|
+
if (pairs.length) {
|
|
425
|
+
for (const { pn, lid } of pairs) {
|
|
426
|
+
await signalRepository.migrateSession(pn, lid)
|
|
427
|
+
}
|
|
428
|
+
}
|
|
362
429
|
break
|
|
363
|
-
case
|
|
430
|
+
case proto.Message.ProtocolMessage.Type.LIMIT_SHARING:
|
|
364
431
|
ev.emit('limit-sharing.update', {
|
|
365
432
|
id: message.key.remoteJid,
|
|
366
|
-
author:
|
|
433
|
+
author: areJidsSameUser(message.key.remoteJid, protocolMsg.key.remoteJid) ? jidNormalizedUser(meId) : message.key.remoteJid,
|
|
367
434
|
action: `${protocolMsg.limitSharing.sharingLimited ? 'on' : 'off'}`,
|
|
368
435
|
trigger: protocolMsg.limitSharing.trigger,
|
|
369
436
|
update_time: protocolMsg.limitSharing.limitSharingSettingTimestamp
|
|
@@ -383,94 +450,102 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
383
450
|
}
|
|
384
451
|
else if (message.messageStubType) {
|
|
385
452
|
const jid = message.key?.remoteJid
|
|
386
|
-
|
|
453
|
+
|
|
387
454
|
let participants
|
|
388
|
-
|
|
455
|
+
|
|
456
|
+
const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
|
|
457
|
+
id: jid,
|
|
458
|
+
author: message.key.participant,
|
|
459
|
+
authorPn: message.key.participantAlt,
|
|
460
|
+
participants,
|
|
461
|
+
action
|
|
462
|
+
})
|
|
463
|
+
|
|
389
464
|
const emitGroupUpdate = (update) => {
|
|
390
|
-
ev.emit('groups.update', [
|
|
465
|
+
ev.emit('groups.update', [
|
|
466
|
+
{ id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
|
|
467
|
+
])
|
|
391
468
|
}
|
|
469
|
+
|
|
392
470
|
const emitGroupRequestJoin = (participant, action, method) => {
|
|
393
|
-
ev.emit('group.join-request', {
|
|
471
|
+
ev.emit('group.join-request', {
|
|
472
|
+
id: jid,
|
|
473
|
+
author: message.key.participant,
|
|
474
|
+
authorPn: message.key.participantAlt,
|
|
475
|
+
participant: participant.lid,
|
|
476
|
+
participantPn: participant.pn,
|
|
477
|
+
action,
|
|
478
|
+
method: method
|
|
479
|
+
})
|
|
394
480
|
}
|
|
395
|
-
|
|
481
|
+
|
|
482
|
+
const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)) // ADD SUPPORT FOR LID
|
|
396
483
|
switch (message.messageStubType) {
|
|
397
|
-
case
|
|
398
|
-
participants = message.messageStubParameters || []
|
|
484
|
+
case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
485
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
|
|
399
486
|
emitParticipantsUpdate('modify')
|
|
400
487
|
break
|
|
401
|
-
case
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
// mark the chat read only if you left the group
|
|
405
|
-
if (participantsIncludesMe()) {
|
|
406
|
-
chat.readOnly = true;
|
|
407
|
-
}
|
|
408
|
-
break;
|
|
409
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
410
|
-
participants = message.messageStubParameters || []
|
|
488
|
+
case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
489
|
+
case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
490
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
|
|
411
491
|
emitParticipantsUpdate('remove')
|
|
492
|
+
|
|
412
493
|
// mark the chat read only if you left the group
|
|
413
494
|
if (participantsIncludesMe()) {
|
|
414
495
|
chat.readOnly = true
|
|
415
496
|
}
|
|
416
497
|
break
|
|
417
|
-
case
|
|
418
|
-
case
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (message?.key?.participant && !participants.includes(message?.key?.participant)) {
|
|
423
|
-
actionGp = 'approval-invite'
|
|
424
|
-
}
|
|
425
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
|
|
426
|
-
participants = message.messageStubParameters || []
|
|
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
|
+
|
|
427
503
|
if (participantsIncludesMe()) {
|
|
428
504
|
chat.readOnly = false
|
|
429
505
|
}
|
|
506
|
+
|
|
430
507
|
emitParticipantsUpdate('add')
|
|
431
508
|
break
|
|
432
|
-
case
|
|
433
|
-
|
|
434
|
-
participants = message.messageStubParameters || []
|
|
509
|
+
case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
|
|
510
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
|
|
435
511
|
emitParticipantsUpdate('demote')
|
|
436
512
|
break
|
|
437
|
-
case
|
|
438
|
-
|
|
439
|
-
participants = message.messageStubParameters || []
|
|
513
|
+
case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
|
|
514
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
|
|
440
515
|
emitParticipantsUpdate('promote')
|
|
441
516
|
break
|
|
442
|
-
case
|
|
517
|
+
case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
443
518
|
const announceValue = message.messageStubParameters?.[0]
|
|
444
519
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' })
|
|
445
520
|
break
|
|
446
|
-
case
|
|
521
|
+
case WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
447
522
|
const restrictValue = message.messageStubParameters?.[0]
|
|
448
523
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' })
|
|
449
524
|
break
|
|
450
|
-
case
|
|
525
|
+
case WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
451
526
|
const name = message.messageStubParameters?.[0]
|
|
452
527
|
chat.name = name
|
|
453
528
|
emitGroupUpdate({ subject: name })
|
|
454
529
|
break
|
|
455
|
-
case
|
|
530
|
+
case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
456
531
|
const description = message.messageStubParameters?.[0]
|
|
457
532
|
chat.description = description
|
|
458
533
|
emitGroupUpdate({ desc: description })
|
|
459
534
|
break
|
|
460
|
-
case
|
|
535
|
+
case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
461
536
|
const code = message.messageStubParameters?.[0]
|
|
462
537
|
emitGroupUpdate({ inviteCode: code })
|
|
463
538
|
break
|
|
464
|
-
case
|
|
539
|
+
case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
465
540
|
const memberAddValue = message.messageStubParameters?.[0]
|
|
466
541
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' })
|
|
467
542
|
break
|
|
468
|
-
case
|
|
543
|
+
case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
469
544
|
const approvalMode = message.messageStubParameters?.[0]
|
|
470
545
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' })
|
|
471
546
|
break
|
|
472
|
-
case
|
|
473
|
-
const participant = message.messageStubParameters?.[0]
|
|
547
|
+
case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
|
|
548
|
+
const participant = JSON.parse(message.messageStubParameters?.[0])
|
|
474
549
|
const action = message.messageStubParameters?.[1]
|
|
475
550
|
const method = message.messageStubParameters?.[2]
|
|
476
551
|
emitGroupRequestJoin(participant, action, method)
|
|
@@ -485,13 +560,13 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
485
560
|
const pollMsg = await getMessage(creationMsgKey)
|
|
486
561
|
if (pollMsg) {
|
|
487
562
|
try {
|
|
488
|
-
const meLidNormalised =
|
|
489
|
-
const
|
|
490
|
-
const pollCreationFromMe =
|
|
563
|
+
const meLidNormalised = jidNormalizedUser(meLid)
|
|
564
|
+
const deviceType = getDevice(creationMsgKey.id)
|
|
565
|
+
const pollCreationFromMe = deviceType === 'baileys' ? true : false
|
|
491
566
|
const pollEncKey = pollMsg.messageContextInfo?.messageSecret
|
|
492
|
-
const voterJid =
|
|
567
|
+
const voterJid = getKeyAuthor(message.key, meLidNormalised)
|
|
493
568
|
|
|
494
|
-
let pollCreatorJid =
|
|
569
|
+
let pollCreatorJid = getKeyAuthor(creationMsgKey, meLidNormalised)
|
|
495
570
|
|
|
496
571
|
if (pollCreationFromMe) {
|
|
497
572
|
pollCreatorJid = meLidNormalised
|
|
@@ -535,15 +610,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
535
610
|
const encEventEdit = content.secretEncryptedMessage
|
|
536
611
|
const creationMsgKey = encEventEdit.targetMessageKey
|
|
537
612
|
|
|
538
|
-
if (
|
|
613
|
+
if (proto.Message.SecretEncryptedMessage.SecretEncType[encEventEdit.secretEncType] !== 'EVENT_EDIT') return
|
|
539
614
|
|
|
540
615
|
// we need to fetch the event creation message to get the event enc key
|
|
541
616
|
const eventMsg = await getMessage(creationMsgKey)
|
|
542
617
|
if (eventMsg) {
|
|
543
618
|
try {
|
|
544
|
-
const meLidNormalised =
|
|
545
|
-
const eventCreatorJid =
|
|
546
|
-
const responderJid =
|
|
619
|
+
const meLidNormalised = jidNormalizedUser(meLid)
|
|
620
|
+
const eventCreatorJid = getKeyAuthor(message.key, meLidNormalised)
|
|
621
|
+
const responderJid = getKeyAuthor(message.key, meLidNormalised)
|
|
547
622
|
const eventEncKey = eventMsg.messageContextInfo?.messageSecret
|
|
548
623
|
|
|
549
624
|
if (!eventEncKey) {
|
|
@@ -555,7 +630,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
555
630
|
eventMsgId: creationMsgKey.id,
|
|
556
631
|
responderJid
|
|
557
632
|
})
|
|
558
|
-
const content =
|
|
633
|
+
const content = normalizeMessageContent(responseMsg)
|
|
559
634
|
const protocolMsg = content?.protocolMessage
|
|
560
635
|
|
|
561
636
|
ev.emit('messages.update', [
|
|
@@ -569,7 +644,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
569
644
|
}
|
|
570
645
|
},
|
|
571
646
|
messageTimestamp: protocolMsg.timestampMs
|
|
572
|
-
? Math.floor(
|
|
647
|
+
? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
|
|
573
648
|
: message.messageTimestamp
|
|
574
649
|
}
|
|
575
650
|
}
|
|
@@ -592,9 +667,9 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
592
667
|
const eventMsg = await getMessage(creationMsgKey)
|
|
593
668
|
if (eventMsg) {
|
|
594
669
|
try {
|
|
595
|
-
const meLidNormalised =
|
|
596
|
-
const eventCreatorJid =
|
|
597
|
-
const responderJid =
|
|
670
|
+
const meLidNormalised = jidNormalizedUser(meLid)
|
|
671
|
+
const eventCreatorJid = getKeyAuthor(creationMsgKey, meLidNormalised)
|
|
672
|
+
const responderJid = getKeyAuthor(message.key, meLidNormalised)
|
|
598
673
|
const eventEncKey = eventMsg.messageContextInfo?.messageSecret
|
|
599
674
|
|
|
600
675
|
if (!eventEncKey) {
|
|
@@ -635,11 +710,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
635
710
|
const encComment = content.encCommentMessage
|
|
636
711
|
const creationMsgKey = encComment.targetMessageKey
|
|
637
712
|
|
|
638
|
-
// we need to fetch the message to get the
|
|
713
|
+
// we need to fetch the message to get the comment enc key
|
|
639
714
|
const commentMsg = await getMessage(creationMsgKey)
|
|
640
715
|
if (commentMsg) {
|
|
641
716
|
try {
|
|
642
|
-
const meLidNormalised =
|
|
717
|
+
const meLidNormalised = jidNormalizedUser(meLid)
|
|
643
718
|
const commentCreatorJid = creationMsgKey.participant ? creationMsgKey.participant : message.key?.participant ? message.key.participant : meLidNormalised
|
|
644
719
|
const commentJid = message.key?.participant ? message.key.participant : creationMsgKey.participant ? creationMsgKey.participant : meLidNormalised
|
|
645
720
|
const commentEncKey = commentMsg.messageContextInfo?.messageSecret
|
|
@@ -679,7 +754,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
679
754
|
const reactMsg = await getMessage(creationMsgKey)
|
|
680
755
|
if (reactMsg) {
|
|
681
756
|
try {
|
|
682
|
-
const meLidNormalised =
|
|
757
|
+
const meLidNormalised = jidNormalizedUser(meLid)
|
|
683
758
|
const reactionCreatorJid = creationMsgKey.participant ? creationMsgKey.participant : message.key?.participant ? message.key.participant : meLidNormalised
|
|
684
759
|
const reactionJid = message.key?.participant ? message.key.participant : creationMsgKey.participant ? creationMsgKey.participant : meLidNormalised
|
|
685
760
|
const reactionEncKey = reactMsg.messageContextInfo?.messageSecret
|