Skip to content

Commit

Permalink
fix: partially deleting of media groups
Browse files Browse the repository at this point in the history
  • Loading branch information
soberhacker committed Feb 11, 2024
1 parent 71a63bb commit 9b52c40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/telegram/bot/message/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface MediaGroup {
id: string;
notePath: string;
initialMsg: TelegramBot.Message;
mediaMessages: TelegramBot.Message[];
error?: Error;
filesPaths: string[];
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand All @@ -355,6 +359,7 @@ async function appendFileToNote(
id: msg.media_group_id,
notePath,
initialMsg: msg,
mediaMessages: [],
error: error,
filesPaths: [filePath],
};
Expand Down
5 changes: 5 additions & 0 deletions src/telegram/bot/message/processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 9b52c40

Please sign in to comment.