From 9b52c4054c036f282c8e5dfe82e7de31ca30b165 Mon Sep 17 00:00:00 2001 From: Burtasov Date: Sun, 11 Feb 2024 19:10:50 +0000 Subject: [PATCH] fix: partially deleting of media groups --- src/telegram/bot/message/handlers.ts | 5 +++++ src/telegram/bot/message/processors.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/telegram/bot/message/handlers.ts b/src/telegram/bot/message/handlers.ts index 28ac928..a47ca86 100644 --- a/src/telegram/bot/message/handlers.ts +++ b/src/telegram/bot/message/handlers.ts @@ -28,6 +28,7 @@ interface MediaGroup { id: string; notePath: string; initialMsg: TelegramBot.Message; + mediaMessages: TelegramBot.Message[]; error?: Error; filesPaths: string[]; } @@ -310,6 +311,8 @@ async function handleMediaGroup(plugin: TelegramSyncPlugin, distributionRule: Me if (mediaGroups.length > 0 && plugin.messagesLeftCnt == 0) { for (const mg of mediaGroups) { try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (mg.initialMsg as any).mediaMessages = mg.mediaMessages; const noteContent = await createNoteContent( plugin, mg.notePath, @@ -340,6 +343,7 @@ async function appendFileToNote( if (mediaGroup) { mediaGroup.filesPaths.push(filePath); if (msg.caption || !mediaGroup.initialMsg) mediaGroup.initialMsg = msg; + mediaGroup.mediaMessages.push(msg); if (error) mediaGroup.error = error; return; } @@ -355,6 +359,7 @@ async function appendFileToNote( id: msg.media_group_id, notePath, initialMsg: msg, + mediaMessages: [], error: error, filesPaths: [filePath], }; diff --git a/src/telegram/bot/message/processors.ts b/src/telegram/bot/message/processors.ts index 08ca2f5..a2a8ec8 100644 --- a/src/telegram/bot/message/processors.ts +++ b/src/telegram/bot/message/processors.ts @@ -33,6 +33,8 @@ export async function finalizeMessageProcessing(plugin: TelegramSyncPlugin, msg: } // eslint-disable-next-line @typescript-eslint/no-explicit-any const originalMsg: Api.Message | undefined = (msg as any).originalUserMsg; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const mediaMessages: TelegramBot.Message[] = (msg as any).mediaMessages || []; if (originalMsg) { await plugin.bot.deleteMessage(msg.chat.id, msg.message_id); @@ -45,6 +47,9 @@ export async function finalizeMessageProcessing(plugin: TelegramSyncPlugin, msg: if (plugin.settings.deleteMessagesFromTelegram && originalMsg) { await originalMsg.delete(); } else if (plugin.settings.deleteMessagesFromTelegram && hoursDifference <= 24) { + for (const mediaMsg of mediaMessages) { + await plugin.bot.deleteMessage(mediaMsg.chat.id, mediaMsg.message_id); + } await plugin.bot.deleteMessage(msg.chat.id, msg.message_id); } else { let needReply = true;