From 49621f15183871eead42130af1c82101e31821ed Mon Sep 17 00:00:00 2001 From: Vufer Date: Mon, 30 Jun 2025 22:03:18 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20getUniqueChatIds=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D1=82=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D1=8B,=20=D1=81=D1=84=D0=BE=D1=80=D0=BC=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=BC=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE=D0=BC=20=D1=87=D0=B0=D1=82=D0=B5?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bot.js b/bot.js index a61ddc1..6c444b6 100644 --- a/bot.js +++ b/bot.js @@ -40,11 +40,21 @@ class TelegramHistoryBot { } } getUniqueChatIds() { - const ids = new Set(); + const chatMap = new Map(); + for (const msg of this.history) { - ids.add(msg.chat_id); + const current = chatMap.get(msg.chat_id); + if (!current || new Date(msg.timestamp) > new Date(current.timestamp)) { + chatMap.set(msg.chat_id, { + chat_id: msg.chat_id, + title: msg.chat_title || `(${msg.chat_id})`, + timestamp: msg.timestamp + }); + } } - return Array.from(ids); + + // Преобразуем Map в массив, возвращаем только chat_id и title + return Array.from(chatMap.values()).map(({ chat_id, title }) => ({ chat_id, title })) } async init() {