diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index bfb67ebb3..caf53952b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -25646,42 +25646,9 @@ bool MessagesManager::can_set_game_score(DialogId dialog_id, const Message *m) c } Result> MessagesManager::get_dialog_reply_markup( - DialogId dialog_id, tl_object_ptr &&reply_markup_ptr) const { - if (reply_markup_ptr == nullptr) { - return nullptr; - } - - auto dialog_type = dialog_id.get_type(); - bool is_anonymous = td_->dialog_manager_->is_anonymous_administrator(dialog_id, nullptr); - - bool only_inline_keyboard = is_anonymous; - bool request_buttons_allowed = dialog_type == DialogType::User; - bool switch_inline_buttons_allowed = !is_anonymous; - - TRY_RESULT(reply_markup, - get_reply_markup(std::move(reply_markup_ptr), td_->auth_manager_->is_bot(), only_inline_keyboard, - request_buttons_allowed, switch_inline_buttons_allowed)); - if (reply_markup == nullptr) { - return nullptr; - } - - switch (dialog_type) { - case DialogType::User: - if (reply_markup->type != ReplyMarkup::Type::InlineKeyboard) { - reply_markup->is_personal = false; - } - break; - case DialogType::Channel: - case DialogType::Chat: - case DialogType::SecretChat: - case DialogType::None: - // nothing special - break; - default: - UNREACHABLE(); - } - - return std::move(reply_markup); + DialogId dialog_id, tl_object_ptr &&reply_markup) const { + return get_reply_markup(std::move(reply_markup), dialog_id, td_->auth_manager_->is_bot(), + td_->dialog_manager_->is_anonymous_administrator(dialog_id, nullptr)); } class MessagesManager::ForwardMessagesLogEvent { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index f3cc3e002..9b66e9de6 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2774,7 +2774,7 @@ class MessagesManager final : public Actor { void change_message_files(DialogId dialog_id, const Message *m, const vector &old_file_ids); Result> get_dialog_reply_markup( - DialogId dialog_id, tl_object_ptr &&reply_markup_ptr) const TD_WARN_UNUSED_RESULT; + DialogId dialog_id, tl_object_ptr &&reply_markup) const TD_WARN_UNUSED_RESULT; bool get_dialog_view_as_topics(const Dialog *d) const; diff --git a/td/telegram/ReplyMarkup.cpp b/td/telegram/ReplyMarkup.cpp index e5f693d2d..23e08a100 100644 --- a/td/telegram/ReplyMarkup.cpp +++ b/td/telegram/ReplyMarkup.cpp @@ -710,8 +710,8 @@ static Result get_inline_keyboard_button(tl_object_ptr> get_reply_markup(tl_object_ptr &&reply_markup_ptr, bool is_bot, - bool only_inline_keyboard, bool request_buttons_allowed, +Result> get_reply_markup(td_api::object_ptr &&reply_markup_ptr, + bool is_bot, bool only_inline_keyboard, bool request_buttons_allowed, bool switch_inline_buttons_allowed) { CHECK(!only_inline_keyboard || !request_buttons_allowed); if (reply_markup_ptr == nullptr || !is_bot) { @@ -824,6 +824,36 @@ Result> get_reply_markup(tl_object_ptr> get_reply_markup(td_api::object_ptr &&reply_markup_ptr, + DialogId dialog_id, bool is_bot, bool is_anonymous) { + auto dialog_type = dialog_id.get_type(); + bool only_inline_keyboard = is_anonymous; + bool request_buttons_allowed = dialog_type == DialogType::User; + bool switch_inline_buttons_allowed = !is_anonymous; + + TRY_RESULT(reply_markup, get_reply_markup(std::move(reply_markup_ptr), is_bot, only_inline_keyboard, + request_buttons_allowed, switch_inline_buttons_allowed)); + if (reply_markup == nullptr) { + return nullptr; + } + switch (dialog_type) { + case DialogType::User: + if (reply_markup->type != ReplyMarkup::Type::InlineKeyboard) { + reply_markup->is_personal = false; + } + break; + case DialogType::Channel: + case DialogType::Chat: + case DialogType::SecretChat: + case DialogType::None: + // nothing special + break; + default: + UNREACHABLE(); + } + return std::move(reply_markup); +} + unique_ptr dup_reply_markup(const unique_ptr &reply_markup) { if (reply_markup == nullptr) { return nullptr; diff --git a/td/telegram/ReplyMarkup.h b/td/telegram/ReplyMarkup.h index dc96be21b..e1b5dd3df 100644 --- a/td/telegram/ReplyMarkup.h +++ b/td/telegram/ReplyMarkup.h @@ -103,9 +103,12 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ReplyMarkup &repl unique_ptr get_reply_markup(tl_object_ptr &&reply_markup_ptr, bool is_bot, bool only_inline_keyboard, bool message_contains_mention); -Result> get_reply_markup(tl_object_ptr &&reply_markup_ptr, bool is_bot, - bool only_inline_keyboard, bool request_buttons_allowed, - bool switch_inline_buttons_allowed) TD_WARN_UNUSED_RESULT; +Result> get_reply_markup(td_api::object_ptr &&reply_markup_ptr, + bool is_bot, bool only_inline_keyboard, bool request_buttons_allowed, + bool switch_inline_buttons_allowed); + +Result> get_reply_markup(td_api::object_ptr &&reply_markup_ptr, + DialogId dialog_id, bool is_bot, bool is_anonymous); unique_ptr dup_reply_markup(const unique_ptr &reply_markup);