diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index fdc6137ec..71ad8f749 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -542,6 +542,10 @@ void PeerListRow::paintStatusText( _status.drawLeftElided(p, x, y, availableWidth, outerWidth); } +bool PeerListRow::hasAction() { + return true; +} + template 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; } } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index ac88bf3cb..46debdf10 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -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; diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index bf400ead7..bbee15f94 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -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( diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.h b/Telegram/SourceFiles/boxes/peer_list_controllers.h index b6ca666f9..6210ea93d 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.h +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.h @@ -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; }; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 67a19c655..66b3fa154 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -123,6 +123,7 @@ public: template Widget *addControl(object_ptr 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 _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( this, @@ -236,6 +253,7 @@ void EditParticipantBox::prepare() { _user, hasAdminRights())); setDimensionsToContent(st::boxWideWidth, _inner); + _inner->setCustomStatus(_customStatus); } template diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.h b/Telegram/SourceFiles/boxes/peers/edit_participant_box.h index 689b08a7b..49cee8694 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.h @@ -37,6 +37,7 @@ public: not_null user, bool hasAdminRights); + void setCustomStatus(const QString &status); protected: void prepare() override; @@ -62,6 +63,7 @@ private: class Inner; QPointer _inner; + QString _customStatus; }; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 25a113016..e5717703b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1475,6 +1475,20 @@ void ParticipantsBoxController::showAdmin(not_null 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 ParticipantsBoxController::createRow( auto row = std::make_unique(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 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