Simplify InlineQueriesManager::get_inline_message_content.
GitOrigin-RevId: bf32b2756b899513afa6d935820d5ad37d158267
This commit is contained in:
parent
a23d62905b
commit
9c9ee999c4
@ -429,23 +429,21 @@ bool InlineQueriesManager::register_inline_message_content(
|
||||
return false;
|
||||
}
|
||||
|
||||
std::tuple<const MessageContent *, const ReplyMarkup *, bool> 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 {
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
@ -38,6 +37,12 @@ class MessageContent;
|
||||
|
||||
class Game;
|
||||
|
||||
struct InlineMessageContent {
|
||||
unique_ptr<MessageContent> message_content;
|
||||
unique_ptr<ReplyMarkup> 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<Unit> &&promise);
|
||||
|
||||
std::tuple<const MessageContent *, const ReplyMarkup *, bool> 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<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>>
|
||||
inline_message_contents_; // query_id -> [result_id -> inline_message_content]
|
||||
|
||||
|
@ -18071,26 +18071,22 @@ Result<MessageId> 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<ReplyMarkup>(*reply_markup);
|
||||
if (content->message_reply_markup != nullptr && !to_secret) {
|
||||
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;
|
||||
|
||||
update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos);
|
||||
|
Reference in New Issue
Block a user