From 195c0ab8fefa296fdd10ddac25f71d62e9a942ca Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 11 Sep 2022 05:40:56 +0300 Subject: [PATCH] [Improvement] Show linked chat/channel button in profile --- .../info/profile/info_profile_actions.cpp | 15 +++++++++++++++ .../info/profile/info_profile_values.cpp | 7 +++++++ .../info/profile/info_profile_values.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 9a502a82d..5d357b5ba 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -745,6 +745,21 @@ object_ptr DetailsFiller::setupInfo() { if (!_topic) { addTranslateToMenu(about.text, AboutWithIdValue(_peer)); } + + if (const auto channel = _peer->asChannel()) { + const auto controller = _controller->parentController(); + auto viewLinkedGroup = [=] { + controller->showPeerHistory( + channel->linkedChat(), + Window::SectionShow::Way::Forward); + }; + AddMainButton( + result, + (channel->isBroadcast() ? tr::lng_channel_discuss() : tr::lng_manage_linked_channel()), + HasLinkedChatValue(channel), + std::move(viewLinkedGroup), + tracker); + } } if (!_peer->isSelf() && !::Kotato::JsonSettings::GetBool("profile_top_mute")) { // No notifications toggle for Self => no separator. diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index b89b4cb98..7b92dac9d 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -376,6 +376,13 @@ rpl::producer CanAddContactValue(not_null user) { ) | rpl::map(!_1); } +rpl::producer HasLinkedChatValue(not_null channel) { + return channel->session().changes().peerFlagsValue( + channel, + UpdateFlag::ChannelLinkedChat + ) | rpl::map([channel] { return channel->linkedChat() != nullptr; }); +} + rpl::producer AmInChannelValue(not_null channel) { return channel->session().changes().peerFlagsValue( channel, diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.h b/Telegram/SourceFiles/info/profile/info_profile_values.h index f8f1cd315..581229903 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.h +++ b/Telegram/SourceFiles/info/profile/info_profile_values.h @@ -87,6 +87,8 @@ QString IDString(not_null peer); not_null user); [[nodiscard]] rpl::producer CanAddContactValue( not_null user); +[[nodiscard]] rpl::producer HasLinkedChatValue( + not_null channel); [[nodiscard]] rpl::producer AmInChannelValue( not_null channel); [[nodiscard]] rpl::producer MembersCountValue(not_null peer);