From f439443fe58104a1cbd45127731cb46c51aa2c48 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 29 Mar 2024 12:01:34 +0400 Subject: [PATCH] Show personal channel in users profile. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/info/info.style | 2 + .../info/profile/info_profile_actions.cpp | 71 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0f8f971f12..83b3546102 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1330,6 +1330,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_via_link_shared_many#one" = "Link shared with **{count} user**."; "lng_via_link_shared_many#other" = "Link shared with **{count} users**."; +"lng_info_personal_channel_label" = "Channel"; "lng_info_mobile_label" = "Mobile"; "lng_info_mobile_context_menu_fragment_about" = "This number is not tied to a SIM card and was acquired on {link}."; "lng_info_mobile_context_menu_fragment_about_link" = "Fragment"; diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 19162c4000..d59de8526b 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -446,6 +446,8 @@ infoSharedMediaButtonIconPosition: point(20px, 3px); infoGroupMembersIconPosition: point(20px, 10px); infoChannelMembersIconPosition: point(20px, 19px); +infoPersonalChannelIconPosition: point(25px, 20px); + infoBlockHeaderLabel: FlatLabel(infoProfileStatus) { textFg: windowBoldFg; style: TextStyle(defaultTextStyle) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 25fc17c346..1f5e23a1a8 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -661,6 +661,7 @@ public: object_ptr fill(); private: + object_ptr setupPersonalChannel(not_null user); object_ptr setupInfo(); object_ptr setupMuteToggle(); void setupMainButtons(); @@ -1115,6 +1116,73 @@ object_ptr DetailsFiller::setupInfo() { return result; } +object_ptr DetailsFiller::setupPersonalChannel( + not_null user) { + auto result = object_ptr>( + _wrap, + object_ptr(_wrap)); + const auto container = result->entity(); + + result->toggleOn(PersonalChannelValue( + user + ) | rpl::map(rpl::mappers::_1 != nullptr)); + result->finishAnimating(); + + Ui::AddDivider(container); + + auto channel = PersonalChannelValue( + user + ) | rpl::start_spawning(result->lifetime()); + auto text = rpl::duplicate( + channel + ) | rpl::map([=](ChannelData *channel) { + return channel ? NameValue(channel) : rpl::single(QString()); + }) | rpl::flatten_latest() | rpl::map([](const QString &name) { + return name.isEmpty() ? TextWithEntities() : Ui::Text::Link(name); + }); + auto label = rpl::combine( + tr::lng_info_personal_channel_label(Ui::Text::WithEntities), + rpl::duplicate(channel) + ) | rpl::map([](TextWithEntities &&text, ChannelData *channel) { + const auto count = channel ? channel->membersCount() : 0; + if (count > 1) { + text.append( + QString::fromUtf8(" \xE2\x80\xA2 ") + ).append(tr::lng_chat_status_subscribers( + tr::now, + lt_count_decimal, + count)); + } + return text; + }); + auto line = CreateTextWithLabel( + result, + std::move(label), + std::move(text), + st::infoLabel, + st::infoLabeled, + st::infoProfileLabeledPadding); + container->add(std::move(line.wrap)); + + line.text->setClickHandlerFilter([ + =, + window = _controller->parentController()]( + const ClickHandlerPtr &handler, + Qt::MouseButton button) { + if (const auto channelId = user->personalChannelId()) { + window->showPeerInfo(peerFromChannel(channelId)); + } + return false; + }); + + object_ptr( + result, + st::infoIconMediaChannel, + st::infoPersonalChannelIconPosition); + + return result; +} + object_ptr DetailsFiller::setupMuteToggle() { const auto peer = _peer; const auto topicRootId = _topic ? _topic->rootId() : MsgId(); @@ -1349,6 +1417,9 @@ Ui::MultiSlideTracker DetailsFiller::fillChannelButtons( object_ptr DetailsFiller::fill() { Expects(!_topic || !_topic->creating()); + if (const auto user = _peer->asUser()) { + add(setupPersonalChannel(user)); + } add(object_ptr(_wrap)); add(CreateSkipWidget(_wrap)); add(setupInfo());