From 0826895c6b8c2660305a7e0f94c614cf60cbbc6a Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Thu, 22 Jan 2026 14:34:22 +0200 Subject: [PATCH] history: add proper logging support in history --- src/Utils/history.ts | 13 +++++++++---- src/Utils/process-message.ts | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Utils/history.ts b/src/Utils/history.ts index 7572940e..ff7207e1 100644 --- a/src/Utils/history.ts +++ b/src/Utils/history.ts @@ -6,6 +6,7 @@ import { WAMessageStubType } from '../Types' import { toNumber } from './generics' import { normalizeMessageContent } from './messages' import { downloadContentFromMessage } from './messages-media' +import type { ILogger } from './logger.js' const inflatePromise = promisify(inflate) @@ -25,12 +26,15 @@ export const downloadHistory = async (msg: proto.Message.IHistorySyncNotificatio return syncData } -export const processHistoryMessage = (item: proto.IHistorySync) => { +export const processHistoryMessage = (item: proto.IHistorySync, logger?: ILogger) => { const messages: WAMessage[] = [] const contacts: Contact[] = [] const chats: Chat[] = [] - // Extract LID-PN mappings for all sync types const lidPnMappings: LIDMapping[] = [] + + logger?.trace({ progress: item.progress }, 'processing history of type '+ item.syncType?.toString()) + + // Extract LID-PN mappings for all sync types for (const m of item.phoneNumberToLidMappings || []) { if (m.lidJid && m.pnJid) { lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid }) @@ -102,7 +106,8 @@ export const processHistoryMessage = (item: proto.IHistorySync) => { export const downloadAndProcessHistorySyncNotification = async ( msg: proto.Message.IHistorySyncNotification, - options: RequestInit + options: RequestInit, + logger?: ILogger ) => { let historyMsg: proto.HistorySync if (msg.initialHistBootstrapInlinePayload) { @@ -111,7 +116,7 @@ export const downloadAndProcessHistorySyncNotification = async ( historyMsg = await downloadHistory(msg, options) } - return processHistoryMessage(historyMsg) + return processHistoryMessage(historyMsg, logger) } export const getHistoryMsg = (message: proto.IMessage) => { diff --git a/src/Utils/process-message.ts b/src/Utils/process-message.ts index 6817fb3b..2e8a0f40 100644 --- a/src/Utils/process-message.ts +++ b/src/Utils/process-message.ts @@ -285,7 +285,7 @@ const processMessage = async ( }) } - const data = await downloadAndProcessHistorySyncNotification(histNotification, options) + const data = await downloadAndProcessHistorySyncNotification(histNotification, options, logger) // Emit LID-PN mappings from history sync // This is how WhatsApp Web learns mappings for chats with non-contacts