fix: extract LID-PN mappings from history sync phoneNumberToLidMappings (#2268)
This commit is contained in:
committed by
GitHub
parent
32134a870e
commit
a89736f89d
@@ -1,7 +1,7 @@
|
||||
import { promisify } from 'util'
|
||||
import { inflate } from 'zlib'
|
||||
import { proto } from '../../WAProto/index.js'
|
||||
import type { Chat, Contact, WAMessage } from '../Types'
|
||||
import type { Chat, Contact, LIDMapping, WAMessage } from '../Types'
|
||||
import { WAMessageStubType } from '../Types'
|
||||
import { toNumber } from './generics'
|
||||
import { normalizeMessageContent } from './messages'
|
||||
@@ -29,6 +29,13 @@ export const processHistoryMessage = (item: proto.IHistorySync) => {
|
||||
const messages: WAMessage[] = []
|
||||
const contacts: Contact[] = []
|
||||
const chats: Chat[] = []
|
||||
// Extract LID-PN mappings for all sync types
|
||||
const lidPnMappings: LIDMapping[] = []
|
||||
for (const m of item.phoneNumberToLidMappings || []) {
|
||||
if (m.lidJid && m.pnJid) {
|
||||
lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid })
|
||||
}
|
||||
}
|
||||
|
||||
switch (item.syncType) {
|
||||
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
||||
@@ -87,6 +94,7 @@ export const processHistoryMessage = (item: proto.IHistorySync) => {
|
||||
chats,
|
||||
contacts,
|
||||
messages,
|
||||
lidPnMappings,
|
||||
syncType: item.syncType,
|
||||
progress: item.progress
|
||||
}
|
||||
|
||||
@@ -287,6 +287,16 @@ const processMessage = async (
|
||||
|
||||
const data = await downloadAndProcessHistorySyncNotification(histNotification, options)
|
||||
|
||||
// Emit LID-PN mappings from history sync
|
||||
// This is how WhatsApp Web learns mappings for chats with non-contacts
|
||||
if (data.lidPnMappings?.length) {
|
||||
logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync')
|
||||
// eslint-disable-next-line max-depth
|
||||
for (const mapping of data.lidPnMappings) {
|
||||
ev.emit('lid-mapping.update', mapping)
|
||||
}
|
||||
}
|
||||
|
||||
ev.emit('messaging-history.set', {
|
||||
...data,
|
||||
isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
|
||||
|
||||
Reference in New Issue
Block a user