Delete photos after exit from card

This commit is contained in:
Artyom Ashirov 2024-11-16 18:04:32 +03:00
parent ec96f67dfe
commit 44ae5a6631

View File

@ -425,6 +425,16 @@ export default class AdminProductHandler {
const messageId = callbackQuery.message.message_id;
const [locationId, categoryId, subcategoryId] = callbackQuery.data.replace('prod_subcategory_', '').split('_');
const state = this.userStates.get(chatId)
for (const msgId of state?.msgToDelete || []) {
try {
await this.bot.deleteMessage(chatId, msgId);
} catch (e) {
// ignore if can't delete
}
}
this.userStates.delete(chatId);
try {
@ -750,22 +760,29 @@ Coordinates: ${product.hidden_coordinates}
]
};
let photoMessage;
let hiddenPhotoMessage;
// Send product photos
if (product.photo_url) {
try {
await this.bot.sendPhoto(chatId, product.photo_url, {caption: 'Public photo'});
photoMessage = await this.bot.sendPhoto(chatId, product.photo_url, {caption: 'Public photo'});
} catch (e) {
await this.bot.sendPhoto(chatId, "./corrupt-photo.jpg", {caption: 'Public photo'})
photoMessage = await this.bot.sendPhoto(chatId, "./corrupt-photo.jpg", {caption: 'Public photo'})
}
}
if (product.hidden_photo_url) {
try {
await this.bot.sendPhoto(chatId, product.hidden_photo_url, {caption: 'Hidden photo'});
hiddenPhotoMessage = await this.bot.sendPhoto(chatId, product.hidden_photo_url, {caption: 'Hidden photo'});
} catch (e) {
await this.bot.sendPhoto(chatId, "./corrupt-photo.jpg", {caption: 'Hidden photo'})
hiddenPhotoMessage = await this.bot.sendPhoto(chatId, "./corrupt-photo.jpg", {caption: 'Hidden photo'})
}
}
this.userStates.set(chatId, {
msgToDelete: [photoMessage.message_id, hiddenPhotoMessage.message_id]
})
await this.bot.deleteMessage(chatId, messageId);
await this.bot.sendMessage(chatId, message, {reply_markup: keyboard});
} catch (error) {