Allow to edit chat ttl_period from Clear History.

This commit is contained in:
John Preston 2021-02-09 19:17:27 +04:00
parent d81c8f002d
commit 756fa702b2
5 changed files with 91 additions and 32 deletions

View File

@ -1696,6 +1696,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_delete_for_me_chat_hint#other" = "This will delete them just for you, not for other participants of the chat.";
"lng_delete_for_me_hint#one" = "This will delete it just for you.";
"lng_delete_for_me_hint#other" = "This will delete them just for you.";
"lng_edit_auto_delete_settings" = "Edit Auto-Delete Settings";
"lng_selected_unsend_about_user_one" = "You can also delete the message you sent from {user}'s inbox by checking \"Unsend my messages\".";
"lng_selected_unsend_about_user#one" = "You can also delete the {count} message you sent from {user}'s inbox by checking \"Unsend my messages\".";
"lng_selected_unsend_about_user#other" = "You can also delete the {count} messages you sent from {user}'s inbox by checking \"Unsend my messages\".";

View File

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_invite_links.h"
#include "history/history.h"
#include "history/history_item.h"
#include "ui/layers/generic_box.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
@ -36,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo_media.h"
#include "data/data_changes.h"
#include "base/unixtime.h"
#include "boxes/peers/edit_peer_info_box.h"
#include "main/main_session.h"
#include "mtproto/mtproto_config.h"
#include "facades.h" // Ui::showChatsList
@ -650,6 +652,37 @@ void DeleteMessagesBox::prepare() {
}
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
if (_wipeHistoryJustClear
&& _wipeHistoryPeer
&& (_wipeHistoryPeer->isUser()
|| _wipeHistoryPeer->isMegagroup()
|| _wipeHistoryPeer->isChat())) {
_autoDeleteSettings.create(
this,
tr::lng_edit_auto_delete_settings(tr::now),
st::boxLinkButton);
const auto peer = _wipeHistoryPeer;
const auto callback = crl::guard(&peer->session(), [=](TimeId period) {
using Flag = MTPmessages_SetHistoryTTL::Flag;
peer->session().api().request(MTPmessages_SetHistoryTTL(
MTP_flags(peer->oneSideTTL() ? Flag::f_pm_oneside : Flag(0)),
peer->input,
MTP_int(period)
)).done([=](const MTPUpdates &result) {
peer->session().api().applyUpdates(result);
}).fail([=](const RPCError &error) {
}).send();
});
_autoDeleteSettings->setClickedCallback([=] {
getDelegate()->show(
Box(
AutoDeleteSettingsBox,
_wipeHistoryPeer->myMessagesTTL(),
callback),
Ui::LayerOption(0));
});
}
addButton(
deleteText->value(),
[=] { deleteAndClear(); },
@ -669,6 +702,9 @@ void DeleteMessagesBox::prepare() {
} else if (_revoke) {
fullHeight += st::boxMediumSkip + _revoke->heightNoMargins();
}
if (_autoDeleteSettings) {
fullHeight += st::boxMediumSkip + _autoDeleteSettings->height();
}
setDimensions(st::boxWidth, fullHeight);
}
@ -791,8 +827,8 @@ void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
auto top = _text->bottomNoMargins() + st::boxMediumSkip;
if (_moderateFrom) {
auto top = _text->bottomNoMargins() + st::boxMediumSkip;
if (_banUser) {
_banUser->moveToLeft(st::boxPadding.left(), top);
top += _banUser->heightNoMargins() + st::boxLittleSkip;
@ -801,11 +837,17 @@ void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
top += _reportSpam->heightNoMargins() + st::boxLittleSkip;
if (_deleteAll) {
_deleteAll->moveToLeft(st::boxPadding.left(), top);
top += _deleteAll->heightNoMargins() + st::boxLittleSkip;
}
} else if (_revoke) {
const auto availableWidth = width() - 2 * st::boxPadding.left();
_revoke->resizeToNaturalWidth(availableWidth);
_revoke->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip);
_revoke->moveToLeft(st::boxPadding.left(), top);
top += _revoke->heightNoMargins() + st::boxLittleSkip;
}
if (_autoDeleteSettings) {
top += st::boxMediumSkip - st::boxLittleSkip;
_autoDeleteSettings->moveToLeft(st::boxPadding.left(), top);
}
}

View File

@ -23,6 +23,7 @@ namespace Ui {
class Checkbox;
class FlatLabel;
class EmptyUserpic;
class LinkButton;
} // namespace Ui
class InformBox;
@ -243,6 +244,7 @@ private:
object_ptr<Ui::Checkbox> _banUser = { nullptr };
object_ptr<Ui::Checkbox> _reportSpam = { nullptr };
object_ptr<Ui::Checkbox> _deleteAll = { nullptr };
object_ptr<Ui::LinkButton> _autoDeleteSettings = { nullptr };
Fn<void()> _deleteConfirmedCallback;

View File

@ -899,36 +899,9 @@ void Controller::fillSetMessagesTTLButton() {
_ttlSavedValue = value;
});
const auto buttonCallback = [=] {
Ui::show(Box([=](not_null<Ui::GenericBox*> box) {
const auto options = {
tr::lng_manage_messages_ttl_never(tr::now),
tr::lng_manage_messages_ttl_after1(tr::now),
tr::lng_manage_messages_ttl_after2(tr::now),
u"5 seconds"_q, AssertIsDebug()
};
const auto initial = !*_ttlSavedValue
? 0
: (*_ttlSavedValue == 5) AssertIsDebug()
? 3 AssertIsDebug()
: (*_ttlSavedValue < 3 * 86400)
? 1
: 2;
const auto callback = [=](int option) {
boxCallback(!option
? 0
: (option == 1)
? 86400
: (option == 3) AssertIsDebug()
? 5 AssertIsDebug()
: 7 * 86400);
};
SingleChoiceBox(box, {
.title = tr::lng_manage_messages_ttl_title(),
.options = options,
.initialSelection = initial,
.callback = callback,
});
}), Ui::LayerOption::KeepOther);
Ui::show(
Box(AutoDeleteSettingsBox, *_ttlSavedValue, boxCallback),
Ui::LayerOption::KeepOther);
};
AddButtonWithText(
_controls.buttonsLayout,
@ -1641,6 +1614,42 @@ void Controller::deleteChannel() {
} // namespace
void AutoDeleteSettingsBox(
not_null<Ui::GenericBox*> box,
TimeId ttlPeriod,
Fn<void(TimeId)> callback) {
const auto options = {
tr::lng_manage_messages_ttl_never(tr::now),
tr::lng_manage_messages_ttl_after1(tr::now),
tr::lng_manage_messages_ttl_after2(tr::now),
u"5 seconds"_q, AssertIsDebug()
};
const auto initial = !ttlPeriod
? 0
: (ttlPeriod == 5) AssertIsDebug()
? 3 AssertIsDebug()
: (ttlPeriod < 3 * 86400)
? 1
: 2;
const auto callbackFromOption = [=](int option) {
const auto period = !option
? 0
: (option == 1)
? 86400
: (option == 3) AssertIsDebug()
? 5 AssertIsDebug()
: 7 * 86400;
callback(period);
};
SingleChoiceBox(box, {
.title = tr::lng_manage_messages_ttl_title(),
.options = options,
.initialSelection = initial,
.callback = callbackFromOption,
});
}
EditPeerInfoBox::EditPeerInfoBox(
QWidget*,
not_null<Window::SessionNavigation*> navigation,

View File

@ -23,6 +23,11 @@ class VerticalLayout;
class SettingsButton;
} // namespace Ui
void AutoDeleteSettingsBox(
not_null<Ui::GenericBox*> box,
TimeId ttlPeriod,
Fn<void(TimeId)> callback);
class EditPeerInfoBox : public Ui::BoxContent {
public:
EditPeerInfoBox(