From 1db552102742c0794e24edee61deb45e7cb764a8 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 25 Feb 2021 22:11:11 +0300 Subject: [PATCH] Add fast path in check_message. --- telegram-bot-api/Client.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index ea1848d..a98a8c8 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -3723,11 +3723,16 @@ void Client::check_message(Slice chat_id_str, int64 message_id, bool allow_empty check_chat(chat_id_str, access_rights, std::move(query), [this, message_id, allow_empty, message_type, on_success = std::move(on_success)]( int64 chat_id, PromisedQueryPtr query) mutable { - if (!have_message_access(chat_id)) { + if ((message_id <= 0 && !allow_empty) || !have_message_access(chat_id)) { return fail_query_with_error(std::move(query), 400, "MESSAGE_NOT_FOUND", PSLICE() << message_type << " not found"); } + if (message_id <= 0) { + CHECK(allow_empty); + return on_success(chat_id, 0, std::move(query)); + } + send_request(make_object(chat_id, message_id), std::make_unique>( this, chat_id, allow_empty, message_type, std::move(query), std::move(on_success))); @@ -6460,7 +6465,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { std::make_unique(this, std::move(query))); }; check_message(chat_id, reply_to_message_id, reply_to_message_id <= 0 || allow_sending_without_reply, - AccessRights::Write, "reply message", std::move(query), std::move(on_success)); + AccessRights::Write, "replied message", std::move(query), std::move(on_success)); }); return Status::OK(); } @@ -7696,7 +7701,7 @@ void Client::do_send_message(object_ptr input_messa std::make_unique(this, std::move(query))); }; check_message(chat_id, reply_to_message_id, reply_to_message_id <= 0 || allow_sending_without_reply, - AccessRights::Write, "reply message", std::move(query), std::move(on_success)); + AccessRights::Write, "replied message", std::move(query), std::move(on_success)); }); }