mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-28 21:27:53 +00:00
Show admin titles in member list
This commit is contained in:
parent
6e9ab9aea9
commit
edd9d74c04
@ -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());
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -340,6 +340,26 @@ bool ChannelData::isGroupAdmin(not_null<UserData*> user) const {
|
||||
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 {
|
||||
return _unavailableReason;
|
||||
}
|
||||
|
@ -219,6 +219,7 @@ public:
|
||||
void markForbidden();
|
||||
|
||||
[[nodiscard]] bool isGroupAdmin(not_null<UserData*> user) const;
|
||||
[[nodiscard]] QString adminRank(not_null<UserData*> user) const;
|
||||
|
||||
[[nodiscard]] bool lastParticipantsCountOutdated() const {
|
||||
if (!mgInfo
|
||||
|
@ -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<UserData*> 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<PeerListController> CreateMembersController(
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
struct Type {
|
||||
Rights rights;
|
||||
bool canRemove = false;
|
||||
QString adminRank;
|
||||
};
|
||||
|
||||
MemberListRow(not_null<UserData*> 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,
|
||||
|
@ -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))) {
|
||||
|
@ -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());
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
Creator,
|
||||
};
|
||||
AdminState adminState = AdminState::None;
|
||||
QString adminRank;
|
||||
int adminRankWidth = 0;
|
||||
bool hasRemoveLink = false;
|
||||
std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user