From 08ba28539fdd073d0b3ad3409ac1b036151be448 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 27 Jan 2021 00:57:51 +0300 Subject: [PATCH] Return error 500 if sent message was immediately deleted and can't be returned. --- telegram-bot-api/Client.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 2df448d..4847f66 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -8714,21 +8714,23 @@ void Client::delete_message(int64 chat_id, int64 message_id, bool only_from_cach auto it = messages_.find({chat_id, message_id}); if (it == messages_.end()) { if (yet_unsent_messages_.count({chat_id, message_id}) > 0) { - // yet unsent message is deleted, possible only if we are trying to write to inaccessible supergroup + // yet unsent message is deleted, possible only if we are trying to write to inaccessible supergroup or + // sent message was deleted before added to the chat auto chat_info = get_chat(chat_id); CHECK(chat_info != nullptr); - Status error; - if (chat_info->type != ChatInfo::Type::Supergroup) { - LOG(ERROR) << "Yet unsent message " << message_id << " is deleted in the chat " << chat_id; - error = Status::Error(403, "Forbidden: bot is not a member of the chat"); - } else { + Status error = + Status::Error(500, "Internal Server Error: sent message was immediately deleted and can't be returned"); + if (chat_info->type == ChatInfo::Type::Supergroup) { auto supergroup_info = get_supergroup_info(chat_info->supergroup_id); CHECK(supergroup_info != nullptr); - if (supergroup_info->is_supergroup) { - error = Status::Error(403, "Forbidden: bot is not a member of the supergroup chat"); - } else { - error = Status::Error(403, "Forbidden: bot is not a member of the channel chat"); + if (supergroup_info->status->get_id() == td_api::chatMemberStatusBanned::ID || + supergroup_info->status->get_id() == td_api::chatMemberStatusLeft::ID) { + if (supergroup_info->is_supergroup) { + error = Status::Error(403, "Forbidden: bot is not a member of the supergroup chat"); + } else { + error = Status::Error(403, "Forbidden: bot is not a member of the channel chat"); + } } }