Added date of restriction to EditRestrictedBox.

This commit is contained in:
23rd 2024-09-09 15:25:51 +03:00
parent 686e9643ad
commit edf1417bbb
6 changed files with 65 additions and 14 deletions

View file

@ -4303,6 +4303,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_rights_chat_files" = "Files"; "lng_rights_chat_files" = "Files";
"lng_rights_chat_voice_messages" = "Voice messages"; "lng_rights_chat_voice_messages" = "Voice messages";
"lng_rights_chat_video_messages" = "Video 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_until_header" = "Restricted until";
"lng_rights_chat_banned_forever" = "Forever"; "lng_rights_chat_banned_forever" = "Forever";
"lng_rights_chat_banned_day#one" = "For {count} day"; "lng_rights_chat_banned_day#one" = "For {count} day";

View file

@ -1354,7 +1354,9 @@ void AddSpecialBoxController::showRestricted(
_peer, _peer,
user, user,
_additional.adminRights(user).has_value(), _additional.adminRights(user).has_value(),
currentRights); currentRights,
_additional.restrictedBy(user),
_additional.restrictedSince(user));
if (_additional.canRestrictParticipant(user)) { if (_additional.canRestrictParticipant(user)) {
const auto done = crl::guard(this, [=]( const auto done = crl::guard(this, [=](
ChatRestrictionsInfo newRights) { ChatRestrictionsInfo newRights) {

View file

@ -705,9 +705,13 @@ EditRestrictedBox::EditRestrictedBox(
not_null<PeerData*> peer, not_null<PeerData*> peer,
not_null<UserData*> user, not_null<UserData*> user,
bool hasAdminRights, bool hasAdminRights,
ChatRestrictionsInfo rights) ChatRestrictionsInfo rights,
UserData *by,
TimeId since)
: EditParticipantBox(nullptr, peer, user, hasAdminRights) : EditParticipantBox(nullptr, peer, user, hasAdminRights)
, _oldRights(rights) { , _oldRights(rights)
, _by(by)
, _since(since) {
} }
void EditRestrictedBox::prepare() { void EditRestrictedBox::prepare() {
@ -782,6 +786,29 @@ void EditRestrictedBox::prepare() {
// tr::lng_rights_chat_banned_block(tr::now), // tr::lng_rights_chat_banned_block(tr::now),
// st::boxLinkButton)); // st::boxLinkButton));
if (_since) {
const auto parsed = base::unixtime::parse(_since);
const auto inner = addControl(object_ptr<Ui::VerticalLayout>(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()) { if (canSave()) {
const auto save = [=, value = getRestrictions] { const auto save = [=, value = getRestrictions] {
if (!_saveCallback) { if (!_saveCallback) {

View file

@ -146,7 +146,9 @@ public:
not_null<PeerData*> peer, not_null<PeerData*> peer,
not_null<UserData*> user, not_null<UserData*> user,
bool hasAdminRights, bool hasAdminRights,
ChatRestrictionsInfo rights); ChatRestrictionsInfo rights,
UserData *by,
TimeId since);
void setSaveCallback( void setSaveCallback(
Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> callback) { Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> callback) {
@ -170,6 +172,8 @@ private:
TimeId getRealUntilValue() const; TimeId getRealUntilValue() const;
const ChatRestrictionsInfo _oldRights; const ChatRestrictionsInfo _oldRights;
UserData *_by = nullptr;
TimeId _since = 0;
TimeId _until = 0; TimeId _until = 0;
Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> _saveCallback; Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> _saveCallback;

View file

@ -1804,7 +1804,9 @@ void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {
_peer, _peer,
user, user,
hasAdminRights, hasAdminRights,
currentRights); currentRights,
_additional.restrictedBy(user),
_additional.restrictedSince(user));
if (_additional.canRestrictParticipant(user)) { if (_additional.canRestrictParticipant(user)) {
const auto done = crl::guard(this, [=]( const auto done = crl::guard(this, [=](
ChatRestrictionsInfo newRights) { ChatRestrictionsInfo newRights) {

View file

@ -1509,15 +1509,28 @@ void InnerWidget::suggestRestrictParticipant(
} }
_menu->addAction(tr::lng_context_restrict_user(tr::now), [=] { _menu->addAction(tr::lng_context_restrict_user(tr::now), [=] {
const auto user = participant->asUser(); const auto user = participant->asUser();
auto editRestrictions = [=](bool hasAdminRights, ChatRestrictionsInfo currentRights) { auto editRestrictions = [=](
bool hasAdminRights,
ChatRestrictionsInfo currentRights,
UserData *by,
TimeId since) {
auto weak = QPointer<InnerWidget>(this); auto weak = QPointer<InnerWidget>(this);
auto weakBox = std::make_shared<QPointer<Ui::BoxContent>>(); auto weakBox = std::make_shared<QPointer<Ui::BoxContent>>();
auto box = Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights); auto box = Box<EditRestrictedBox>(
_channel,
user,
hasAdminRights,
currentRights,
by,
since);
box->setSaveCallback([=]( box->setSaveCallback([=](
ChatRestrictionsInfo oldRights, ChatRestrictionsInfo oldRights,
ChatRestrictionsInfo newRights) { ChatRestrictionsInfo newRights) {
if (weak) { if (weak) {
weak->restrictParticipant(participant, oldRights, newRights); weak->restrictParticipant(
participant,
oldRights,
newRights);
} }
if (*weakBox) { if (*weakBox) {
(*weakBox)->closeBox(); (*weakBox)->closeBox();
@ -1544,7 +1557,7 @@ void InnerWidget::suggestRestrictParticipant(
}); });
*weakBox = _controller->show(Ui::MakeConfirmBox({ text, sure })); *weakBox = _controller->show(Ui::MakeConfirmBox({ text, sure }));
} else if (base::contains(_admins, user)) { } else if (base::contains(_admins, user)) {
editRestrictions(true, ChatRestrictionsInfo()); editRestrictions(true, {}, nullptr, 0);
} else { } else {
_api.request(MTPchannels_GetParticipant( _api.request(MTPchannels_GetParticipant(
_channel->inputChannel, _channel->inputChannel,
@ -1558,15 +1571,16 @@ void InnerWidget::suggestRestrictParticipant(
using Type = Api::ChatParticipant::Type; using Type = Api::ChatParticipant::Type;
if (participant.type() == Type::Creator if (participant.type() == Type::Creator
|| participant.type() == Type::Admin) { || participant.type() == Type::Admin) {
editRestrictions(true, {}); editRestrictions(true, {}, nullptr, 0);
} else if (participant.type() == Type::Restricted } else if (const auto since = participant.restrictedSince()) {
|| participant.type() == Type::Banned) {
editRestrictions( editRestrictions(
false, false,
participant.restrictions()); participant.restrictions(),
user->owner().user(participant.by()),
since);
} }
}).fail([=] { }).fail([=] {
editRestrictions(false, ChatRestrictionsInfo()); editRestrictions(false, {}, nullptr, 0);
}).send(); }).send();
} }
}, &st::menuIconPermissions); }, &st::menuIconPermissions);