From 9c9ee999c47638c848100f02494fb5ad12e271cf Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 22 Sep 2018 03:47:40 +0300 Subject: [PATCH] Simplify InlineQueriesManager::get_inline_message_content. GitOrigin-RevId: bf32b2756b899513afa6d935820d5ad37d158267 --- td/telegram/InlineQueriesManager.cpp | 10 ++++------ td/telegram/InlineQueriesManager.h | 16 +++++++--------- td/telegram/MessagesManager.cpp | 22 +++++++++------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 5d852b0b7..734ae6f9c 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -429,23 +429,21 @@ bool InlineQueriesManager::register_inline_message_content( return false; } -std::tuple InlineQueriesManager::get_inline_message_content( - int64 query_id, const string &result_id) { +const InlineMessageContent *InlineQueriesManager::get_inline_message_content(int64 query_id, const string &result_id) { auto it = inline_message_contents_.find(query_id); if (it == inline_message_contents_.end()) { - return std::make_tuple(nullptr, nullptr, false); + return nullptr; } auto result_it = it->second.find(result_id); if (result_it == it->second.end()) { - return std::make_tuple(nullptr, nullptr, false); + return nullptr; } if (update_bot_usage(get_inline_bot_user_id(query_id))) { save_recently_used_bots(); } - return std::make_tuple(result_it->second.message_content.get(), result_it->second.message_reply_markup.get(), - result_it->second.disable_web_page_preview); + return &result_it->second; } UserId InlineQueriesManager::get_inline_bot_user_id(int64 query_id) const { diff --git a/td/telegram/InlineQueriesManager.h b/td/telegram/InlineQueriesManager.h index 6eff600d8..5d0100473 100644 --- a/td/telegram/InlineQueriesManager.h +++ b/td/telegram/InlineQueriesManager.h @@ -26,7 +26,6 @@ #include "td/utils/common.h" #include "td/utils/Status.h" -#include #include #include @@ -38,6 +37,12 @@ class MessageContent; class Game; +struct InlineMessageContent { + unique_ptr message_content; + unique_ptr message_reply_markup; + bool disable_web_page_preview; +}; + class InlineQueriesManager : public Actor { public: InlineQueriesManager(Td *td, ActorShared<> parent); @@ -56,8 +61,7 @@ class InlineQueriesManager : public Actor { void remove_recent_inline_bot(UserId bot_user_id, Promise &&promise); - std::tuple get_inline_message_content(int64 query_id, - const string &result_id); + const InlineMessageContent *get_inline_message_content(int64 query_id, const string &result_id); UserId get_inline_bot_user_id(int64 query_id) const; @@ -148,12 +152,6 @@ class InlineQueriesManager : public Actor { MultiTimeout drop_inline_query_result_timeout_{"DropInlineQueryResultTimeout"}; std::unordered_map inline_query_results_; // query_hash -> result - struct InlineMessageContent { - unique_ptr message_content; - unique_ptr message_reply_markup; - bool disable_web_page_preview; - }; - std::unordered_map> inline_message_contents_; // query_id -> [result_id -> inline_message_content] diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 3b3fe13ef..4c7d69f82 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -18071,26 +18071,22 @@ Result MessagesManager::send_inline_query_result_message(DialogId dia UNREACHABLE(); } - const MessageContent *message_content; - const ReplyMarkup *reply_markup; - bool disable_web_page_preview; - std::tie(message_content, reply_markup, disable_web_page_preview) = - td_->inline_queries_manager_->get_inline_message_content(query_id, result_id); - if (message_content == nullptr) { + const InlineMessageContent *content = td_->inline_queries_manager_->get_inline_message_content(query_id, result_id); + if (content == nullptr) { return Status::Error(5, "Inline query result not found"); } - TRY_STATUS(can_send_message_content(dialog_id, message_content, false)); + TRY_STATUS(can_send_message_content(dialog_id, content->message_content.get(), false)); bool need_update_dialog_pos = false; - Message *m = - get_message_to_send(d, get_reply_to_message_id(d, reply_to_message_id), disable_notification, from_background, - dup_message_content(dialog_id, message_content, false), &need_update_dialog_pos); + Message *m = get_message_to_send( + d, get_reply_to_message_id(d, reply_to_message_id), disable_notification, from_background, + dup_message_content(dialog_id, content->message_content.get(), false), &need_update_dialog_pos); m->via_bot_user_id = td_->inline_queries_manager_->get_inline_bot_user_id(query_id); - if (reply_markup != nullptr && !to_secret) { - m->reply_markup = make_unique(*reply_markup); + if (content->message_reply_markup != nullptr && !to_secret) { + m->reply_markup = make_unique(*content->message_reply_markup); } - m->disable_web_page_preview = disable_web_page_preview; + m->disable_web_page_preview = content->disable_web_page_preview; m->clear_draft = true; update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos);