implement message reporting tokens (#1906)
* feat: implement message reporting tokens and privacy token handling * feat: add support for privacy tokens in profile picture requests and history sync * chore: pr feedback purpshell * fix: improve privacy token handling and error messaging in socket configuration * feat: enhance privacy token handling with improved sender mapping * chore: removing tc token in favor of #2080 * chore: revert some unecessary changes * feat(reporting): enhance reporting token extraction and compilation logic * feat(reporting): add unit tests for reporting token utilities * fix(reporting): streamline reporting token attachment logic in message sending * fix: adjust reporting token inclusion logic to prevent retries * chore: add return type to shouldIncludeReportingToken and improve getToken function type safety
This commit is contained in:
committed by
GitHub
parent
4e681d3219
commit
c9c3481817
@@ -35,6 +35,7 @@ import {
|
||||
} from '../Utils'
|
||||
import { getUrlInfo } from '../Utils/link-preview'
|
||||
import { makeKeyedMutex } from '../Utils/make-mutex'
|
||||
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils'
|
||||
import {
|
||||
areJidsSameUser,
|
||||
type BinaryNode,
|
||||
@@ -624,6 +625,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const destinationJid = !isStatus ? finalJid : statusJid
|
||||
const binaryNodeContent: BinaryNode[] = []
|
||||
const devices: DeviceWithJid[] = []
|
||||
let reportingMessage: proto.IMessage | undefined
|
||||
|
||||
const meMsg: proto.IMessage = {
|
||||
deviceSentMessage: {
|
||||
@@ -734,6 +736,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
const bytes = encodeWAMessage(patched)
|
||||
reportingMessage = patched
|
||||
const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'lid'
|
||||
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId
|
||||
|
||||
@@ -798,6 +801,12 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
const { user: ownUser } = jidDecode(ownId)!
|
||||
if (!participant) {
|
||||
const patchedForReporting = await patchMessageBeforeSending(message, [jid])
|
||||
reportingMessage = Array.isArray(patchedForReporting)
|
||||
? patchedForReporting.find(item => item.recipientJid === jid) || patchedForReporting[0]
|
||||
: patchedForReporting
|
||||
}
|
||||
|
||||
if (!isRetryResend) {
|
||||
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net'
|
||||
@@ -970,6 +979,30 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
logger.debug({ jid }, 'adding device identity')
|
||||
}
|
||||
|
||||
if (
|
||||
!isNewsletter &&
|
||||
!isRetryResend &&
|
||||
reportingMessage?.messageContextInfo?.messageSecret &&
|
||||
shouldIncludeReportingToken(reportingMessage)
|
||||
) {
|
||||
try {
|
||||
const encoded = encodeWAMessage(reportingMessage)
|
||||
const reportingKey: WAMessageKey = {
|
||||
id: msgId,
|
||||
fromMe: true,
|
||||
remoteJid: destinationJid,
|
||||
participant: participant?.jid
|
||||
}
|
||||
const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey)
|
||||
if (reportingNode) {
|
||||
;(stanza.content as BinaryNode[]).push(reportingNode)
|
||||
logger.trace({ jid }, 'added reporting token to message')
|
||||
}
|
||||
} catch (error: any) {
|
||||
logger.warn({ jid, trace: error?.stack }, 'failed to attach reporting token')
|
||||
}
|
||||
}
|
||||
|
||||
const contactTcTokenData =
|
||||
!isGroup && !isRetryResend && !isStatus ? await authState.keys.get('tctoken', [destinationJid]) : {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user