From d7bf9e285c47b2df7043e9de768186d3d150a276 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 29 Mar 2022 19:43:33 +0300 Subject: [PATCH] Replaced kick button with admin rank in list of members. --- .../SourceFiles/boxes/peer_list_controllers.h | 6 ++- .../boxes/peers/edit_participants_box.cpp | 3 +- .../info_profile_members_controllers.cpp | 45 ++++++++++++------- .../info_profile_members_controllers.h | 11 ++--- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.h b/Telegram/SourceFiles/boxes/peer_list_controllers.h index 21d0043c9..3422c5ad6 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.h +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.h @@ -46,8 +46,7 @@ public: void lazyInitialize(const style::PeerListItem &st) override; -private: - void refreshActionLink(); +protected: QSize rightActionSize() const override; QMargins rightActionMargins() const override; void rightActionPaint( @@ -58,6 +57,9 @@ private: bool selected, bool actionSelected) override; +private: + void refreshActionLink(); + QString _action; int _actionWidth = 0; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 10c997f85..ff2a36f7e 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1930,7 +1930,8 @@ auto ParticipantsBoxController::computeType( : (user && _additional.adminRights(user).has_value()) ? Rights::Admin : Rights::Normal; - result.canRemove = _additional.canRemoveParticipant(participant); + // result.canRemove = _additional.canRemoveParticipant(participant); + result.adminRank = user ? _additional.adminRank(user) : QString(); return result; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp index 435236ed0..74f5f86ff 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp @@ -7,21 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/profile/info_profile_members_controllers.h" -#include -#include "base/weak_ptr.h" #include "boxes/peers/edit_participants_box.h" -#include "ui/widgets/popup_menu.h" -#include "lang/lang_keys.h" -#include "apiwrap.h" -#include "main/main_session.h" -#include "mainwidget.h" -#include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" -#include "ui/boxes/confirm_box.h" -#include "window/window_session_controller.h" +#include "lang/lang_keys.h" #include "styles/style_info.h" -#include "data/data_peer_values.h" namespace Info { namespace Profile { @@ -29,12 +19,18 @@ namespace Profile { MemberListRow::MemberListRow( not_null user, Type type) -: PeerListRow(user) +: PeerListRowWithLink(user) , _type(type) { + PeerListRowWithLink::setActionLink(_type.adminRank); } void MemberListRow::setType(Type type) { _type = type; + PeerListRowWithLink::setActionLink(_type.adminRank); +} + +bool MemberListRow::rightActionDisabled() const { + return !canRemove(); } QSize MemberListRow::rightActionSize() const { @@ -43,7 +39,7 @@ QSize MemberListRow::rightActionSize() const { QPoint(), st::infoMembersRemoveIcon.size()).marginsAdded( st::infoMembersRemoveIconMargins).size() - : QSize(); + : PeerListRowWithLink::rightActionSize(); } void MemberListRow::rightActionPaint( @@ -59,9 +55,23 @@ void MemberListRow::rightActionPaint( (actionSelected ? st::infoMembersRemoveIconOver : st::infoMembersRemoveIcon).paint(p, x, y, outerWidth); + } else { + PeerListRowWithLink::rightActionPaint( + p, + x, + y, + outerWidth, + selected, + actionSelected); } } +QMargins MemberListRow::rightActionMargins() const { + return canRemove() + ? QMargins() + : PeerListRowWithLink::rightActionMargins(); +} + int MemberListRow::nameIconWidth() const { return (_type.rights == Rights::Admin) ? st::infoMembersAdminIcon.width() @@ -80,7 +90,7 @@ void MemberListRow::paintNameIcon( int y, int outerWidth, bool selected) { - auto icon = [&] { + const auto icon = [&] { return (_type.rights == Rights::Admin) ? (selected ? &st::infoMembersAdminIconOver @@ -94,7 +104,8 @@ void MemberListRow::paintNameIcon( void MemberListRow::refreshStatus() { if (user()->isBot()) { - auto seesAllMessages = (user()->botInfo->readsAllHistory || _type.rights != Rights::Normal); + const auto seesAllMessages = (user()->botInfo->readsAllHistory + || _type.rights != Rights::Normal); setCustomStatus(seesAllMessages ? tr::lng_status_bot_reads_all(tr::now) : tr::lng_status_bot_not_reads_all(tr::now)); @@ -103,6 +114,10 @@ void MemberListRow::refreshStatus() { } } +bool MemberListRow::canRemove() const { + return _type.canRemove; +} + std::unique_ptr CreateMembersController( not_null navigation, not_null peer) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h index d081e559a..cc2607df6 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "boxes/peer_list_box.h" +#include "boxes/peer_list_controllers.h" namespace Window { class SessionNavigation; @@ -16,7 +16,7 @@ class SessionNavigation; namespace Info { namespace Profile { -class MemberListRow final : public PeerListRow { +class MemberListRow final : public PeerListRowWithLink { public: enum class Rights { Normal, @@ -26,11 +26,14 @@ public: struct Type { Rights rights; bool canRemove = false; + QString adminRank; }; MemberListRow(not_null user, Type type); void setType(Type type); + bool rightActionDisabled() const override; + QMargins rightActionMargins() const override; QSize rightActionSize() const override; void rightActionPaint( Painter &p, @@ -49,11 +52,9 @@ public: void refreshStatus() override; not_null user() const; - bool canRemove() const { - return _type.canRemove; - } private: + [[nodiscard]] bool canRemove() const; Type _type; };