From dbb011fc560f4ba834a553edd76efd0f9c12c6d6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 10 Nov 2017 23:19:43 +0400 Subject: [PATCH] Add members link in info for channel admins. --- .../SourceFiles/history/history_widget.cpp | 6 +- Telegram/SourceFiles/info/info.style | 2 +- .../SourceFiles/info/info_wrap_widget.cpp | 2 +- .../info/profile/info_profile_actions.cpp | 68 +++++++++++++++++-- .../info/profile/info_profile_actions.h | 5 ++ .../profile/info_profile_inner_widget.cpp | 4 +- .../info/profile/info_profile_values.cpp | 14 +--- .../info/profile/info_profile_widget.h | 2 +- 8 files changed, 79 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 8e46127f31..bb900eb2cd 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -696,7 +696,8 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null cont | UpdateFlag::UserIsBlocked | UpdateFlag::AdminsChanged | UpdateFlag::MembersChanged - | UpdateFlag::UserOnlineChanged; + | UpdateFlag::UserOnlineChanged + | UpdateFlag::ChannelAmIn; subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) { if (update.peer == _peer) { if (update.flags & UpdateFlag::ChannelRightsChanged) { @@ -730,7 +731,8 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null cont if (update.flags & (UpdateFlag::UserIsBlocked | UpdateFlag::AdminsChanged | UpdateFlag::MembersChanged - | UpdateFlag::UserOnlineChanged)) { + | UpdateFlag::UserOnlineChanged + | UpdateFlag::ChannelAmIn)) { handlePeerUpdate(); } } diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 0a9dfd53d8..1f452824c5 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -321,7 +321,7 @@ infoNotificationsIconPosition: point(20px, 5px); infoSharedMediaIconPosition: point(20px, 24px); infoSharedMediaButtonIconPosition: point(20px, 3px); infoIconPosition: point(20px, 15px); - +infoChannelMembersIconPosition: point(20px, 24px); infoLabeledOneLine: FlatLabel(defaultFlatLabel) { maxHeight: 20px; style: TextStyle(defaultTextStyle) { diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index b0f607d30a..c0ea68dcbf 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -262,7 +262,7 @@ void WrapWidget::createTopBar() { } if (_controller->section().type() == Section::Type::Profile) { addProfileMenuButton(); - addProfileNotificationsButton(); +// addProfileNotificationsButton(); } _topBar->move(0, 0); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 837d72517f..75201be6c0 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -21,6 +21,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "info/profile/info_profile_actions.h" #include +#include +#include "data/data_peer_values.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/padding_wrap.h" #include "ui/wrap/slide_wrap.h" @@ -42,6 +44,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "info/profile/info_profile_text.h" #include "window/window_controller.h" #include "window/window_peer_menu.h" +#include "profile/profile_channel_controllers.h" #include "mainwidget.h" #include "auth_session.h" #include "messenger.h" @@ -557,8 +560,7 @@ void ActionsFiller::addLeaveChannelAction( _wrap, Lang::Viewer(lng_profile_leave_channel), AmInChannelValue(channel), - [channel] { Auth().api().leaveChannel(channel); }, - st::infoBlockButton); + [channel] { Auth().api().leaveChannel(channel); }); } void ActionsFiller::addJoinChannelAction( @@ -608,10 +610,10 @@ void ActionsFiller::fillChannelActions( using namespace rpl::mappers; addJoinChannelAction(channel); + addLeaveChannelAction(channel); if (!channel->amCreator()) { addReportAction(); } - addLeaveChannelAction(channel); } object_ptr ActionsFiller::fill() { @@ -631,11 +633,12 @@ object_ptr ActionsFiller::fill() { fillUserActions(user); }); } else if (auto channel = _peer->asChannel()) { - if (!channel->isMegagroup()) { - return wrapResult([=] { - fillChannelActions(channel); - }); + if (channel->isMegagroup()) { + return { nullptr }; } + return wrapResult([=] { + fillChannelActions(channel); + }); } return { nullptr }; } @@ -658,5 +661,56 @@ object_ptr SetupActions( return filler.fill(); } +object_ptr SetupChannelMembers( + not_null controller, + not_null parent, + not_null peer) { + using namespace rpl::mappers; + + auto channel = peer->asChannel(); + if (!channel || channel->isMegagroup()) { + return { nullptr }; + } + + auto membersShown = rpl::combine( + MembersCountValue(channel), + Data::PeerFullFlagValue( + channel, + MTPDchannelFull::Flag::f_can_view_participants), + ($1 > 0) && $2); + auto membersText = MembersCountValue(channel) + | rpl::map([](int count) { + return lng_chat_status_members(lt_count, count); + }); + auto membersCallback = [controller, channel] { + using Controller = ::Profile::ParticipantsBoxController; + Controller::Start( + controller->window(), + channel, + Controller::Role::Members); + }; + + auto result = object_ptr>( + parent, + object_ptr(parent)); + result->toggleOn(std::move(membersShown)); + + auto members = result->entity(); + members->add(object_ptr(members)); + members->add(CreateSkipWidget(members)); + AddActionButton( + members, + std::move(membersText), + rpl::single(true), + std::move(membersCallback)); + object_ptr( + members, + st::infoIconMembers, + st::infoChannelMembersIconPosition); + members->add(CreateSkipWidget(members)); + + return std::move(result); +} + } // namespace Profile } // namespace Info diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.h b/Telegram/SourceFiles/info/profile/info_profile_actions.h index 1310f7f244..e92b3ee1e3 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.h +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.h @@ -40,5 +40,10 @@ object_ptr SetupActions( not_null parent, not_null peer); +object_ptr SetupChannelMembers( + not_null controller, + not_null parent, + not_null peer); + } // namespace Profile } // namespace Info diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index dba56bc16c..caa808b128 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -102,8 +102,10 @@ object_ptr InnerWidget::setupContent( result->add(std::move(details)); } result->add(setupSharedMedia(result.data())); + if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) { + result->add(std::move(members)); + } result->add(object_ptr(result)); - if (auto actions = SetupActions(_controller, result.data(), _peer)) { result->add(std::move(actions)); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index e837089743..31423357f9 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -183,19 +183,11 @@ rpl::producer MembersCountValue( : 0; }); } else if (auto channel = peer->asChannel()) { - return rpl::combine( - Notify::PeerUpdateValue( + return Notify::PeerUpdateValue( channel, - Notify::PeerUpdate::Flag::MembersChanged), - Data::PeerFullFlagValue( - channel, - MTPDchannelFull::Flag::f_can_view_participants)) + Notify::PeerUpdate::Flag::MembersChanged) | rpl::map([channel] { - auto canViewCount = channel->canViewMembers() - || !channel->isMegagroup(); - return canViewCount - ? qMax(channel->membersCount(), 1) - : 0; + return channel->membersCount(); }); } Unexpected("User in MembersCountViewer()."); diff --git a/Telegram/SourceFiles/info/profile/info_profile_widget.h b/Telegram/SourceFiles/info/profile/info_profile_widget.h index 2b7e883844..4cb56d4a12 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_widget.h +++ b/Telegram/SourceFiles/info/profile/info_profile_widget.h @@ -63,7 +63,7 @@ public: } private: - bool _infoExpanded = false; + bool _infoExpanded = true; base::optional _membersSearch; std::unique_ptr _membersState;