From 756fa702b2ce8a9cb7975f15db9551ac4a458929 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 9 Feb 2021 19:17:27 +0400 Subject: [PATCH] Allow to edit chat ttl_period from Clear History. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/boxes/confirm_box.cpp | 46 ++++++++++++- Telegram/SourceFiles/boxes/confirm_box.h | 2 + .../boxes/peers/edit_peer_info_box.cpp | 69 +++++++++++-------- .../boxes/peers/edit_peer_info_box.h | 5 ++ 5 files changed, 91 insertions(+), 32 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1b79c72d9..262e1e2e4 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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\"."; diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index d7f68a63c..e560fe0b2 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -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); } } diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index dea112536..22ebb6b60 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -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 _banUser = { nullptr }; object_ptr _reportSpam = { nullptr }; object_ptr _deleteAll = { nullptr }; + object_ptr _autoDeleteSettings = { nullptr }; Fn _deleteConfirmedCallback; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 739477483..c0ae442d4 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -899,36 +899,9 @@ void Controller::fillSetMessagesTTLButton() { _ttlSavedValue = value; }); const auto buttonCallback = [=] { - Ui::show(Box([=](not_null 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 box, + TimeId ttlPeriod, + Fn 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 navigation, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h index 11ffd36ec..3a81e6fa1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h @@ -23,6 +23,11 @@ class VerticalLayout; class SettingsButton; } // namespace Ui +void AutoDeleteSettingsBox( + not_null box, + TimeId ttlPeriod, + Fn callback); + class EditPeerInfoBox : public Ui::BoxContent { public: EditPeerInfoBox(