2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-29 05:37:45 +00:00

Show admin titles in member list

This commit is contained in:
RadRussianRus 2019-10-06 09:00:19 +03:00
parent 6e9ab9aea9
commit edd9d74c04
10 changed files with 80 additions and 27 deletions

View File

@ -463,6 +463,18 @@ void PeerListRow::addRipple(const style::PeerListItem &st, QSize size, QPoint po
_ripple->add(point); _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() { void PeerListRow::stopLastRipple() {
if (_ripple) { if (_ripple) {
_ripple->lastStop(); _ripple->lastStop();
@ -1163,6 +1175,22 @@ crl::time PeerListContent::paintRow(Painter &p, crl::time ms, RowIndex index) {
width(), width(),
selected); 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(); auto nameCheckedRatio = row->disabled() ? 0. : row->checkedRatio();
p.setPen(anim::pen(st::contactsNameFg, st::contactsNameCheckedFg, nameCheckedRatio)); p.setPen(anim::pen(st::contactsNameFg, st::contactsNameCheckedFg, nameCheckedRatio));
name.drawLeftElided(p, namex, _st.item.namePosition.y(), namew, width()); name.drawLeftElided(p, namex, _st.item.namePosition.y(), namew, width());

View File

@ -84,6 +84,14 @@ public:
int y, int y,
int outerWidth, int outerWidth,
bool selected); bool selected);
virtual int adminRankWidth() const;
virtual void paintAdminRank(
Painter &p,
int x,
int y,
int outerWidth,
bool selected);
virtual QSize actionSize() const { virtual QSize actionSize() const {
return QSize(); return QSize();
} }

View File

@ -1798,6 +1798,9 @@ auto ParticipantsBoxController::computeType(
? Rights::Admin ? Rights::Admin
: Rights::Normal; : Rights::Normal;
result.canRemove = _additional.canRestrictUser(user); result.canRemove = _additional.canRestrictUser(user);
if (const auto channel = _peer->asChannel()) {
result.adminRank = channel->adminRank(user);
}
return result; return result;
} }

View File

@ -340,6 +340,26 @@ bool ChannelData::isGroupAdmin(not_null<UserData*> user) const {
return false; return false;
} }
QString ChannelData::adminRank(not_null<UserData*> 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 { QString ChannelData::unavailableReason() const {
return _unavailableReason; return _unavailableReason;
} }

View File

@ -219,6 +219,7 @@ public:
void markForbidden(); void markForbidden();
[[nodiscard]] bool isGroupAdmin(not_null<UserData*> user) const; [[nodiscard]] bool isGroupAdmin(not_null<UserData*> user) const;
[[nodiscard]] QString adminRank(not_null<UserData*> user) const;
[[nodiscard]] bool lastParticipantsCountOutdated() const { [[nodiscard]] bool lastParticipantsCountOutdated() const {
if (!mgInfo if (!mgInfo

View File

@ -63,34 +63,21 @@ void MemberListRow::paintAction(
} }
} }
int MemberListRow::nameIconWidth() const { int MemberListRow::adminRankWidth() const {
return (_type.rights == Rights::Admin) return st::normalFont->width(_type.adminRank);
? st::infoMembersAdminIcon.width()
: (_type.rights == Rights::Creator)
? st::infoMembersCreatorIcon.width()
: 0;
} }
not_null<UserData*> MemberListRow::user() const { not_null<UserData*> MemberListRow::user() const {
return peer()->asUser(); return peer()->asUser();
} }
void MemberListRow::paintNameIcon( void MemberListRow::paintAdminRank(
Painter &p, Painter &p,
int x, int x,
int y, int y,
int outerWidth, int outerWidth,
bool selected) { bool selected) {
auto icon = [&] { p.drawTextLeft(x, y, outerWidth, _type.adminRank, adminRankWidth());
return (_type.rights == Rights::Admin)
? (selected
? &st::infoMembersAdminIconOver
: &st::infoMembersAdminIcon)
: (selected
? &st::infoMembersCreatorIconOver
: &st::infoMembersCreatorIcon);
}();
icon->paint(p, x, y, outerWidth);
} }
std::unique_ptr<PeerListController> CreateMembersController( std::unique_ptr<PeerListController> CreateMembersController(

View File

@ -26,6 +26,7 @@ public:
struct Type { struct Type {
Rights rights; Rights rights;
bool canRemove = false; bool canRemove = false;
QString adminRank;
}; };
MemberListRow(not_null<UserData*> user, Type type); MemberListRow(not_null<UserData*> user, Type type);
@ -39,8 +40,8 @@ public:
int outerWidth, int outerWidth,
bool selected, bool selected,
bool actionSelected) override; bool actionSelected) override;
int nameIconWidth() const override; int adminRankWidth() const override;
void paintNameIcon( void paintAdminRank(
Painter &p, Painter &p,
int x, int x,
int y, int y,

View File

@ -297,6 +297,10 @@ void GroupMembersWidget::setItemFlags(
? AdminState::Admin ? AdminState::Admin
: AdminState::None; : AdminState::None;
item->adminState = adminState; 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()) { if (item->peer->id == chat->session().userPeerId()) {
item->hasRemoveLink = false; item->hasRemoveLink = false;
} else if (chat->amCreator() } else if (chat->amCreator()
@ -399,6 +403,8 @@ void GroupMembersWidget::setItemFlags(
updateItemStatusText(item); updateItemStatusText(item);
} }
} }
item->adminRank = megagroup->adminRank(item->peer->asUser());
item->adminRankWidth = st::normalFont->width(item->adminRank);
if (item->peer->isSelf()) { if (item->peer->isSelf()) {
item->hasRemoveLink = false; item->hasRemoveLink = false;
} else if (megagroup->amCreator() || (megagroup->canBanMembers() && ((adminState == AdminState::None) || adminCanEdit))) { } else if (megagroup->amCreator() || (megagroup->canBanMembers() && ((adminState == AdminState::None) || adminCanEdit))) {

View File

@ -100,14 +100,11 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select
p.setPen(st::windowActiveTextFg); p.setPen(st::windowActiveTextFg);
p.drawTextLeft(nameLeft + nameWidth - _removeWidth, nameTop, width(), _removeText, _removeWidth); p.drawTextLeft(nameLeft + nameWidth - _removeWidth, nameTop, width(), _removeText, _removeWidth);
nameWidth -= _removeWidth + skip; nameWidth -= _removeWidth + skip;
} } else if (item->adminState != Item::AdminState::None) {
if (item->adminState != Item::AdminState::None) { p.setFont(st::normalFont);
nameWidth -= st::profileMemberAdminIcon.width(); p.setPen(selected ? _st.statusFgOver : _st.statusFg);
auto iconLeft = nameLeft + qMin(nameWidth, item->name.maxWidth()); p.drawTextLeft(nameLeft + nameWidth - item->adminRankWidth, nameTop, width(), item->adminRank, item->adminRankWidth);
auto &icon = (item->adminState == Item::AdminState::Creator) nameWidth -= item->adminRankWidth + skip;
? (selected ? st::profileMemberCreatorIconOver : st::profileMemberCreatorIcon)
: (selected ? st::profileMemberAdminIconOver : st::profileMemberAdminIcon);
icon.paint(p, QPoint(iconLeft, nameTop), width());
} }
p.setPen(st::profileMemberNameFg); p.setPen(st::profileMemberNameFg);
item->name.drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); item->name.drawLeftElided(p, nameLeft, nameTop, nameWidth, width());

View File

@ -42,6 +42,8 @@ public:
Creator, Creator,
}; };
AdminState adminState = AdminState::None; AdminState adminState = AdminState::None;
QString adminRank;
int adminRankWidth = 0;
bool hasRemoveLink = false; bool hasRemoveLink = false;
std::unique_ptr<Ui::RippleAnimation> ripple; std::unique_ptr<Ui::RippleAnimation> ripple;
}; };