From fae9b40555653da2db1ac00a1f8f29dce4ee2781 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 24 Jul 2020 06:10:52 +0300 Subject: [PATCH] Show admin icon for groups and channels with creator/admin rights --- Telegram/SourceFiles/boxes/peer_list_box.cpp | 71 +++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 45b7bf381..296fb7f10 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" #include "styles/style_dialogs.h" #include "styles/style_widgets.h" +#include "styles/style_info.h" #include @@ -523,9 +524,37 @@ void PeerListRow::invalidatePixmapsCache() { } int PeerListRow::nameIconWidth() const { - return (special() || !_peer->isVerified()) + if (special()) { + return 0; + } + auto hasCreatorRights = false; + auto hasAdminRights = false; + if (const auto chat = _peer->asChat()) { + if (chat->amCreator()) { + hasCreatorRights = true; + hasAdminRights = true; + } else if (chat->hasAdminRights()) { + hasAdminRights = true; + } + } else if (const auto channel = _peer->asChannel()) { + if (channel->amCreator()) { + hasCreatorRights = true; + hasAdminRights = true; + } else if (channel->hasAdminRights()) { + hasAdminRights = true; + } + } + + return special() ? 0 - : st::dialogsVerifiedIcon.width(); + : (_peer->isVerified() + ? st::dialogsVerifiedIcon.width() + : 0) + + (hasCreatorRights + ? st::infoMembersCreatorIcon.width() + : hasAdminRights + ? st::infoMembersAdminIcon.width() + : 0); } void PeerListRow::paintNameIcon( @@ -534,7 +563,43 @@ void PeerListRow::paintNameIcon( int y, int outerWidth, bool selected) { - st::dialogsVerifiedIcon.paint(p, x, y, outerWidth); + if (special()) { + return; + } + + auto hasCreatorRights = false; + auto hasAdminRights = false; + if (const auto chat = _peer->asChat()) { + if (chat->amCreator()) { + hasCreatorRights = true; + hasAdminRights = true; + } else if (chat->hasAdminRights()) { + hasAdminRights = true; + } + } else if (const auto channel = _peer->asChannel()) { + if (channel->amCreator()) { + hasCreatorRights = true; + hasAdminRights = true; + } else if (channel->hasAdminRights()) { + hasAdminRights = true; + } + } + + auto icon = [&] { + return hasCreatorRights + ? (selected + ? &st::infoMembersCreatorIconOver + : &st::infoMembersCreatorIcon) + : (selected + ? &st::infoMembersAdminIconOver + : &st::infoMembersAdminIcon); + }(); + if (_peer->isVerified()) { + st::dialogsVerifiedIcon.paint(p, x, y, outerWidth); + } + if (hasAdminRights) { + icon->paint(p, x + (_peer->isVerified() ? st::dialogsVerifiedIcon.width() : 0 ), y, outerWidth); + } } void PeerListRow::paintStatusText(