Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7436beaab3 | |||
| 5926da9493 | |||
| 2b2c3f9155 | |||
| 6060293793 | |||
| afce764ce9 |
+1
-3
@@ -27,7 +27,6 @@ export type BaileysEventMap = {
|
|||||||
chats: Chat[]
|
chats: Chat[]
|
||||||
contacts: Contact[]
|
contacts: Contact[]
|
||||||
messages: WAMessage[]
|
messages: WAMessage[]
|
||||||
/** Past participants for group chats (people who left/were removed). userJid is always a phone number (PN), never a LID. */
|
|
||||||
pastParticipants?: proto.IPastParticipants[] | null
|
pastParticipants?: proto.IPastParticipants[] | null
|
||||||
isLatest?: boolean
|
isLatest?: boolean
|
||||||
progress?: number | null
|
progress?: number | null
|
||||||
@@ -187,8 +186,7 @@ export type BufferedEventData = {
|
|||||||
chats: { [jid: string]: Chat }
|
chats: { [jid: string]: Chat }
|
||||||
contacts: { [jid: string]: Contact }
|
contacts: { [jid: string]: Contact }
|
||||||
messages: { [uqId: string]: WAMessage }
|
messages: { [uqId: string]: WAMessage }
|
||||||
/** Keyed by groupJid for O(1) deduplication across chunks */
|
pastParticipants?: proto.IPastParticipants[]
|
||||||
pastParticipants: { [groupJid: string]: proto.IPastParticipant[] }
|
|
||||||
empty: boolean
|
empty: boolean
|
||||||
isLatest: boolean
|
isLatest: boolean
|
||||||
progress?: number | null
|
progress?: number | null
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import EventEmitter from 'events'
|
import EventEmitter from 'events'
|
||||||
import { proto } from '../../WAProto/index.js'
|
|
||||||
import type {
|
import type {
|
||||||
BaileysEvent,
|
BaileysEvent,
|
||||||
BaileysEventEmitter,
|
BaileysEventEmitter,
|
||||||
@@ -891,7 +890,6 @@ const makeBufferData = (): BufferedEventData => {
|
|||||||
chats: {},
|
chats: {},
|
||||||
messages: {},
|
messages: {},
|
||||||
contacts: {},
|
contacts: {},
|
||||||
pastParticipants: {},
|
|
||||||
isLatest: false,
|
isLatest: false,
|
||||||
empty: true
|
empty: true
|
||||||
},
|
},
|
||||||
@@ -969,28 +967,10 @@ function append<E extends BufferableEvent>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge pastParticipants with deduplication by groupJid and by userJid within each group.
|
data.historySets.pastParticipants = [
|
||||||
// Multiple HistorySync chunks can carry the same group -- we merge rather than concatenate
|
...(data.historySets.pastParticipants || []),
|
||||||
// to avoid duplicate entries in the final event delivered to the consumer.
|
...(eventData.pastParticipants || [])
|
||||||
for (const group of (eventData.pastParticipants ?? []) as proto.IPastParticipants[]) {
|
]
|
||||||
const groupJid = group.groupJid
|
|
||||||
if (!groupJid) continue
|
|
||||||
|
|
||||||
if (!data.historySets.pastParticipants[groupJid]) {
|
|
||||||
data.historySets.pastParticipants[groupJid] = []
|
|
||||||
}
|
|
||||||
|
|
||||||
const existing = data.historySets.pastParticipants[groupJid]
|
|
||||||
const seenJids = new Set(existing.map(p => p.userJid).filter(Boolean))
|
|
||||||
|
|
||||||
for (const participant of (group.pastParticipants ?? []) as proto.IPastParticipant[]) {
|
|
||||||
if (participant.userJid && !seenJids.has(participant.userJid)) {
|
|
||||||
existing.push(participant)
|
|
||||||
seenJids.add(participant.userJid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.historySets.empty = false
|
data.historySets.empty = false
|
||||||
data.historySets.syncType = eventData.syncType
|
data.historySets.syncType = eventData.syncType
|
||||||
data.historySets.progress = eventData.progress
|
data.historySets.progress = eventData.progress
|
||||||
@@ -1316,10 +1296,7 @@ function consolidateEvents(data: BufferedEventData) {
|
|||||||
chats: Object.values(data.historySets.chats),
|
chats: Object.values(data.historySets.chats),
|
||||||
messages: Object.values(data.historySets.messages),
|
messages: Object.values(data.historySets.messages),
|
||||||
contacts: Object.values(data.historySets.contacts),
|
contacts: Object.values(data.historySets.contacts),
|
||||||
// Convert dedup map back to array. Each entry has groupJid + participants (all unique userJids).
|
pastParticipants: data.historySets.pastParticipants,
|
||||||
pastParticipants: Object.entries(data.historySets.pastParticipants).map(
|
|
||||||
([groupJid, participants]) => ({ groupJid, pastParticipants: participants })
|
|
||||||
),
|
|
||||||
syncType: data.historySets.syncType,
|
syncType: data.historySets.syncType,
|
||||||
progress: data.historySets.progress,
|
progress: data.historySets.progress,
|
||||||
isLatest: data.historySets.isLatest,
|
isLatest: data.historySets.isLatest,
|
||||||
|
|||||||
+1
-15
@@ -374,25 +374,11 @@ export const processHistoryMessage = (item: proto.IHistorySync, logger?: ILogger
|
|||||||
// Convert Map back to array for return
|
// Convert Map back to array for return
|
||||||
const lidPnMappings = Array.from(lidPnMap.values())
|
const lidPnMappings = Array.from(lidPnMap.values())
|
||||||
|
|
||||||
// Normalize pastParticipants: resolve LID userJids → PN so the consumer always
|
|
||||||
// receives a phone number, never an opaque LID identifier.
|
|
||||||
// Uses the lidPnMap built above (populated from phoneNumberToLidMappings + conversations).
|
|
||||||
// If a LID cannot be resolved, the original value is kept rather than dropping the participant.
|
|
||||||
const pastParticipants: proto.IPastParticipants[] = (item.pastParticipants ?? []).map(group => ({
|
|
||||||
groupJid: group.groupJid,
|
|
||||||
pastParticipants: (group.pastParticipants ?? []).map(participant => {
|
|
||||||
const userJid = participant.userJid
|
|
||||||
if (!userJid || !isAnyLidUser(userJid)) return participant
|
|
||||||
const mapping = lidPnMap.get(jidNormalizedUser(userJid))
|
|
||||||
return mapping?.pn ? { ...participant, userJid: mapping.pn } : participant
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chats,
|
chats,
|
||||||
contacts,
|
contacts,
|
||||||
messages,
|
messages,
|
||||||
pastParticipants,
|
pastParticipants: item.pastParticipants,
|
||||||
lidPnMappings,
|
lidPnMappings,
|
||||||
syncType: item.syncType,
|
syncType: item.syncType,
|
||||||
progress: item.progress
|
progress: item.progress
|
||||||
|
|||||||
Reference in New Issue
Block a user