diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index f6a59e656..5bd32636f 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -242,9 +242,9 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) { _wasForMsgId = FullMsgId(to->channelId(), to->id); auto markupFlags = to->replyKeyboardFlags(); - _forceReply = markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply; - _maximizeSize = !(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_resize); - _singleUse = _forceReply || (markupFlags & MTPDreplyKeyboardMarkup::Flag::f_single_use); + _forceReply = markupFlags & ReplyMarkupFlag::ForceReply; + _maximizeSize = !(markupFlags & ReplyMarkupFlag::Resize); + _singleUse = _forceReply || (markupFlags & ReplyMarkupFlag::SingleUse); if (const auto markup = to->Get()) { _placeholder = markup->placeholder; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 2fc24ea98..6ba61aee6 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -781,7 +781,7 @@ not_null History::addNewToBack( } if (item->definesReplyKeyboard()) { auto markupFlags = item->replyKeyboardFlags(); - if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) + if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) { auto getMarkupSenders = [this]() -> base::flat_set>* { if (auto chat = peer->asChat()) { @@ -794,7 +794,8 @@ not_null History::addNewToBack( if (auto markupSenders = getMarkupSenders()) { markupSenders->insert(item->from()); } - if (markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero) { // zero markup means replyKeyboardHide + if (markupFlags & ReplyMarkupFlag::None) { + // None markup means replyKeyboardHide. if (lastKeyboardFrom == item->from()->id || (!lastKeyboardInited && !peer->isChat() @@ -1294,13 +1295,13 @@ void History::addItemsToLists( if (item->author()->id) { if (markupSenders) { // chats with bots if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) { - auto markupFlags = item->replyKeyboardFlags(); - if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) || item->mentionsMe()) { + const auto markupFlags = item->replyKeyboardFlags(); + if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) { bool wasKeyboardHide = markupSenders->contains(item->author()); if (!wasKeyboardHide) { markupSenders->insert(item->author()); } - if (!(markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero)) { + if (!(markupFlags & ReplyMarkupFlag::None)) { if (!lastKeyboardInited) { bool botNotInChat = false; if (peer->isChat()) { @@ -1321,9 +1322,9 @@ void History::addItemsToLists( } } } else if (!lastKeyboardInited && item->definesReplyKeyboard() && !item->out()) { // conversations with bots - MTPDreplyKeyboardMarkup::Flags markupFlags = item->replyKeyboardFlags(); - if (!(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_selective) || item->mentionsMe()) { - if (markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_zero) { + const auto markupFlags = item->replyKeyboardFlags(); + if (!(markupFlags & ReplyMarkupFlag::Selective) || item->mentionsMe()) { + if (markupFlags & ReplyMarkupFlag::None) { clearLastKeyboard(); } else { lastKeyboardInited = true; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 7a9d5ac3f..31840b221 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -231,7 +231,7 @@ void HistoryItem::setGroupId(MessageGroupId groupId) { HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() { if (const auto markup = Get()) { - if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) { + if (markup->flags & ReplyMarkupFlag::Inline) { return markup; } } @@ -379,7 +379,7 @@ void HistoryItem::setIsPinned(bool pinned) { bool HistoryItem::definesReplyKeyboard() const { if (const auto markup = Get()) { - if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) { + if (markup->flags & ReplyMarkupFlag::Inline) { return false; } return true; @@ -390,7 +390,7 @@ bool HistoryItem::definesReplyKeyboard() const { return (_flags & MTPDmessage::Flag::f_reply_markup); } -MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const { +ReplyMarkupFlags HistoryItem::replyKeyboardFlags() const { Expects(definesReplyKeyboard()); if (const auto markup = Get()) { @@ -399,7 +399,7 @@ MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const { // optimization: don't create markup component for the case // MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag - return MTPDreplyKeyboardMarkup_ClientFlag::f_zero | 0; + return ReplyMarkupFlag::None; } void HistoryItem::addLogEntryOriginal( diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index b9517f2ae..754f1e6f3 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -57,6 +57,18 @@ class ElementDelegate; struct HiddenSenderInfo; class History; +enum class ReplyMarkupFlag : uint32 { + None = (1U << 0), + ForceReply = (1U << 1), + HasSwitchInlineButton = (1U << 2), + Inline = (1U << 3), + Resize = (1U << 4), + SingleUse = (1U << 5), + Selective = (1U << 6), +}; +inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; } +using ReplyMarkupFlags = base::flags; + class HistoryItem : public RuntimeComposer { public: static not_null Create( @@ -149,7 +161,7 @@ public: } [[nodiscard]] bool definesReplyKeyboard() const; - [[nodiscard]] MTPDreplyKeyboardMarkup::Flags replyKeyboardFlags() const; + [[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const; [[nodiscard]] bool hasSwitchInlineButton() const { return _clientFlags & MTPDmessage_ClientFlag::f_has_switch_inline_button; diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 54b5bf6e4..05d178e98 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -887,7 +887,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows( if (type == Type::SwitchInline) { // Optimization flag. // Fast check on all new messages if there is a switch button to auto-click it. - flags |= MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button; + flags |= ReplyMarkupFlag::HasSwitchInlineButton; } }, [&](const MTPDkeyboardButtonGame &data) { row.emplace_back(Type::Game, qs(data.vtext())); @@ -932,35 +932,26 @@ void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) { rows.clear(); inlineKeyboard = nullptr; - switch (markup.type()) { - case mtpc_replyKeyboardMarkup: { - auto &d = markup.c_replyKeyboardMarkup(); - flags = d.vflags().v; - placeholder = d.vplaceholder() ? qs(*d.vplaceholder()) : QString(); - - createFromButtonRows(d.vrows().v); - } break; - - case mtpc_replyInlineMarkup: { - auto &d = markup.c_replyInlineMarkup(); - flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline; + using Flag = ReplyMarkupFlag; + markup.match([&](const MTPDreplyKeyboardMarkup &data) { + flags = (data.is_resize() ? Flag::Resize : Flag()) + | (data.is_selective() ? Flag::Selective : Flag()) + | (data.is_single_use() ? Flag::SingleUse : Flag()); + placeholder = qs(data.vplaceholder().value_or_empty()); + createFromButtonRows(data.vrows().v); + }, [&](const MTPDreplyInlineMarkup &data) { + flags = Flag::Inline; placeholder = QString(); - - createFromButtonRows(d.vrows().v); - } break; - - case mtpc_replyKeyboardHide: { - auto &d = markup.c_replyKeyboardHide(); - flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_zero; + createFromButtonRows(data.vrows().v); + }, [&](const MTPDreplyKeyboardHide &data) { + flags = Flag::None | (data.is_selective() ? Flag::Selective : Flag()); placeholder = QString(); - } break; - - case mtpc_replyKeyboardForceReply: { - auto &d = markup.c_replyKeyboardForceReply(); - flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply; - placeholder = d.vplaceholder() ? qs(*d.vplaceholder()) : QString(); - } break; - } + }, [&](const MTPDreplyKeyboardForceReply &data) { + flags = Flag::ForceReply + | (data.is_selective() ? Flag::Selective : Flag()) + | (data.is_single_use() ? Flag::SingleUse : Flag()); + placeholder = qs(data.vplaceholder().value_or_empty()); + }); } void HistoryMessageReplyMarkup::create( diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 7acae7c72..2173a1afe 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -225,18 +225,19 @@ struct HistoryMessageMarkupButton { }; -struct HistoryMessageReplyMarkup : public RuntimeComponent { +struct HistoryMessageReplyMarkup + : public RuntimeComponent { using Button = HistoryMessageMarkupButton; HistoryMessageReplyMarkup() = default; - HistoryMessageReplyMarkup(MTPDreplyKeyboardMarkup::Flags f) : flags(f) { + HistoryMessageReplyMarkup(ReplyMarkupFlags flags) : flags(flags) { } void create(const MTPReplyMarkup &markup); void create(const HistoryMessageReplyMarkup &markup); std::vector> rows; - MTPDreplyKeyboardMarkup::Flags flags = 0; + ReplyMarkupFlags flags = 0; QString placeholder; std::unique_ptr inlineKeyboard; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 5d73a4dc3..ca1dc74f3 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1132,7 +1132,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { } else if (config.inlineMarkup) { markup->create(*config.inlineMarkup); } - if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button) { + if (markup->flags & ReplyMarkupFlag::HasSwitchInlineButton) { _clientFlags |= MTPDmessage_ClientFlag::f_has_switch_inline_button; } } diff --git a/Telegram/SourceFiles/mtproto/type_utils.h b/Telegram/SourceFiles/mtproto/type_utils.h index 0b1b69fe8..451e40b9b 100644 --- a/Telegram/SourceFiles/mtproto/type_utils.h +++ b/Telegram/SourceFiles/mtproto/type_utils.h @@ -76,21 +76,3 @@ enum class MTPDmessage_ClientFlag : uint32 { }; inline constexpr bool is_flag_type(MTPDmessage_ClientFlag) { return true; } using MTPDmessage_ClientFlags = base::flags; - -enum class MTPDreplyKeyboardMarkup_ClientFlag : uint32 { - // none (zero) markup - f_zero = (1U << 30), - - // markup just wants a text reply - f_force_reply = (1U << 29), - - // markup keyboard is inline - f_inline = (1U << 28), - - // markup has a switch inline keyboard button - f_has_switch_inline_button = (1U << 27), - - // update this when adding new client side flags - MIN_FIELD = (1U << 27), -}; -DEFINE_MTP_CLIENT_FLAGS(MTPDreplyKeyboardMarkup)