Rework admins info
This commit is contained in:
parent
fd2aebc1d5
commit
86e02cf13c
7 changed files with 96 additions and 8 deletions
|
|
@ -542,6 +542,10 @@ void PeerListRow::paintStatusText(
|
|||
_status.drawLeftElided(p, x, y, availableWidth, outerWidth);
|
||||
}
|
||||
|
||||
bool PeerListRow::hasAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename UpdateCallback>
|
||||
void PeerListRow::addRipple(const style::PeerListItem &st, QSize size, QPoint point, UpdateCallback updateCallback) {
|
||||
if (!_ripple) {
|
||||
|
|
@ -1276,7 +1280,11 @@ crl::time PeerListContent::paintRow(
|
|||
p.setPen(st::contactsNameFg);
|
||||
|
||||
auto skipRight = _st.item.photoPosition.x();
|
||||
auto actionSize = row->actionSize();
|
||||
auto actionSize = !row->actionSize().isEmpty()
|
||||
&& (row->placeholderSize().isEmpty()
|
||||
|| selected)
|
||||
? row->actionSize()
|
||||
: row->placeholderSize();
|
||||
auto actionMargins = actionSize.isEmpty() ? QMargins() : row->actionMargins();
|
||||
auto &name = row->name();
|
||||
auto namex = _st.item.namePosition.x();
|
||||
|
|
@ -1649,7 +1657,7 @@ void PeerListContent::selectByMouse(QPoint globalPosition) {
|
|||
if (row->disabled()) {
|
||||
selected = Selected();
|
||||
} else {
|
||||
if (getActionRect(row, selected.index).contains(point)) {
|
||||
if (row->hasAction() && getActionRect(row, selected.index).contains(point)) {
|
||||
selected.action = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,9 @@ public:
|
|||
virtual QSize actionSize() const {
|
||||
return QSize();
|
||||
}
|
||||
virtual QSize placeholderSize() const {
|
||||
return QSize();
|
||||
}
|
||||
virtual QMargins actionMargins() const {
|
||||
return QMargins();
|
||||
}
|
||||
|
|
@ -207,6 +210,8 @@ public:
|
|||
int outerWidth,
|
||||
bool selected);
|
||||
|
||||
virtual bool hasAction();
|
||||
|
||||
protected:
|
||||
bool isInitialized() const {
|
||||
return _initialized;
|
||||
|
|
|
|||
|
|
@ -109,9 +109,16 @@ void PeerListRowWithLink::setActionLink(const QString &action) {
|
|||
refreshActionLink();
|
||||
}
|
||||
|
||||
void PeerListRowWithLink::setActionPlaceholder(const QString &placeholder, bool active) {
|
||||
_actionPlaceholder = placeholder;
|
||||
_actionPlaceholderActive = active;
|
||||
refreshActionLink();
|
||||
}
|
||||
|
||||
void PeerListRowWithLink::refreshActionLink() {
|
||||
if (!isInitialized()) return;
|
||||
_actionWidth = _action.isEmpty() ? 0 : st::normalFont->width(_action);
|
||||
_actionPlaceholderWidth = _actionPlaceholder.isEmpty() ? 0 : st::normalFont->width(_actionPlaceholder);
|
||||
}
|
||||
|
||||
void PeerListRowWithLink::lazyInitialize(const style::PeerListItem &st) {
|
||||
|
|
@ -119,10 +126,18 @@ void PeerListRowWithLink::lazyInitialize(const style::PeerListItem &st) {
|
|||
refreshActionLink();
|
||||
}
|
||||
|
||||
bool PeerListRowWithLink::hasAction() {
|
||||
return !_action.isEmpty();
|
||||
}
|
||||
|
||||
QSize PeerListRowWithLink::actionSize() const {
|
||||
return QSize(_actionWidth, st::normalFont->height);
|
||||
}
|
||||
|
||||
QSize PeerListRowWithLink::placeholderSize() const {
|
||||
return QSize(_actionPlaceholderWidth, st::normalFont->height);
|
||||
}
|
||||
|
||||
QMargins PeerListRowWithLink::actionMargins() const {
|
||||
return QMargins(
|
||||
st::contactsCheckPosition.x(),
|
||||
|
|
@ -138,9 +153,19 @@ void PeerListRowWithLink::paintAction(
|
|||
int outerWidth,
|
||||
bool selected,
|
||||
bool actionSelected) {
|
||||
p.setFont(actionSelected ? st::linkOverFont : st::linkFont);
|
||||
p.setPen(actionSelected ? st::defaultLinkButton.overColor : st::defaultLinkButton.color);
|
||||
p.drawTextLeft(x, y, outerWidth, _action, _actionWidth);
|
||||
if (!_action.isEmpty() && (_actionPlaceholder.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);
|
||||
} else {
|
||||
p.setFont(st::linkFont);
|
||||
p.setPen(_actionPlaceholderActive
|
||||
? st::defaultPeerListItem.statusFgActive
|
||||
: selected
|
||||
? st::defaultPeerListItem.statusFgOver
|
||||
: st::defaultPeerListItem.statusFg);
|
||||
p.drawTextLeft(x, y, outerWidth, _actionPlaceholder, _actionPlaceholderWidth);
|
||||
}
|
||||
}
|
||||
|
||||
PeerListGlobalSearchController::PeerListGlobalSearchController(
|
||||
|
|
|
|||
|
|
@ -39,12 +39,15 @@ public:
|
|||
using PeerListRow::PeerListRow;
|
||||
|
||||
void setActionLink(const QString &action);
|
||||
void setActionPlaceholder(const QString &placeholder, bool active = false);
|
||||
|
||||
void lazyInitialize(const style::PeerListItem &st) override;
|
||||
bool hasAction() override;
|
||||
|
||||
private:
|
||||
void refreshActionLink();
|
||||
QSize actionSize() const override;
|
||||
QSize placeholderSize() const override;
|
||||
QMargins actionMargins() const override;
|
||||
void paintAction(
|
||||
Painter &p,
|
||||
|
|
@ -55,7 +58,10 @@ private:
|
|||
bool actionSelected) override;
|
||||
|
||||
QString _action;
|
||||
QString _actionPlaceholder;
|
||||
bool _actionPlaceholderActive = false;
|
||||
int _actionWidth = 0;
|
||||
int _actionPlaceholderWidth = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ public:
|
|||
|
||||
template <typename Widget>
|
||||
Widget *addControl(object_ptr<Widget> widget, QMargins margin);
|
||||
void setCustomStatus(const QString &status);
|
||||
|
||||
protected:
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
|
@ -135,6 +136,7 @@ private:
|
|||
Ui::Text::String _userName;
|
||||
bool _hasAdminRights = false;
|
||||
object_ptr<Ui::VerticalLayout> _rows;
|
||||
QString _customStatus;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -172,6 +174,10 @@ Widget *EditParticipantBox::Inner::addControl(
|
|||
return _rows->add(std::move(widget), margin);
|
||||
}
|
||||
|
||||
void EditParticipantBox::Inner::setCustomStatus(const QString &status) {
|
||||
_customStatus = status;
|
||||
}
|
||||
|
||||
int EditParticipantBox::Inner::resizeGetHeight(int newWidth) {
|
||||
_userPhoto->moveToLeft(
|
||||
st::rightsPhotoMargin.left(),
|
||||
|
|
@ -201,6 +207,10 @@ void EditParticipantBox::Inner::paintEvent(QPaintEvent *e) {
|
|||
namew,
|
||||
width());
|
||||
const auto statusText = [&] {
|
||||
if (!_customStatus.isEmpty()) {
|
||||
return _customStatus;
|
||||
}
|
||||
|
||||
if (_user->isBot()) {
|
||||
const auto seesAllMessages = _user->botInfo->readsAllHistory
|
||||
|| _hasAdminRights;
|
||||
|
|
@ -229,6 +239,13 @@ EditParticipantBox::EditParticipantBox(
|
|||
, _hasAdminRights(hasAdminRights) {
|
||||
}
|
||||
|
||||
void EditParticipantBox::setCustomStatus(const QString &status) {
|
||||
_customStatus = status;
|
||||
if (_inner) {
|
||||
_inner->setCustomStatus(status);
|
||||
}
|
||||
}
|
||||
|
||||
void EditParticipantBox::prepare() {
|
||||
_inner = setInnerWidget(object_ptr<Inner>(
|
||||
this,
|
||||
|
|
@ -236,6 +253,7 @@ void EditParticipantBox::prepare() {
|
|||
_user,
|
||||
hasAdminRights()));
|
||||
setDimensionsToContent(st::boxWideWidth, _inner);
|
||||
_inner->setCustomStatus(_customStatus);
|
||||
}
|
||||
|
||||
template <typename Widget>
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public:
|
|||
not_null<UserData*> user,
|
||||
bool hasAdminRights);
|
||||
|
||||
void setCustomStatus(const QString &status);
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
||||
|
|
@ -62,6 +63,7 @@ private:
|
|||
|
||||
class Inner;
|
||||
QPointer<Inner> _inner;
|
||||
QString _customStatus;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1475,6 +1475,20 @@ void ParticipantsBoxController::showAdmin(not_null<UserData*> user) {
|
|||
user,
|
||||
currentRights,
|
||||
_additional.adminRank(user));
|
||||
if (const auto by = _additional.adminPromotedBy(user)) {
|
||||
box->setCustomStatus(tr::lng_channel_admin_status_promoted_by(
|
||||
tr::now,
|
||||
lt_user,
|
||||
by->name));
|
||||
} else {
|
||||
if (_additional.isCreator(user)) {
|
||||
box->setCustomStatus(
|
||||
tr::lng_channel_admin_status_creator(tr::now));
|
||||
} else {
|
||||
box->setCustomStatus(
|
||||
tr::lng_channel_admin_status_not_admin(tr::now));
|
||||
}
|
||||
}
|
||||
const auto chat = _peer->asChat();
|
||||
const auto channel = _peer->asChannel();
|
||||
if (_additional.canAddOrEditAdmin(user)) {
|
||||
|
|
@ -1787,9 +1801,17 @@ std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(
|
|||
auto row = std::make_unique<PeerListRowWithLink>(user);
|
||||
refreshCustomStatus(row.get());
|
||||
if (_role == Role::Admins
|
||||
&& _additional.adminRights(user).has_value()
|
||||
&& _additional.canEditAdmin(user)) {
|
||||
row->setActionLink(tr::lng_profile_kick(tr::now));
|
||||
&& (_additional.adminRights(user).has_value()
|
||||
|| _additional.isCreator(user))) {
|
||||
if (_additional.canEditAdmin(user) && !_additional.isCreator(user)) {
|
||||
row->setActionLink(tr::lng_profile_kick(tr::now));
|
||||
}
|
||||
row->setActionPlaceholder(channel
|
||||
? channel->adminRank(user)
|
||||
: (chat && _additional.isCreator(user))
|
||||
? tr::lng_owner_badge(tr::now)
|
||||
: QString(),
|
||||
_additional.isCreator(user));
|
||||
} else if (_role == Role::Kicked || _role == Role::Restricted) {
|
||||
if (_additional.canRestrictUser(user)) {
|
||||
row->setActionLink(tr::lng_profile_delete_removed(tr::now));
|
||||
|
|
@ -1840,6 +1862,7 @@ void ParticipantsBoxController::refreshCustomStatus(
|
|||
not_null<PeerListRow*> row) const {
|
||||
const auto user = row->peer()->asUser();
|
||||
if (_role == Role::Admins) {
|
||||
/*
|
||||
if (const auto by = _additional.adminPromotedBy(user)) {
|
||||
row->setCustomStatus(tr::lng_channel_admin_status_promoted_by(
|
||||
tr::now,
|
||||
|
|
@ -1854,6 +1877,7 @@ void ParticipantsBoxController::refreshCustomStatus(
|
|||
tr::lng_channel_admin_status_not_admin(tr::now));
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else if (_role == Role::Kicked || _role == Role::Restricted) {
|
||||
const auto by = _additional.restrictedBy(user);
|
||||
row->setCustomStatus((_role == Role::Kicked
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue