Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 48 additions & 38 deletions src/Socket/messages-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,52 +510,62 @@

const encryptionPromises = (patchedMessages as any).map(
async ({ recipientJid: jid, message: patchedMessage }: any) => {
if (!jid) return null
let msgToEncrypt = patchedMessage
if (dsmMessage) {
const { user: targetUser } = jidDecode(jid)!
const { user: ownPnUser } = jidDecode(meId)!
const ownLidUser = meLidUser
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser)
const isExactSenderDevice = jid === meId || (meLid && jid === meLid)
if (isOwnUser && !isExactSenderDevice) {
msgToEncrypt = dsmMessage
logger.debug({ jid, targetUser }, 'Using DSM for own device')
try {
if (!jid) return null

let msgToEncrypt = patchedMessage

if (dsmMessage) {
const { user: targetUser } = jidDecode(jid)!
const { user: ownPnUser } = jidDecode(meId)!
const ownLidUser = meLidUser

const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser)
const isExactSenderDevice = jid === meId || (meLid && jid === meLid)

if (isOwnUser && !isExactSenderDevice) {
msgToEncrypt = dsmMessage
logger.debug({ jid, targetUser }, 'Using DSM for own device')
}
}
}

const bytes = encodeWAMessage(msgToEncrypt)
const mutexKey = jid
const node = await encryptionMutex.mutex(mutexKey, async () => {
const { type, ciphertext } = await signalRepository.encryptMessage({
jid,
data: bytes
const bytes = encodeWAMessage(msgToEncrypt)
const mutexKey = jid

const node = await encryptionMutex.mutex(mutexKey, async () => {
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes })

if (type === 'pkmsg') {
shouldIncludeDeviceIdentity = true
}

Check warning on line 541 in src/Socket/messages-send.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
return {

Check warning on line 542 in src/Socket/messages-send.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
tag: 'to',
attrs: { jid },
content: [
{
tag: 'enc',
attrs: { v: '2', type, ...(extraAttrs || {}) },
content: ciphertext
}
]
}
})
if (type === 'pkmsg') {
shouldIncludeDeviceIdentity = true
}

return {
tag: 'to',
attrs: { jid },
content: [
{
tag: 'enc',
attrs: {
v: '2',
type,
...(extraAttrs || {})
},
content: ciphertext
}
]
}
})
return node
return node
} catch (err) {
logger.error({ jid, err }, 'Failed to encrypt for recipient')
return null
}
}
)

const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null) as BinaryNode[]

if (recipientJids.length > 0 && nodes.length === 0) {
throw new Boom('All encryptions failed', { statusCode: 500 })
}

return { nodes, shouldIncludeDeviceIdentity }
}

Expand Down Expand Up @@ -1129,7 +1139,7 @@
typeof disappearingMessagesInChat === 'boolean'
? disappearingMessagesInChat
? WA_DEFAULT_EPHEMERAL
: 0

Check warning on line 1142 in src/Socket/messages-send.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
: disappearingMessagesInChat
await groupToggleEphemeral(jid, value)
} else {
Expand Down
Loading