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