Simplify InlineQueriesManager::get_inline_message_content.

GitOrigin-RevId: bf32b2756b899513afa6d935820d5ad37d158267
This commit is contained in:
levlam 2018-09-22 03:47:40 +03:00
parent a23d62905b
commit 9c9ee999c4
3 changed files with 20 additions and 28 deletions

View File

@ -429,23 +429,21 @@ bool InlineQueriesManager::register_inline_message_content(
return false; return false;
} }
std::tuple<const MessageContent *, const ReplyMarkup *, bool> InlineQueriesManager::get_inline_message_content( const InlineMessageContent *InlineQueriesManager::get_inline_message_content(int64 query_id, const string &result_id) {
int64 query_id, const string &result_id) {
auto it = inline_message_contents_.find(query_id); auto it = inline_message_contents_.find(query_id);
if (it == inline_message_contents_.end()) { if (it == inline_message_contents_.end()) {
return std::make_tuple(nullptr, nullptr, false); return nullptr;
} }
auto result_it = it->second.find(result_id); auto result_it = it->second.find(result_id);
if (result_it == it->second.end()) { 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))) { if (update_bot_usage(get_inline_bot_user_id(query_id))) {
save_recently_used_bots(); save_recently_used_bots();
} }
return std::make_tuple(result_it->second.message_content.get(), result_it->second.message_reply_markup.get(), return &result_it->second;
result_it->second.disable_web_page_preview);
} }
UserId InlineQueriesManager::get_inline_bot_user_id(int64 query_id) const { UserId InlineQueriesManager::get_inline_bot_user_id(int64 query_id) const {

View File

@ -26,7 +26,6 @@
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/Status.h" #include "td/utils/Status.h"
#include <tuple>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
@ -38,6 +37,12 @@ class MessageContent;
class Game; class Game;
struct InlineMessageContent {
unique_ptr<MessageContent> message_content;
unique_ptr<ReplyMarkup> message_reply_markup;
bool disable_web_page_preview;
};
class InlineQueriesManager : public Actor { class InlineQueriesManager : public Actor {
public: public:
InlineQueriesManager(Td *td, ActorShared<> parent); InlineQueriesManager(Td *td, ActorShared<> parent);
@ -56,8 +61,7 @@ class InlineQueriesManager : public Actor {
void remove_recent_inline_bot(UserId bot_user_id, Promise<Unit> &&promise); void remove_recent_inline_bot(UserId bot_user_id, Promise<Unit> &&promise);
std::tuple<const MessageContent *, const ReplyMarkup *, bool> get_inline_message_content(int64 query_id, const InlineMessageContent *get_inline_message_content(int64 query_id, const string &result_id);
const string &result_id);
UserId get_inline_bot_user_id(int64 query_id) const; 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"}; MultiTimeout drop_inline_query_result_timeout_{"DropInlineQueryResultTimeout"};
std::unordered_map<uint64, InlineQueryResult> inline_query_results_; // query_hash -> result std::unordered_map<uint64, InlineQueryResult> inline_query_results_; // query_hash -> result
struct InlineMessageContent {
unique_ptr<MessageContent> message_content;
unique_ptr<ReplyMarkup> message_reply_markup;
bool disable_web_page_preview;
};
std::unordered_map<int64, std::unordered_map<string, InlineMessageContent>> std::unordered_map<int64, std::unordered_map<string, InlineMessageContent>>
inline_message_contents_; // query_id -> [result_id -> inline_message_content] inline_message_contents_; // query_id -> [result_id -> inline_message_content]

View File

@ -18071,26 +18071,22 @@ Result<MessageId> MessagesManager::send_inline_query_result_message(DialogId dia
UNREACHABLE(); UNREACHABLE();
} }
const MessageContent *message_content; const InlineMessageContent *content = td_->inline_queries_manager_->get_inline_message_content(query_id, result_id);
const ReplyMarkup *reply_markup; if (content == nullptr) {
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) {
return Status::Error(5, "Inline query result not found"); 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; bool need_update_dialog_pos = false;
Message *m = Message *m = get_message_to_send(
get_message_to_send(d, get_reply_to_message_id(d, reply_to_message_id), disable_notification, from_background, 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); 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); m->via_bot_user_id = td_->inline_queries_manager_->get_inline_bot_user_id(query_id);
if (reply_markup != nullptr && !to_secret) { if (content->message_reply_markup != nullptr && !to_secret) {
m->reply_markup = make_unique<ReplyMarkup>(*reply_markup); m->reply_markup = make_unique<ReplyMarkup>(*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; m->clear_draft = true;
update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos); update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos);