From 4518067f9cfacb0744653f640b5dc9f9d4ea6ad1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 20 Dec 2022 18:21:00 +0400 Subject: [PATCH] Support persistent flag for bot keyboard. --- Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp | 7 ++++++- Telegram/SourceFiles/chat_helpers/bot_keyboard.h | 2 ++ .../SourceFiles/history/history_item_reply_markup.cpp | 3 ++- .../SourceFiles/history/history_item_reply_markup.h | 1 + Telegram/SourceFiles/history/history_widget.cpp | 11 ++++++++--- Telegram/SourceFiles/history/history_widget.h | 1 + 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index f07740ccc..93ee5f624 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -255,7 +255,7 @@ void BotKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pres bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) { if (!to || !to->definesReplyKeyboard()) { if (_wasForMsgId.msg) { - _maximizeSize = _singleUse = _forceReply = false; + _maximizeSize = _singleUse = _forceReply = _persistent = false; _wasForMsgId = FullMsgId(); _placeholder = QString(); _impl = nullptr; @@ -275,6 +275,7 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) { _forceReply = markupFlags & ReplyMarkupFlag::ForceReply; _maximizeSize = !(markupFlags & ReplyMarkupFlag::Resize); _singleUse = _forceReply || (markupFlags & ReplyMarkupFlag::SingleUse); + _persistent = (markupFlags & ReplyMarkupFlag::Persistent); if (const auto markup = to->Get()) { _placeholder = markup->data.placeholder; @@ -326,6 +327,10 @@ bool BotKeyboard::singleUse() const { return _singleUse; } +bool BotKeyboard::persistent() const { + return _persistent; +} + void BotKeyboard::updateStyle(int newWidth) { if (!_impl) return; diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.h b/Telegram/SourceFiles/chat_helpers/bot_keyboard.h index 6ac69b97b..622bbd5be 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.h +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.h @@ -49,6 +49,7 @@ public: [[nodiscard]] bool maximizeSize() const; [[nodiscard]] bool singleUse() const; + [[nodiscard]] bool persistent() const; [[nodiscard]] FullMsgId forMsgId() const { return _wasForMsgId; @@ -91,6 +92,7 @@ private: bool _maximizeSize = false; bool _singleUse = false; bool _forceReply = false; + bool _persistent = false; QPoint _lastMousePos; std::unique_ptr _impl; diff --git a/Telegram/SourceFiles/history/history_item_reply_markup.cpp b/Telegram/SourceFiles/history/history_item_reply_markup.cpp index ad4b032c4..94ec3b2ae 100644 --- a/Telegram/SourceFiles/history/history_item_reply_markup.cpp +++ b/Telegram/SourceFiles/history/history_item_reply_markup.cpp @@ -154,7 +154,8 @@ HistoryMessageMarkupData::HistoryMessageMarkupData( data->match([&](const MTPDreplyKeyboardMarkup &data) { flags = (data.is_resize() ? Flag::Resize : Flag()) | (data.is_selective() ? Flag::Selective : Flag()) - | (data.is_single_use() ? Flag::SingleUse : Flag()); + | (data.is_single_use() ? Flag::SingleUse : Flag()) + | (data.is_persistent() ? Flag::Persistent : Flag()); placeholder = qs(data.vplaceholder().value_or_empty()); fillRows(data.vrows().v); }, [&](const MTPDreplyInlineMarkup &data) { diff --git a/Telegram/SourceFiles/history/history_item_reply_markup.h b/Telegram/SourceFiles/history/history_item_reply_markup.h index 5c7507cd3..49ffd1e46 100644 --- a/Telegram/SourceFiles/history/history_item_reply_markup.h +++ b/Telegram/SourceFiles/history/history_item_reply_markup.h @@ -23,6 +23,7 @@ enum class ReplyMarkupFlag : uint32 { Selective = (1U << 6), IsNull = (1U << 7), OnlyBuyButton = (1U << 8), + Persistent = (1U << 9), }; inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; } using ReplyMarkupFlags = base::flags; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ca1bb1102..c0c19ad5f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2737,7 +2737,7 @@ void HistoryWidget::updateControlsVisibility() { if (_kbShown) { _kbScroll->show(); _tabbedSelectorToggle->hide(); - _botKeyboardHide->show(); + showKeyboardHideButton(); _botKeyboardShow->hide(); _botCommandStart->hide(); } else if (_kbReplyTo) { @@ -4543,6 +4543,11 @@ bool HistoryWidget::kbWasHidden() const { _history->lastKeyboardHiddenId)); } +void HistoryWidget::showKeyboardHideButton() { + _botKeyboardHide->setVisible(!_peer->isUser() + || !_keyboard->persistent()); +} + void HistoryWidget::toggleKeyboard(bool manual) { auto fieldEnabled = canWriteMessage() && !_showAnimation; if (_kbShown || _kbReplyTo) { @@ -4594,7 +4599,7 @@ void HistoryWidget::toggleKeyboard(bool manual) { _history->lastKeyboardHiddenId = 0; } } else if (fieldEnabled) { - _botKeyboardHide->show(); + showKeyboardHideButton(); _botKeyboardShow->hide(); _kbScroll->show(); _kbShown = true; @@ -5741,7 +5746,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { if (hasMarkup) { _kbScroll->show(); _tabbedSelectorToggle->hide(); - _botKeyboardHide->show(); + showKeyboardHideButton(); } else { _kbScroll->hide(); _tabbedSelectorToggle->show(); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 1dea2549e..3429b79b0 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -391,6 +391,7 @@ private: [[nodiscard]] int computeMaxFieldHeight() const; void toggleMuteUnmute(); void reportSelectedMessages(); + void showKeyboardHideButton(); void toggleKeyboard(bool manual = true); void startBotCommand(); void hidePinnedMessage();