From edf1417bbbb532edb497f2ecd284883aade22f71 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 9 Sep 2024 15:25:51 +0300 Subject: [PATCH] Added date of restriction to EditRestrictedBox. --- Telegram/Resources/langs/lang.strings | 2 ++ .../boxes/peers/add_participants_box.cpp | 4 ++- .../boxes/peers/edit_participant_box.cpp | 31 ++++++++++++++++-- .../boxes/peers/edit_participant_box.h | 6 +++- .../boxes/peers/edit_participants_box.cpp | 4 ++- .../admin_log/history_admin_log_inner.cpp | 32 +++++++++++++------ 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 2712e5d7d..1d8fe5099 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4303,6 +4303,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_rights_chat_files" = "Files"; "lng_rights_chat_voice_messages" = "Voice messages"; "lng_rights_chat_video_messages" = "Video messages"; +"lng_rights_chat_restricted_by" = "Restricted by {user} at {date}."; +"lng_rights_chat_banned_by" = "Banned by {user} at {date}."; "lng_rights_chat_banned_until_header" = "Restricted until"; "lng_rights_chat_banned_forever" = "Forever"; "lng_rights_chat_banned_day#one" = "For {count} day"; diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index bd66b859e..e995864c4 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -1354,7 +1354,9 @@ void AddSpecialBoxController::showRestricted( _peer, user, _additional.adminRights(user).has_value(), - currentRights); + currentRights, + _additional.restrictedBy(user), + _additional.restrictedSince(user)); if (_additional.canRestrictParticipant(user)) { const auto done = crl::guard(this, [=]( ChatRestrictionsInfo newRights) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 23c7602f3..af223ff71 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -705,9 +705,13 @@ EditRestrictedBox::EditRestrictedBox( not_null peer, not_null user, bool hasAdminRights, - ChatRestrictionsInfo rights) + ChatRestrictionsInfo rights, + UserData *by, + TimeId since) : EditParticipantBox(nullptr, peer, user, hasAdminRights) -, _oldRights(rights) { +, _oldRights(rights) +, _by(by) +, _since(since) { } void EditRestrictedBox::prepare() { @@ -782,6 +786,29 @@ void EditRestrictedBox::prepare() { // tr::lng_rights_chat_banned_block(tr::now), // st::boxLinkButton)); + if (_since) { + const auto parsed = base::unixtime::parse(_since); + const auto inner = addControl(object_ptr(this)); + const auto isBanned = (_oldRights.flags + & ChatRestriction::ViewMessages); + Ui::AddSkip(inner); + const auto label = Ui::AddDividerText( + inner, + (isBanned + ? tr::lng_rights_chat_banned_by + : tr::lng_rights_chat_restricted_by)( + lt_user, + rpl::single(_by + ? Ui::Text::Link(_by->name(), 1) + : TextWithEntities(QString::fromUtf8("\U0001F47B"))), + lt_date, + rpl::single(TextWithEntities{ langDateTimeFull(parsed) }), + Ui::Text::WithEntities)); + if (_by) { + label->setLink(1, _by->createOpenLink()); + } + } + if (canSave()) { const auto save = [=, value = getRestrictions] { if (!_saveCallback) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.h b/Telegram/SourceFiles/boxes/peers/edit_participant_box.h index 6d9afe25a..1385a1756 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.h @@ -146,7 +146,9 @@ public: not_null peer, not_null user, bool hasAdminRights, - ChatRestrictionsInfo rights); + ChatRestrictionsInfo rights, + UserData *by, + TimeId since); void setSaveCallback( Fn callback) { @@ -170,6 +172,8 @@ private: TimeId getRealUntilValue() const; const ChatRestrictionsInfo _oldRights; + UserData *_by = nullptr; + TimeId _since = 0; TimeId _until = 0; Fn _saveCallback; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 2b4f4a202..a96c7602f 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1804,7 +1804,9 @@ void ParticipantsBoxController::showRestricted(not_null user) { _peer, user, hasAdminRights, - currentRights); + currentRights, + _additional.restrictedBy(user), + _additional.restrictedSince(user)); if (_additional.canRestrictParticipant(user)) { const auto done = crl::guard(this, [=]( ChatRestrictionsInfo newRights) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index d90bc322c..1194feb10 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1509,15 +1509,28 @@ void InnerWidget::suggestRestrictParticipant( } _menu->addAction(tr::lng_context_restrict_user(tr::now), [=] { const auto user = participant->asUser(); - auto editRestrictions = [=](bool hasAdminRights, ChatRestrictionsInfo currentRights) { + auto editRestrictions = [=]( + bool hasAdminRights, + ChatRestrictionsInfo currentRights, + UserData *by, + TimeId since) { auto weak = QPointer(this); auto weakBox = std::make_shared>(); - auto box = Box(_channel, user, hasAdminRights, currentRights); + auto box = Box( + _channel, + user, + hasAdminRights, + currentRights, + by, + since); box->setSaveCallback([=]( ChatRestrictionsInfo oldRights, ChatRestrictionsInfo newRights) { if (weak) { - weak->restrictParticipant(participant, oldRights, newRights); + weak->restrictParticipant( + participant, + oldRights, + newRights); } if (*weakBox) { (*weakBox)->closeBox(); @@ -1544,7 +1557,7 @@ void InnerWidget::suggestRestrictParticipant( }); *weakBox = _controller->show(Ui::MakeConfirmBox({ text, sure })); } else if (base::contains(_admins, user)) { - editRestrictions(true, ChatRestrictionsInfo()); + editRestrictions(true, {}, nullptr, 0); } else { _api.request(MTPchannels_GetParticipant( _channel->inputChannel, @@ -1558,15 +1571,16 @@ void InnerWidget::suggestRestrictParticipant( using Type = Api::ChatParticipant::Type; if (participant.type() == Type::Creator || participant.type() == Type::Admin) { - editRestrictions(true, {}); - } else if (participant.type() == Type::Restricted - || participant.type() == Type::Banned) { + editRestrictions(true, {}, nullptr, 0); + } else if (const auto since = participant.restrictedSince()) { editRestrictions( false, - participant.restrictions()); + participant.restrictions(), + user->owner().user(participant.by()), + since); } }).fail([=] { - editRestrictions(false, ChatRestrictionsInfo()); + editRestrictions(false, {}, nullptr, 0); }).send(); } }, &st::menuIconPermissions);