2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 06:07:45 +00:00

Fix admin ranks in admin list

This commit is contained in:
RadRussianRus 2021-12-30 10:00:20 +03:00
parent 89fdd00284
commit fe4dddea36
3 changed files with 41 additions and 6 deletions

View File

@ -172,7 +172,7 @@ void PeerListRowWithLink::rightActionPaint(
int outerWidth,
bool selected,
bool actionSelected) {
if (!_action.isEmpty() && (_actionPlaceholder.isEmpty() || selected)) {
if (!_action.isEmpty() && ((_actionPlaceholder.isEmpty() && _adminRank.isEmpty()) || selected)) {
p.setFont(actionSelected ? st::linkOverFont : st::linkFont);
p.setPen(actionSelected ? st::defaultLinkButton.overColor : st::defaultLinkButton.color);
p.drawTextLeft(x, y, outerWidth, _action, _actionWidth);
@ -187,6 +187,32 @@ void PeerListRowWithLink::rightActionPaint(
}
}
void PeerListRowWithLink::setAdminRank(const QString &rank, bool isCreator) {
_adminRank = rank;
_isCreator = isCreator;
}
int PeerListRowWithLink::adminRankWidth() const {
return st::normalFont->width(_adminRank);
}
void PeerListRowWithLink::paintAdminRank(
Painter &p,
int x,
int y,
int outerWidth,
bool selected) {
if (hasAction() && selected) {
return;
}
p.setPen(_isCreator
? st::defaultPeerListItem.statusFgActive
: selected
? st::defaultPeerListItem.statusFgOver
: st::defaultPeerListItem.statusFg);
p.drawTextLeft(x, y, outerWidth, _adminRank, adminRankWidth());
}
PeerListGlobalSearchController::PeerListGlobalSearchController(
not_null<Main::Session*> session)
: _session(session)

View File

@ -47,6 +47,15 @@ public:
void lazyInitialize(const style::PeerListItem &st) override;
bool hasAction() override;
void setAdminRank(const QString &rank, bool isCreator = false);
int adminRankWidth() const override;
void paintAdminRank(
Painter &p,
int x,
int y,
int outerWidth,
bool selected) override;
private:
void refreshActionLink();
QSize rightActionSize() const override;
@ -66,6 +75,8 @@ private:
int _actionWidth = 0;
int _actionPlaceholderWidth = 0;
QString _adminRank;
bool _isCreator = false;
};
class PeerListGlobalSearchController : public PeerListSearchController {

View File

@ -1917,7 +1917,7 @@ std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(
if (_additional.canEditAdmin(user) && !_additional.isCreator(user)) {
row->setActionLink(tr::lng_profile_kick(tr::now));
}
row->setActionPlaceholder(channel
row->setAdminRank(channel
? channel->adminRank(user)
: (chat && _additional.isCreator(user))
? tr::lng_owner_badge(tr::now)
@ -1976,9 +1976,8 @@ void ParticipantsBoxController::recomputeTypeFor(
void ParticipantsBoxController::refreshCustomStatus(
not_null<PeerListRow*> row) const {
const auto participant = row->peer();
// const auto user = participant->asUser();
/* const auto user = participant->asUser();
if (_role == Role::Admins) {
/*
Assert(user != nullptr);
if (const auto by = _additional.adminPromotedBy(user)) {
row->setCustomStatus(tr::lng_channel_admin_status_promoted_by(
@ -1994,8 +1993,7 @@ void ParticipantsBoxController::refreshCustomStatus(
tr::lng_channel_admin_status_not_admin(tr::now));
}
}
*/
} else if (_role == Role::Kicked || _role == Role::Restricted) {
} else */if (_role == Role::Kicked || _role == Role::Restricted) {
const auto by = _additional.restrictedBy(participant);
row->setCustomStatus((_role == Role::Kicked
? tr::lng_channel_banned_status_removed_by