Skip to content

Commit 4c3e735

Browse files
committed
Use autogenerated constants in ReplyMarkup.
1 parent 7453760 commit 4c3e735

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

td/telegram/ReplyMarkup.cpp

+46-25
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424

2525
namespace td {
2626

27-
static constexpr int32 REPLY_MARKUP_FLAG_NEED_RESIZE_KEYBOARD = 1 << 0;
28-
static constexpr int32 REPLY_MARKUP_FLAG_IS_ONE_TIME_KEYBOARD = 1 << 1;
29-
static constexpr int32 REPLY_MARKUP_FLAG_IS_PERSONAL = 1 << 2;
30-
static constexpr int32 REPLY_MARKUP_FLAG_HAS_PLACEHOLDER = 1 << 3;
31-
static constexpr int32 REPLY_MARKUP_FLAG_IS_PERSISTENT = 1 << 4;
32-
3327
static bool operator==(const KeyboardButton &lhs, const KeyboardButton &rhs) {
3428
return lhs.type == rhs.type && lhs.text == rhs.text && lhs.url == rhs.url;
3529
}
@@ -395,10 +389,10 @@ unique_ptr<ReplyMarkup> get_reply_markup(tl_object_ptr<telegram_api::ReplyMarkup
395389
case telegram_api::replyKeyboardMarkup::ID: {
396390
auto keyboard_markup = move_tl_object_as<telegram_api::replyKeyboardMarkup>(reply_markup_ptr);
397391
reply_markup->type = ReplyMarkup::Type::ShowKeyboard;
398-
reply_markup->is_persistent = (keyboard_markup->flags_ & REPLY_MARKUP_FLAG_IS_PERSISTENT) != 0;
399-
reply_markup->need_resize_keyboard = (keyboard_markup->flags_ & REPLY_MARKUP_FLAG_NEED_RESIZE_KEYBOARD) != 0;
400-
reply_markup->is_one_time_keyboard = (keyboard_markup->flags_ & REPLY_MARKUP_FLAG_IS_ONE_TIME_KEYBOARD) != 0;
401-
reply_markup->is_personal = (keyboard_markup->flags_ & REPLY_MARKUP_FLAG_IS_PERSONAL) != 0;
392+
reply_markup->is_persistent = keyboard_markup->persistent_;
393+
reply_markup->need_resize_keyboard = keyboard_markup->resize_;
394+
reply_markup->is_one_time_keyboard = keyboard_markup->single_use_;
395+
reply_markup->is_personal = keyboard_markup->selective_;
402396
reply_markup->placeholder = std::move(keyboard_markup->placeholder_);
403397
reply_markup->keyboard.reserve(keyboard_markup->rows_.size());
404398
for (auto &row : keyboard_markup->rows_) {
@@ -422,13 +416,13 @@ unique_ptr<ReplyMarkup> get_reply_markup(tl_object_ptr<telegram_api::ReplyMarkup
422416
case telegram_api::replyKeyboardHide::ID: {
423417
auto hide_keyboard_markup = move_tl_object_as<telegram_api::replyKeyboardHide>(reply_markup_ptr);
424418
reply_markup->type = ReplyMarkup::Type::RemoveKeyboard;
425-
reply_markup->is_personal = (hide_keyboard_markup->flags_ & REPLY_MARKUP_FLAG_IS_PERSONAL) != 0;
419+
reply_markup->is_personal = hide_keyboard_markup->selective_;
426420
break;
427421
}
428422
case telegram_api::replyKeyboardForceReply::ID: {
429423
auto force_reply_markup = move_tl_object_as<telegram_api::replyKeyboardForceReply>(reply_markup_ptr);
430424
reply_markup->type = ReplyMarkup::Type::ForceReply;
431-
reply_markup->is_personal = (force_reply_markup->flags_ & REPLY_MARKUP_FLAG_IS_PERSONAL) != 0;
425+
reply_markup->is_personal = force_reply_markup->selective_;
432426
reply_markup->placeholder = std::move(force_reply_markup->placeholder_);
433427
break;
434428
}
@@ -978,20 +972,47 @@ tl_object_ptr<telegram_api::ReplyMarkup> ReplyMarkup::get_input_reply_markup(Use
978972
}
979973
rows.push_back(make_tl_object<telegram_api::keyboardButtonRow>(std::move(buttons)));
980974
}
981-
return make_tl_object<telegram_api::replyKeyboardMarkup>(
982-
is_persistent * REPLY_MARKUP_FLAG_IS_PERSISTENT +
983-
need_resize_keyboard * REPLY_MARKUP_FLAG_NEED_RESIZE_KEYBOARD +
984-
is_one_time_keyboard * REPLY_MARKUP_FLAG_IS_ONE_TIME_KEYBOARD +
985-
is_personal * REPLY_MARKUP_FLAG_IS_PERSONAL + (!placeholder.empty()) * REPLY_MARKUP_FLAG_HAS_PLACEHOLDER,
986-
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(rows), placeholder);
975+
int32 flags = 0;
976+
if (is_persistent) {
977+
flags |= telegram_api::replyKeyboardMarkup::PERSISTENT_MASK;
978+
}
979+
if (need_resize_keyboard) {
980+
flags |= telegram_api::replyKeyboardMarkup::RESIZE_MASK;
981+
}
982+
if (is_one_time_keyboard) {
983+
flags |= telegram_api::replyKeyboardMarkup::SINGLE_USE_MASK;
984+
}
985+
if (is_personal) {
986+
flags |= telegram_api::replyKeyboardMarkup::SELECTIVE_MASK;
987+
}
988+
if (!placeholder.empty()) {
989+
flags |= telegram_api::replyKeyboardMarkup::PLACEHOLDER_MASK;
990+
}
991+
return make_tl_object<telegram_api::replyKeyboardMarkup>(flags, false /*ignored*/, false /*ignored*/,
992+
false /*ignored*/, false /*ignored*/, std::move(rows),
993+
placeholder);
994+
}
995+
case ReplyMarkup::Type::ForceReply: {
996+
int32 flags = 0;
997+
if (is_one_time_keyboard) {
998+
flags |= telegram_api::replyKeyboardForceReply::SINGLE_USE_MASK;
999+
}
1000+
if (is_personal) {
1001+
flags |= telegram_api::replyKeyboardForceReply::SELECTIVE_MASK;
1002+
}
1003+
if (!placeholder.empty()) {
1004+
flags |= telegram_api::replyKeyboardForceReply::PLACEHOLDER_MASK;
1005+
}
1006+
return make_tl_object<telegram_api::replyKeyboardForceReply>(flags, false /*ignored*/, false /*ignored*/,
1007+
placeholder);
1008+
}
1009+
case ReplyMarkup::Type::RemoveKeyboard: {
1010+
int32 flags = 0;
1011+
if (is_personal) {
1012+
flags |= telegram_api::replyKeyboardHide::SELECTIVE_MASK;
1013+
}
1014+
return make_tl_object<telegram_api::replyKeyboardHide>(flags, false /*ignored*/);
9871015
}
988-
case ReplyMarkup::Type::ForceReply:
989-
return make_tl_object<telegram_api::replyKeyboardForceReply>(
990-
is_personal * REPLY_MARKUP_FLAG_IS_PERSONAL + (!placeholder.empty()) * REPLY_MARKUP_FLAG_HAS_PLACEHOLDER,
991-
false /*ignored*/, false /*ignored*/, placeholder);
992-
case ReplyMarkup::Type::RemoveKeyboard:
993-
return make_tl_object<telegram_api::replyKeyboardHide>(is_personal * REPLY_MARKUP_FLAG_IS_PERSONAL,
994-
false /*ignored*/);
9951016
default:
9961017
UNREACHABLE();
9971018
return nullptr;

0 commit comments

Comments
 (0)