From e92270a9ab60850a50aab3ebc5e6b011f74bf307 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 11 Dec 2024 12:48:26 +0400 Subject: [PATCH] Add "View Discussion" button to third column. --- Telegram/SourceFiles/dialogs/dialogs_key.h | 8 +++- .../SourceFiles/history/history_widget.cpp | 6 +-- .../view/history_view_replies_section.cpp | 2 +- .../view/history_view_scheduled_section.cpp | 2 +- .../info/profile/info_profile_actions.cpp | 39 ++++++++++++++++++- .../inline_bots/bot_attach_web_view.cpp | 2 +- .../inline_bots/inline_results_inner.cpp | 2 +- .../window/window_session_controller.cpp | 13 +++++-- .../window/window_session_controller.h | 8 ++-- 9 files changed, 65 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_key.h b/Telegram/SourceFiles/dialogs/dialogs_key.h index 8b5d22ed7..52c07fa17 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_key.h +++ b/Telegram/SourceFiles/dialogs/dialogs_key.h @@ -121,8 +121,12 @@ struct EntryState { FilterId filterId = 0; FullReplyTo currentReplyTo; - friend inline auto operator<=>(EntryState, EntryState) noexcept - = default; + friend inline auto operator<=>( + const EntryState&, + const EntryState&) = default; + friend inline bool operator==( + const EntryState&, + const EntryState&) = default; }; struct SearchState { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index c9ec3fd81..de9569656 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1014,7 +1014,7 @@ void HistoryWidget::refreshTopBarActiveChat() { const auto state = computeDialogsEntryState(); _topBar->setActiveChat(state, _history->sendActionPainter()); if (state.key) { - controller()->setCurrentDialogsEntryState(state); + controller()->setDialogsEntryState(state); } } @@ -1989,7 +1989,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived( UserData *samePeerBot, MsgId samePeerReplyTo) { if (samePeerBot) { - const auto to = controller()->currentDialogsEntryState(); + const auto to = controller()->dialogsEntryStateCurrent(); if (!to.key.owningHistory()) { return false; } @@ -2222,7 +2222,7 @@ void HistoryWidget::showHistory( _showAtMsgHighlightPart = {}; _showAtMsgHighlightPartOffsetHint = 0; - const auto wasState = controller()->currentDialogsEntryState(); + const auto wasState = controller()->dialogsEntryStateCurrent(); const auto startBot = (showAtMsgId == ShowAndStartBotMsgId); _showAndMaybeSendStart = (showAtMsgId == ShowAndMaybeStartBotMsgId); if (startBot || _showAndMaybeSendStart) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 687551768..62b1e29d1 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1521,7 +1521,7 @@ void RepliesWidget::refreshTopBarActiveChat() { }; _topBar->setActiveChat(state, _sendAction.get()); _composeControls->setCurrentDialogsEntryState(state); - controller()->setCurrentDialogsEntryState(state); + controller()->setDialogsEntryState(state); } void RepliesWidget::refreshUnreadCountBadge(std::optional count) { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index ec9843a5a..5090dd42b 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -186,7 +186,7 @@ ScheduledWidget::ScheduledWidget( }; _topBar->setActiveChat(state, nullptr); _composeControls->setCurrentDialogsEntryState(state); - controller->setCurrentDialogsEntryState(state); + controller->setDialogsEntryState(state); _topBar->move(0, 0); _topBar->resizeToWidth(width()); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index b9a19fafd..068b29c3b 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -967,6 +967,8 @@ private: not_null user); Ui::MultiSlideTracker fillChannelButtons( not_null channel); + Ui::MultiSlideTracker fillDiscussionButtons( + not_null channel); void addReportReaction(Ui::MultiSlideTracker &tracker); void addReportReaction( @@ -1915,7 +1917,11 @@ void DetailsFiller::setupMainButtons() { return fillUserButtons(user); }); } else if (const auto channel = _peer->asChannel()) { - if (!channel->isMegagroup()) { + if (channel->isMegagroup()) { + wrapButtons([=] { + return fillDiscussionButtons(channel); + }); + } else { wrapButtons([=] { return fillChannelButtons(channel); }); @@ -2080,6 +2086,37 @@ Ui::MultiSlideTracker DetailsFiller::fillChannelButtons( return tracker; } +Ui::MultiSlideTracker DetailsFiller::fillDiscussionButtons( + not_null channel) { + using namespace rpl::mappers; + + Ui::MultiSlideTracker tracker; + auto window = _controller->parentController(); + auto viewDiscussionVisible = rpl::combine( + _controller->wrapValue(), + window->dialogsEntryStateValue() + ) | rpl::map([=](Wrap wrap, const Dialogs::EntryState &state) { + const auto history = state.key.history(); + return (wrap == Wrap::Side) + && (state.section == Dialogs::EntryState::Section::Replies) + && history + && (history->peer == channel); + }); + auto viewDiscussion = [=] { + window->showPeerHistory( + channel, + Window::SectionShow::Way::Forward); + }; + AddMainButton( + _wrap, + tr::lng_profile_view_discussion(), + std::move(viewDiscussionVisible), + std::move(viewDiscussion), + tracker); + + return tracker; +} + object_ptr DetailsFiller::fill() { Expects(!_topic || !_topic->creating()); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index cf50857b1..da2122c6c 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -348,7 +348,7 @@ WebViewContext ResolveContext( WebViewContext context) { if (!context.dialogsEntryState.key) { if (const auto strong = context.controller.get()) { - context.dialogsEntryState = strong->currentDialogsEntryState(); + context.dialogsEntryState = strong->dialogsEntryStateCurrent(); } } if (!context.action) { diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp index 6f1ae7916..002bf1f97 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp @@ -700,7 +700,7 @@ void Inner::switchPm() { } else { _inlineBot->botInfo->startToken = _switchPmStartToken; _inlineBot->botInfo->inlineReturnTo - = _controller->currentDialogsEntryState(); + = _controller->dialogsEntryStateCurrent(); _controller->showPeerHistory( _inlineBot, Window::SectionShow::Way::ClearStack, diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index e7b656586..9f4a72396 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1847,13 +1847,18 @@ bool SessionController::jumpToChatListEntry(Dialogs::RowDescriptor row) { return false; } -void SessionController::setCurrentDialogsEntryState( +void SessionController::setDialogsEntryState( Dialogs::EntryState state) { - _currentDialogsEntryState = state; + _dialogsEntryState = state; } -Dialogs::EntryState SessionController::currentDialogsEntryState() const { - return _currentDialogsEntryState; +Dialogs::EntryState SessionController::dialogsEntryStateCurrent() const { + return _dialogsEntryState.current(); +} + +auto SessionController::dialogsEntryStateValue() const +-> rpl::producer { + return _dialogsEntryState.value(); } bool SessionController::switchInlineQuery( diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 041c55113..9403467c0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -394,8 +394,10 @@ public: rpl::producer activeChatValue() const; bool jumpToChatListEntry(Dialogs::RowDescriptor row); - void setCurrentDialogsEntryState(Dialogs::EntryState state); - [[nodiscard]] Dialogs::EntryState currentDialogsEntryState() const; + void setDialogsEntryState(Dialogs::EntryState state); + [[nodiscard]] Dialogs::EntryState dialogsEntryStateCurrent() const; + [[nodiscard]] auto dialogsEntryStateValue() const + -> rpl::producer; bool switchInlineQuery( Dialogs::EntryState to, not_null bot, @@ -708,7 +710,7 @@ private: int _chatEntryHistoryPosition = -1; bool _filtersActivated = false; - Dialogs::EntryState _currentDialogsEntryState; + rpl::variable _dialogsEntryState; base::Timer _invitePeekTimer;