From 3cb0be5be58c1bb06c7f4f766d87675ef6679427 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 4 Oct 2024 08:55:46 +0300 Subject: [PATCH] Added administrators button to profile section of owned channels. --- Telegram/Resources/langs/lang.strings | 2 + Telegram/SourceFiles/info/info.style | 3 +- .../info/profile/info_profile_actions.cpp | 90 +++++++++++++++---- .../info/profile/info_profile_actions.h | 2 +- .../profile/info_profile_inner_widget.cpp | 10 ++- 5 files changed, 84 insertions(+), 23 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d4cd32e52..52fd1c48e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1379,6 +1379,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_profile_copy_fullname" = "Copy Name"; "lng_profile_photo_by_you" = "photo set by you"; "lng_profile_public_photo" = "public photo"; +"lng_profile_administrators#one" = "{count} administrator"; +"lng_profile_administrators#other" = "{count} administrators"; "lng_invite_upgrade_title" = "Upgrade to Premium"; "lng_invite_upgrade_group_invite#one" = "{users} only accepts invitations to groups from Contacts and **Premium** users."; diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index fb096b94c..0c66b41a7 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -488,7 +488,8 @@ infoInformationIconPosition: point(25px, 12px); infoNotificationsIconPosition: point(20px, 5px); infoSharedMediaButtonIconPosition: point(20px, 3px); infoGroupMembersIconPosition: point(20px, 10px); -infoChannelMembersIconPosition: point(20px, 19px); +infoChannelMembersIconPosition: point(20px, 4px); +infoChannelAdminsIconPosition: point(24px, 7px); infoOpenApp: RoundButton(defaultActiveButton) { textTop: 11px; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 3e016c0a3..da41978b9 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "boxes/peers/add_bot_to_chat_box.h" #include "boxes/peers/edit_contact_box.h" +#include "boxes/peers/edit_participants_box.h" #include "boxes/report_messages_box.h" #include "boxes/share_box.h" #include "boxes/star_gift_box.h" @@ -2243,7 +2244,7 @@ void SetupAddChannelMember( }, add->lifetime()); } -object_ptr SetupChannelMembers( +object_ptr SetupChannelMembersAndManage( not_null controller, not_null parent, not_null peer) { @@ -2254,6 +2255,12 @@ object_ptr SetupChannelMembers( return { nullptr }; } + auto result = object_ptr>( + parent, + object_ptr(parent)); + result->entity()->add(object_ptr(result)); + result->entity()->add(CreateSkipWidget(result)); + auto membersShown = rpl::combine( MembersCountValue(channel), Data::PeerFlagValue( @@ -2269,32 +2276,77 @@ object_ptr SetupChannelMembers( Section::Type::Members)); }; - auto result = object_ptr>( - parent, - object_ptr(parent)); - result->setDuration( + const auto membersWrap = result->entity()->add( + object_ptr>( + result->entity(), + object_ptr(result->entity()))); + membersWrap->setDuration( st::infoSlideDuration - )->toggleOn( - std::move(membersShown) - ); + )->toggleOn(rpl::duplicate(membersShown)); - auto members = result->entity(); - members->add(object_ptr(members)); - members->add(CreateSkipWidget(members)); - auto button = AddActionButton( - members, - std::move(membersText), - rpl::single(true), - std::move(membersCallback), - nullptr)->entity(); + const auto members = membersWrap->entity(); + { + auto button = AddActionButton( + members, + std::move(membersText), + rpl::single(true), + std::move(membersCallback), + nullptr)->entity(); - SetupAddChannelMember(controller, button, channel); + SetupAddChannelMember(controller, button, channel); + } object_ptr( members, st::infoIconMembers, st::infoChannelMembersIconPosition); - members->add(CreateSkipWidget(members)); + + auto adminsShown = peer->session().changes().peerFlagsValue( + channel, + Data::PeerUpdate::Flag::Rights + ) | rpl::map([=] { return channel->canViewAdmins(); }); + auto adminsText = tr::lng_profile_administrators( + lt_count_decimal, + Info::Profile::MigratedOrMeValue( + channel + ) | rpl::map( + Info::Profile::AdminsCountValue + ) | rpl::flatten_latest() | tr::to_count()); + auto adminsCallback = [=] { + ParticipantsBoxController::Start( + controller, + channel, + ParticipantsBoxController::Role::Admins); + }; + + const auto adminsWrap = result->entity()->add( + object_ptr>( + result->entity(), + object_ptr(result->entity()))); + adminsWrap->setDuration( + st::infoSlideDuration + )->toggleOn(rpl::duplicate(adminsShown)); + + const auto admins = adminsWrap->entity(); + AddActionButton( + admins, + std::move(adminsText), + rpl::single(true), + std::move(adminsCallback), + nullptr); + + object_ptr( + admins, + st::menuIconAdmin, + st::infoChannelAdminsIconPosition); + + result->setDuration(st::infoSlideDuration)->toggleOn( + rpl::combine( + std::move(membersShown), + std::move(adminsShown) + ) | rpl::map(rpl::mappers::_1 || rpl::mappers::_2)); + + result->entity()->add(CreateSkipWidget(result)); return result; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.h b/Telegram/SourceFiles/info/profile/info_profile_actions.h index d31714a82..c6b070a85 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.h +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.h @@ -43,7 +43,7 @@ object_ptr SetupActions( not_null parent, not_null peer); -object_ptr SetupChannelMembers( +object_ptr SetupChannelMembersAndManage( not_null controller, not_null parent, not_null peer); diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index c0ea78d2a..be2a2bb29 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -113,8 +113,14 @@ object_ptr InnerWidget::setupContent( if (_topic) { return result; } - if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) { - result->add(std::move(members)); + { + auto buttons = SetupChannelMembersAndManage( + _controller, + result.data(), + _peer); + if (buttons) { + result->add(std::move(buttons)); + } } if (auto actions = SetupActions(_controller, result.data(), _peer)) { result->add(object_ptr(result));