fix: getUniqueChatIds выводит объекты, сформированные по последним сообщениям в каждом чате.
This commit is contained in:
parent
4fe93cac7c
commit
49621f1518
16
bot.js
16
bot.js
@ -40,11 +40,21 @@ class TelegramHistoryBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
getUniqueChatIds() {
|
getUniqueChatIds() {
|
||||||
const ids = new Set();
|
const chatMap = new Map();
|
||||||
|
|
||||||
for (const msg of this.history) {
|
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() {
|
async init() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user