From 10adbecb9c2b4ccd62c0d5a49ca99775d4c025c5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 Nov 2020 20:54:43 +0300 Subject: [PATCH] Support creating polls in RepliesSection. --- .../view/history_view_replies_section.cpp | 5 +++++ .../view/history_view_replies_section.h | 2 ++ .../view/history_view_top_bar_widget.cpp | 18 +++++++++++------- Telegram/SourceFiles/mainwidget.cpp | 4 +++- Telegram/SourceFiles/window/section_widget.h | 4 ++++ .../SourceFiles/window/window_peer_menu.cpp | 3 ++- Telegram/SourceFiles/window/window_peer_menu.h | 1 + 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 1d53ed6651..33a088c853 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1398,6 +1398,11 @@ bool RepliesWidget::replyToMessage(not_null item) { return true; } +MsgId RepliesWidget::currentReplyToIdFor( + not_null history) const { + return (_history == history) ? replyToId() : 0; +} + void RepliesWidget::saveState(not_null memento) { memento->setReplies(_replies); memento->setReplyReturns(_replyReturns); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index 63e055abc3..18acc60305 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -88,6 +88,8 @@ public: const Window::SectionShow ¶ms, MsgId messageId) override; bool replyToMessage(not_null item) override; + MsgId currentReplyToIdFor( + not_null history) const override; void setInternalState( const QRect &geometry, diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 6de1fb6440..a4edc14ef3 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -238,9 +238,11 @@ void TopBarWidget::showMenu() { peer, FilterId(), addAction, - (_section == Section::Scheduled) + (_section == Section::Scheduled ? Window::PeerMenuSource::ScheduledSection - : Window::PeerMenuSource::History); + : (_section == Section::Replies) + ? Window::PeerMenuSource::RepliesSection + : Window::PeerMenuSource::History)); } else if (const auto folder = _activeChat.folder()) { Window::FillFolderMenu( _controller, @@ -686,12 +688,14 @@ void TopBarWidget::updateControlsVisibility() { _unreadBadge->show(); } const auto historyMode = (_section == Section::History); - const auto scheduledMode = (_section == Section::Scheduled); - const auto showInScheduledMode = (_activeChat.peer() - && _activeChat.peer()->canSendPolls()); + const auto hasPollsMenu = _activeChat.peer() + && _activeChat.peer()->canSendPolls(); + const auto hasMenu = !_activeChat.folder() + && ((_section == Section::Scheduled || _section == Section::Replies) + ? hasPollsMenu + : historyMode); updateSearchVisibility(); - _menuToggle->setVisible(!_activeChat.folder() - && (scheduledMode ? showInScheduledMode : historyMode)); + _menuToggle->setVisible(hasMenu); _infoToggle->setVisible(historyMode && !_activeChat.folder() && !Adaptive::OneColumn() diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 63a1f13e4a..e74d2118d9 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -820,7 +820,9 @@ crl::time MainWidget::highlightStartTime(not_null item) cons } MsgId MainWidget::currentReplyToIdFor(not_null history) const { - if (_history->history() == history) { + if (_mainSection) { + return _mainSection->currentReplyToIdFor(history); + } else if (_history->history() == history) { return _history->replyToId(); } else if (const auto localDraft = history->localDraft()) { return localDraft->msgId; diff --git a/Telegram/SourceFiles/window/section_widget.h b/Telegram/SourceFiles/window/section_widget.h index 6d5f3b7fdc..664fe97105 100644 --- a/Telegram/SourceFiles/window/section_widget.h +++ b/Telegram/SourceFiles/window/section_widget.h @@ -128,6 +128,10 @@ public: virtual bool replyToMessage(not_null item) { return false; } + [[nodiscard]] virtual MsgId currentReplyToIdFor( + not_null history) const { + return 0; + } // Create a memento of that section to store it in the history stack. // This method may modify the section ("take" heavy items). diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index d105b74280..90088b65ee 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -650,7 +650,8 @@ void Filler::addPollAction(not_null peer) { } void Filler::fill() { - if (_source == PeerMenuSource::ScheduledSection) { + if (_source == PeerMenuSource::ScheduledSection + || _source == PeerMenuSource::RepliesSection) { addPollAction(_peer); return; } diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index e733211a46..f5c9f1a2e6 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -37,6 +37,7 @@ enum class PeerMenuSource { History, Profile, ScheduledSection, + RepliesSection, }; using PeerMenuCallback = Fn