Move get_dialog_reply_markup implementation to ReplyMarkup.cpp.

This commit is contained in:
levlam 2024-01-11 20:35:02 +03:00
parent 645102e4ed
commit 10f77aee95
4 changed files with 42 additions and 42 deletions

View File

@ -25646,42 +25646,9 @@ bool MessagesManager::can_set_game_score(DialogId dialog_id, const Message *m) c
}
Result<unique_ptr<ReplyMarkup>> MessagesManager::get_dialog_reply_markup(
DialogId dialog_id, tl_object_ptr<td_api::ReplyMarkup> &&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<td_api::ReplyMarkup> &&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 {

View File

@ -2774,7 +2774,7 @@ class MessagesManager final : public Actor {
void change_message_files(DialogId dialog_id, const Message *m, const vector<FileId> &old_file_ids);
Result<unique_ptr<ReplyMarkup>> get_dialog_reply_markup(
DialogId dialog_id, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr) const TD_WARN_UNUSED_RESULT;
DialogId dialog_id, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup) const TD_WARN_UNUSED_RESULT;
bool get_dialog_view_as_topics(const Dialog *d) const;

View File

@ -710,8 +710,8 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
return std::move(current_button);
}
Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot,
bool only_inline_keyboard, bool request_buttons_allowed,
Result<unique_ptr<ReplyMarkup>> get_reply_markup(td_api::object_ptr<td_api::ReplyMarkup> &&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<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMark
return std::move(reply_markup);
}
Result<unique_ptr<ReplyMarkup>> get_reply_markup(td_api::object_ptr<td_api::ReplyMarkup> &&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<ReplyMarkup> dup_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup) {
if (reply_markup == nullptr) {
return nullptr;

View File

@ -103,9 +103,12 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ReplyMarkup &repl
unique_ptr<ReplyMarkup> get_reply_markup(tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot,
bool only_inline_keyboard, bool message_contains_mention);
Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot,
bool only_inline_keyboard, bool request_buttons_allowed,
bool switch_inline_buttons_allowed) TD_WARN_UNUSED_RESULT;
Result<unique_ptr<ReplyMarkup>> get_reply_markup(td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr,
bool is_bot, bool only_inline_keyboard, bool request_buttons_allowed,
bool switch_inline_buttons_allowed);
Result<unique_ptr<ReplyMarkup>> get_reply_markup(td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr,
DialogId dialog_id, bool is_bot, bool is_anonymous);
unique_ptr<ReplyMarkup> dup_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup);