diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 4835bf039..08202d713 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -463,6 +463,18 @@ void PeerListRow::addRipple(const style::PeerListItem &st, QSize size, QPoint po _ripple->add(point); } +int PeerListRow::adminRankWidth() const { + return 0; +} + +void PeerListRow::paintAdminRank( + Painter &p, + int x, + int y, + int outerWidth, + bool selected) { +} + void PeerListRow::stopLastRipple() { if (_ripple) { _ripple->lastStop(); @@ -1163,6 +1175,22 @@ crl::time PeerListContent::paintRow(Painter &p, crl::time ms, RowIndex index) { width(), selected); } + if (auto adminRankWidth = row->adminRankWidth()) { + namew -= adminRankWidth; + auto rankx = width() - adminRankWidth - skipRight; + if (!actionSize.isEmpty() && selected) { + namew -= skipRight; + rankx -= skipRight; + } + p.setFont(st::normalFont); + p.setPen(selected ? _st.item.statusFgOver : _st.item.statusFg); + row->paintAdminRank( + p, + rankx, + _st.item.namePosition.y(), + width(), + selected); + } auto nameCheckedRatio = row->disabled() ? 0. : row->checkedRatio(); p.setPen(anim::pen(st::contactsNameFg, st::contactsNameCheckedFg, nameCheckedRatio)); name.drawLeftElided(p, namex, _st.item.namePosition.y(), namew, width()); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index ceced9760..636e789d8 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -84,6 +84,14 @@ public: int y, int outerWidth, bool selected); + virtual int adminRankWidth() const; + virtual void paintAdminRank( + Painter &p, + int x, + int y, + int outerWidth, + bool selected); + virtual QSize actionSize() const { return QSize(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 17d408d34..60cb74800 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1798,6 +1798,9 @@ auto ParticipantsBoxController::computeType( ? Rights::Admin : Rights::Normal; result.canRemove = _additional.canRestrictUser(user); + if (const auto channel = _peer->asChannel()) { + result.adminRank = channel->adminRank(user); + } return result; } diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 8cac56980..e72cf0ff0 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -340,6 +340,26 @@ bool ChannelData::isGroupAdmin(not_null user) const { return false; } +QString ChannelData::adminRank(not_null user) const { + if (!isGroupAdmin(user)) { + return QString(); + } + const auto info = mgInfo.get(); + const auto i = mgInfo->admins.find(peerToUser(user->id)); + const auto custom = (i != mgInfo->admins.end()) + ? i->second + : (info->creator == user) + ? info->creatorRank + : QString(); + return !custom.isEmpty() + ? custom + : (info->creator == user) + ? tr::lng_owner_badge(tr::now) + : (i != mgInfo->admins.end()) + ? tr::lng_admin_badge(tr::now) + : QString(); +} + QString ChannelData::unavailableReason() const { return _unavailableReason; } diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index df8adf4e7..855cc03a7 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -219,6 +219,7 @@ public: void markForbidden(); [[nodiscard]] bool isGroupAdmin(not_null user) const; + [[nodiscard]] QString adminRank(not_null user) const; [[nodiscard]] bool lastParticipantsCountOutdated() const { if (!mgInfo diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp index b47065e73..26f25f6a1 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp @@ -63,34 +63,21 @@ void MemberListRow::paintAction( } } -int MemberListRow::nameIconWidth() const { - return (_type.rights == Rights::Admin) - ? st::infoMembersAdminIcon.width() - : (_type.rights == Rights::Creator) - ? st::infoMembersCreatorIcon.width() - : 0; +int MemberListRow::adminRankWidth() const { + return st::normalFont->width(_type.adminRank); } not_null MemberListRow::user() const { return peer()->asUser(); } -void MemberListRow::paintNameIcon( +void MemberListRow::paintAdminRank( Painter &p, int x, int y, int outerWidth, bool selected) { - auto icon = [&] { - return (_type.rights == Rights::Admin) - ? (selected - ? &st::infoMembersAdminIconOver - : &st::infoMembersAdminIcon) - : (selected - ? &st::infoMembersCreatorIconOver - : &st::infoMembersCreatorIcon); - }(); - icon->paint(p, x, y, outerWidth); + p.drawTextLeft(x, y, outerWidth, _type.adminRank, adminRankWidth()); } std::unique_ptr CreateMembersController( diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h index 70179be19..2db859794 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h @@ -26,6 +26,7 @@ public: struct Type { Rights rights; bool canRemove = false; + QString adminRank; }; MemberListRow(not_null user, Type type); @@ -39,8 +40,8 @@ public: int outerWidth, bool selected, bool actionSelected) override; - int nameIconWidth() const override; - void paintNameIcon( + int adminRankWidth() const override; + void paintAdminRank( Painter &p, int x, int y, diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index 15199b13c..7b0149eb1 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -297,6 +297,10 @@ void GroupMembersWidget::setItemFlags( ? AdminState::Admin : AdminState::None; item->adminState = adminState; + if (isCreator) { + item->adminRank = tr::lng_owner_badge(tr::now); + item->adminRankWidth = st::normalFont->width(item->adminRank); + } if (item->peer->id == chat->session().userPeerId()) { item->hasRemoveLink = false; } else if (chat->amCreator() @@ -399,6 +403,8 @@ void GroupMembersWidget::setItemFlags( updateItemStatusText(item); } } + item->adminRank = megagroup->adminRank(item->peer->asUser()); + item->adminRankWidth = st::normalFont->width(item->adminRank); if (item->peer->isSelf()) { item->hasRemoveLink = false; } else if (megagroup->amCreator() || (megagroup->canBanMembers() && ((adminState == AdminState::None) || adminCanEdit))) { diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index a0545df1d..6848f6360 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -100,14 +100,11 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select p.setPen(st::windowActiveTextFg); p.drawTextLeft(nameLeft + nameWidth - _removeWidth, nameTop, width(), _removeText, _removeWidth); nameWidth -= _removeWidth + skip; - } - if (item->adminState != Item::AdminState::None) { - nameWidth -= st::profileMemberAdminIcon.width(); - auto iconLeft = nameLeft + qMin(nameWidth, item->name.maxWidth()); - auto &icon = (item->adminState == Item::AdminState::Creator) - ? (selected ? st::profileMemberCreatorIconOver : st::profileMemberCreatorIcon) - : (selected ? st::profileMemberAdminIconOver : st::profileMemberAdminIcon); - icon.paint(p, QPoint(iconLeft, nameTop), width()); + } else if (item->adminState != Item::AdminState::None) { + p.setFont(st::normalFont); + p.setPen(selected ? _st.statusFgOver : _st.statusFg); + p.drawTextLeft(nameLeft + nameWidth - item->adminRankWidth, nameTop, width(), item->adminRank, item->adminRankWidth); + nameWidth -= item->adminRankWidth + skip; } p.setPen(st::profileMemberNameFg); item->name.drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.h b/Telegram/SourceFiles/profile/profile_block_peer_list.h index 3d95a9f67..4d750d382 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.h +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.h @@ -42,6 +42,8 @@ public: Creator, }; AdminState adminState = AdminState::None; + QString adminRank; + int adminRankWidth = 0; bool hasRemoveLink = false; std::unique_ptr ripple; };