fix: getUniqueChatIds выводит объекты, сформированные по последним сообщениям в каждом чате.

This commit is contained in:
Vufer 2025-06-30 22:03:18 +03:00
parent 4fe93cac7c
commit 49621f1518

16
bot.js
View File

@ -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() {