Skip to content

Commit

Permalink
Added date of restriction to EditRestrictedBox.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Sep 9, 2024
1 parent 686e964 commit edf1417
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/boxes/peers/add_participants_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 29 additions & 2 deletions Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,13 @@ EditRestrictedBox::EditRestrictedBox(
not_null<PeerData*> peer,
not_null<UserData*> 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() {
Expand Down Expand Up @@ -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<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()) {
const auto save = [=, value = getRestrictions] {
if (!_saveCallback) {
Expand Down
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/boxes/peers/edit_participant_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ class EditRestrictedBox : public EditParticipantBox {
not_null<PeerData*> peer,
not_null<UserData*> user,
bool hasAdminRights,
ChatRestrictionsInfo rights);
ChatRestrictionsInfo rights,
UserData *by,
TimeId since);

void setSaveCallback(
Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> callback) {
Expand All @@ -170,6 +172,8 @@ class EditRestrictedBox : public EditParticipantBox {
TimeId getRealUntilValue() const;

const ChatRestrictionsInfo _oldRights;
UserData *_by = nullptr;
TimeId _since = 0;
TimeId _until = 0;
Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> _saveCallback;

Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,9 @@ void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {
_peer,
user,
hasAdminRights,
currentRights);
currentRights,
_additional.restrictedBy(user),
_additional.restrictedSince(user));
if (_additional.canRestrictParticipant(user)) {
const auto done = crl::guard(this, [=](
ChatRestrictionsInfo newRights) {
Expand Down
32 changes: 23 additions & 9 deletions Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InnerWidget>(this);
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([=](
ChatRestrictionsInfo oldRights,
ChatRestrictionsInfo newRights) {
if (weak) {
weak->restrictParticipant(participant, oldRights, newRights);
weak->restrictParticipant(
participant,
oldRights,
newRights);
}
if (*weakBox) {
(*weakBox)->closeBox();
Expand All @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit edf1417

Please sign in to comment.