Delete photos after exit from card
This commit is contained in:
@@ -425,6 +425,16 @@ export default class AdminProductHandler {
|
|||||||
const messageId = callbackQuery.message.message_id;
|
const messageId = callbackQuery.message.message_id;
|
||||||
const [locationId, categoryId, subcategoryId] = callbackQuery.data.replace('prod_subcategory_', '').split('_');
|
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);
|
this.userStates.delete(chatId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -750,22 +760,29 @@ Coordinates: ${product.hidden_coordinates}
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let photoMessage;
|
||||||
|
let hiddenPhotoMessage;
|
||||||
|
|
||||||
// Send product photos
|
// Send product photos
|
||||||
if (product.photo_url) {
|
if (product.photo_url) {
|
||||||
try {
|
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) {
|
} 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) {
|
if (product.hidden_photo_url) {
|
||||||
try {
|
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) {
|
} 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.deleteMessage(chatId, messageId);
|
||||||
await this.bot.sendMessage(chatId, message, {reply_markup: keyboard});
|
await this.bot.sendMessage(chatId, message, {reply_markup: keyboard});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user