From 073eff93a225e979408b020d8c3e5e194253f12f Mon Sep 17 00:00:00 2001 From: Nir Date: Sun, 8 Mar 2026 19:40:16 +0200 Subject: [PATCH] fetchMessages: Add searchOption.messageId and utilize it in _getMessageById (#105) This fixes issue #104 Co-authored-by: nir --- src/controllers/messageController.js | 4 ++-- src/utils.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controllers/messageController.js b/src/controllers/messageController.js index cd50c27..50784d0 100644 --- a/src/controllers/messageController.js +++ b/src/controllers/messageController.js @@ -15,8 +15,8 @@ const { sendErrorResponse, decodeBase64 } = require('../utils') */ const _getMessageById = async (client, messageId, chatId) => { const chat = await client.getChatById(chatId) - const messages = await chat.fetchMessages({ limit: 100 }) - return messages.find((message) => { return message.id.id === messageId }) + const messages = await chat.fetchMessages({ messageId: messageId, limit: 1 }) + return messages[0] } /** diff --git a/src/utils.js b/src/utils.js index 3833c8a..fae04ea 100644 --- a/src/utils.js +++ b/src/utils.js @@ -98,6 +98,9 @@ const patchWWebLibrary = async (client) => { if (searchOptions && searchOptions.since !== undefined && Number.isFinite(searchOptions.since) && m.t < searchOptions.since) { return false } + if (searchOptions && searchOptions.messageId !== undefined && m.id.id != searchOptions.messageId) { + return false + } return true }