Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 45cbdc4233 |
@@ -682,33 +682,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const canonicalizeCarouselRecipients = async (recipientJids: string[]) => {
|
|
||||||
const uniqueRecipients = [...new Set(recipientJids)]
|
|
||||||
const pnRecipients = uniqueRecipients.filter(jid => isPnUser(jid) || isHostedPnUser(jid))
|
|
||||||
const lidMappings = pnRecipients.length > 0
|
|
||||||
? await signalRepository.lidMapping.getLIDsForPNs(pnRecipients)
|
|
||||||
: []
|
|
||||||
|
|
||||||
const lidByPn = new Map((lidMappings || []).map(({ pn, lid }) => [pn, lid]))
|
|
||||||
const canonicalRecipients: string[] = []
|
|
||||||
|
|
||||||
for (const jid of uniqueRecipients) {
|
|
||||||
const canonicalJid = lidByPn.get(jid) || jid
|
|
||||||
if (!canonicalRecipients.includes(canonicalJid)) {
|
|
||||||
canonicalRecipients.push(canonicalJid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canonicalRecipients.length !== uniqueRecipients.length || canonicalRecipients.some((jid, index) => jid !== uniqueRecipients[index])) {
|
|
||||||
logger.debug(
|
|
||||||
{ before: uniqueRecipients, after: canonicalRecipients },
|
|
||||||
'[CAROUSEL] Canonicalized recipient addressing for session reuse'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return canonicalRecipients
|
|
||||||
}
|
|
||||||
|
|
||||||
const relayMessage = async (
|
const relayMessage = async (
|
||||||
jid: string,
|
jid: string,
|
||||||
message: proto.IMessage,
|
message: proto.IMessage,
|
||||||
@@ -995,30 +968,21 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
allRecipients.push(jid)
|
allRecipients.push(jid)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isCarouselFanout = isCarouselMessage(message)
|
await assertSessions(allRecipients)
|
||||||
const effectiveMeRecipients = isCarouselFanout
|
|
||||||
? await canonicalizeCarouselRecipients(meRecipients)
|
|
||||||
: meRecipients
|
|
||||||
const effectiveOtherRecipients = isCarouselFanout
|
|
||||||
? await canonicalizeCarouselRecipients(otherRecipients)
|
|
||||||
: otherRecipients
|
|
||||||
const effectiveAllRecipients = [...effectiveMeRecipients, ...effectiveOtherRecipients]
|
|
||||||
|
|
||||||
await assertSessions(effectiveAllRecipients)
|
|
||||||
|
|
||||||
const [
|
const [
|
||||||
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
|
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
|
||||||
{ nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }
|
{ nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
// For own devices: use DSM if available (1:1 chats only)
|
// For own devices: use DSM if available (1:1 chats only)
|
||||||
createParticipantNodes(effectiveMeRecipients, meMsg || message, extraAttrs),
|
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
||||||
createParticipantNodes(effectiveOtherRecipients, message, extraAttrs, meMsg)
|
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
||||||
])
|
])
|
||||||
participants.push(...meNodes)
|
participants.push(...meNodes)
|
||||||
participants.push(...otherNodes)
|
participants.push(...otherNodes)
|
||||||
|
|
||||||
if (effectiveMeRecipients.length > 0 || effectiveOtherRecipients.length > 0) {
|
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
||||||
extraAttrs['phash'] = generateParticipantHashV2([...effectiveMeRecipients, ...effectiveOtherRecipients])
|
extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients])
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
|
||||||
|
|||||||
+1
-48
@@ -41,12 +41,10 @@ import type { ILogger } from './logger'
|
|||||||
import {
|
import {
|
||||||
downloadContentFromMessage,
|
downloadContentFromMessage,
|
||||||
encryptedStream,
|
encryptedStream,
|
||||||
extractImageThumb,
|
|
||||||
generateThumbnail,
|
generateThumbnail,
|
||||||
getAudioDuration,
|
getAudioDuration,
|
||||||
getAudioWaveform,
|
getAudioWaveform,
|
||||||
getRawMediaUploadData,
|
getRawMediaUploadData,
|
||||||
getStream,
|
|
||||||
type MediaDownloadOptions
|
type MediaDownloadOptions
|
||||||
} from './messages-media'
|
} from './messages-media'
|
||||||
import { shouldIncludeReportingToken } from './reporting-utils'
|
import { shouldIncludeReportingToken } from './reporting-utils'
|
||||||
@@ -475,48 +473,6 @@ export const formatNativeFlowButton = (button: NativeButton): NativeFlowButton =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const recoverCarouselImageMetadata = async (
|
|
||||||
card: CarouselMessageOptions['cards'][number],
|
|
||||||
imageMessage: proto.Message.IImageMessage,
|
|
||||||
mediaOptions: MessageContentGenerationOptions
|
|
||||||
) => {
|
|
||||||
if (imageMessage.jpegThumbnail && imageMessage.height && imageMessage.width) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { stream } = await getStream(card.image!, mediaOptions.options)
|
|
||||||
const thumb = await extractImageThumb(stream)
|
|
||||||
|
|
||||||
if (!imageMessage.jpegThumbnail) {
|
|
||||||
imageMessage.jpegThumbnail = thumb.buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!imageMessage.width && thumb.original.width) {
|
|
||||||
imageMessage.width = thumb.original.width
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!imageMessage.height && thumb.original.height) {
|
|
||||||
imageMessage.height = thumb.original.height
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaOptions.logger?.info(
|
|
||||||
{
|
|
||||||
cardTitle: card.title,
|
|
||||||
hasJpegThumbnail: !!imageMessage.jpegThumbnail,
|
|
||||||
width: imageMessage.width,
|
|
||||||
height: imageMessage.height
|
|
||||||
},
|
|
||||||
'[CAROUSEL] Recovered image thumbnail/dimensions from source media'
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
mediaOptions.logger?.warn(
|
|
||||||
{ cardTitle: card.title, error },
|
|
||||||
'[CAROUSEL] Failed to recover image thumbnail/dimensions from source media'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a button message using Native Flow format wrapped in viewOnceMessage
|
* Generates a button message using Native Flow format wrapped in viewOnceMessage
|
||||||
* This is the modern approach for button messages that works on iOS and Android
|
* This is the modern approach for button messages that works on iOS and Android
|
||||||
@@ -692,10 +648,7 @@ export const generateCarouselMessage = async (
|
|||||||
if (hasMedia && mediaOptions) {
|
if (hasMedia && mediaOptions) {
|
||||||
if (card.image) {
|
if (card.image) {
|
||||||
const { imageMessage } = await prepareWAMessageMedia({ image: card.image }, mediaOptions)
|
const { imageMessage } = await prepareWAMessageMedia({ image: card.image }, mediaOptions)
|
||||||
if (imageMessage) {
|
// Validate image fields needed for WhatsApp rendering
|
||||||
await recoverCarouselImageMetadata(card, imageMessage, mediaOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imageMessage && !imageMessage.jpegThumbnail) {
|
if (imageMessage && !imageMessage.jpegThumbnail) {
|
||||||
mediaOptions.logger?.warn(
|
mediaOptions.logger?.warn(
|
||||||
{ cardTitle: card.title },
|
{ cardTitle: card.title },
|
||||||
|
|||||||
Reference in New Issue
Block a user