fix: flatten DSM helper to satisfy lint
This commit is contained in:
+25
-20
@@ -617,6 +617,30 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
return msgId
|
return msgId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolveDsmMessageForRecipient = (
|
||||||
|
jid: string,
|
||||||
|
patchedMessage: proto.IMessage,
|
||||||
|
dsmMessage: proto.IMessage | undefined,
|
||||||
|
meId: string,
|
||||||
|
meLid: string | undefined,
|
||||||
|
meLidUser: string | null
|
||||||
|
) => {
|
||||||
|
if (!dsmMessage) {
|
||||||
|
return patchedMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
const { user: targetUser } = jidDecode(jid)!
|
||||||
|
const { user: ownPnUser } = jidDecode(meId)!
|
||||||
|
const isOwnUser = targetUser === ownPnUser || (meLidUser && targetUser === meLidUser)
|
||||||
|
const isExactSenderDevice = jid === meId || (meLid && jid === meLid)
|
||||||
|
|
||||||
|
if (isOwnUser && !isExactSenderDevice) {
|
||||||
|
logger.debug({ jid, targetUser }, 'Using DSM for own device')
|
||||||
|
return dsmMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
return patchedMessage
|
||||||
|
}
|
||||||
const createParticipantNodes = async (
|
const createParticipantNodes = async (
|
||||||
recipientJids: string[],
|
recipientJids: string[],
|
||||||
message: proto.IMessage,
|
message: proto.IMessage,
|
||||||
@@ -657,32 +681,13 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveMessageForRecipient = (jid: string, patchedMessage: proto.IMessage) => {
|
|
||||||
if (!dsmMessage) {
|
|
||||||
return patchedMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
logger.debug({ jid, targetUser }, 'Using DSM for own device')
|
|
||||||
return dsmMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
return patchedMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
const encryptionPromises = (patchedMessages as { recipientJid: string; message: proto.IMessage }[]).map(
|
const encryptionPromises = (patchedMessages as { recipientJid: string; message: proto.IMessage }[]).map(
|
||||||
async ({ recipientJid: jid, message: patchedMessage }: { recipientJid: string; message: proto.IMessage }) => {
|
async ({ recipientJid: jid, message: patchedMessage }: { recipientJid: string; message: proto.IMessage }) => {
|
||||||
try {
|
try {
|
||||||
if (!jid) return null
|
if (!jid) return null
|
||||||
|
|
||||||
const msgToEncrypt = resolveMessageForRecipient(jid, patchedMessage)
|
const msgToEncrypt = resolveDsmMessageForRecipient(jid, patchedMessage, dsmMessage, meId, meLid, meLidUser)
|
||||||
const bytes = encodeWAMessage(msgToEncrypt)
|
const bytes = encodeWAMessage(msgToEncrypt)
|
||||||
const mutexKey = jid
|
const mutexKey = jid
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user