diff --git a/Telegram/SourceFiles/boxes/delete_messages_box.cpp b/Telegram/SourceFiles/boxes/delete_messages_box.cpp index 90d0fcc240..f15a50cb9c 100644 --- a/Telegram/SourceFiles/boxes/delete_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/delete_messages_box.cpp @@ -17,9 +17,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "history/history.h" #include "history/history_item.h" -#include "history/view/controls/history_view_ttl_button.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "menu/menu_ttl_validator.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" #include "ui/widgets/buttons.h" @@ -228,31 +228,22 @@ void DeleteMessagesBox::prepare() { } _text.create(this, rpl::single(std::move(details)), st::boxLabel); - if (_wipeHistoryJustClear - && _wipeHistoryPeer - && ((_wipeHistoryPeer->isUser() - && !_wipeHistoryPeer->isSelf() - && !_wipeHistoryPeer->isNotificationsUser()) - || (_wipeHistoryPeer->isChat() - && _wipeHistoryPeer->asChat()->canDeleteMessages()) - || (_wipeHistoryPeer->isChannel() - && _wipeHistoryPeer->asChannel()->canDeleteMessages()))) { - _wipeHistoryPeer->updateFull(); -#if 0 - _autoDeleteSettings.create( - this, - (_wipeHistoryPeer->messagesTTL() - ? tr::lng_edit_auto_delete_settings(tr::now) - : tr::lng_enable_auto_delete(tr::now)), - st::boxLinkButton); - _autoDeleteSettings->setClickedCallback([=] { - getDelegate()->show( - Box( - HistoryView::Controls::AutoDeleteSettingsMenu, - _wipeHistoryPeer), - Ui::LayerOption(0)); - }); -#endif + if (_wipeHistoryJustClear && _wipeHistoryPeer) { + const auto validator = TTLMenu::TTLValidator( + std::make_shared(this), + _wipeHistoryPeer); + if (validator.can()) { + _wipeHistoryPeer->updateFull(); + _autoDeleteSettings.create( + this, + (_wipeHistoryPeer->messagesTTL() + ? tr::lng_edit_auto_delete_settings(tr::now) + : tr::lng_enable_auto_delete(tr::now)), + st::boxLinkButton); + _autoDeleteSettings->setClickedCallback([=] { + validator.showBox(); + }); + } } if (canDelete) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp b/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp index 7e293f8e45..f0b2eda2f8 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp @@ -25,15 +25,13 @@ TTLButton::TTLButton( , _button(parent, st::historyMessagesTTL) { const auto validator = TTLMenu::TTLValidator(std::move(show), peer); - auto clicks = _button.clicks( - ) | rpl::to_empty | rpl::filter([=] { + _button.setClickedCallback([=] { if (!validator.can()) { validator.showToast(); - return false; + return; } - return true; + validator.showBox(); }); - TTLMenu::SetupTTLMenu(parent, std::move(clicks), validator.createArgs()); peer->session().changes().peerFlagsValue( peer, diff --git a/Telegram/SourceFiles/menu/menu_ttl.cpp b/Telegram/SourceFiles/menu/menu_ttl.cpp index a047427cbf..df6bf2db30 100644 --- a/Telegram/SourceFiles/menu/menu_ttl.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl.cpp @@ -9,23 +9,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/event_filter.h" #include "lang/lang_keys.h" -#include "ui/boxes/choose_time.h" #include "ui/layers/generic_box.h" #include "ui/text/format_values.h" #include "ui/ui_utility.h" #include "ui/widgets/labels.h" +#include "ui/widgets/vertical_drum_picker.h" +#if 0 +#include "ui/boxes/choose_time.h" #include "ui/widgets/menu/menu_action.h" #include "ui/widgets/popup_menu.h" -#include "ui/widgets/vertical_drum_picker.h" -#include "styles/style_chat.h" #include "styles/style_dialogs.h" // dialogsScamFont -#include "styles/style_layers.h" #include "styles/style_menu_icons.h" +#endif +#include "styles/style_chat.h" +#include "styles/style_layers.h" namespace TTLMenu { namespace { +#if 0 constexpr auto kTTLDurHours1 = crl::time(1); constexpr auto kTTLDurSeconds1 = kTTLDurHours1 * 3600; constexpr auto kTTLDurHours2 = crl::time(24); @@ -34,6 +37,7 @@ constexpr auto kTTLDurHours3 = crl::time(24 * 7); constexpr auto kTTLDurSeconds3 = kTTLDurHours3 * 3600; constexpr auto kTTLDurHours4 = crl::time(24 * 30); constexpr auto kTTLDurSeconds4 = kTTLDurHours4 * 3600; +#endif void SetupPickerAndConfirm( not_null box, @@ -144,6 +148,7 @@ void SetupPickerAndConfirm( }); } +#if 0 class IconWithText final : public Ui::Menu::Action { public: using Ui::Menu::Action::Action; @@ -259,29 +264,27 @@ void TTLBoxOld( }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } +#endif -void TTLBox( - not_null box, - rpl::producer &&about, - Fn callback, - TimeId startTtlPeriod) { +} // namespace + +void TTLBox(not_null box, Args args) { box->addRow(object_ptr( box, - std::move(about), + std::move(args.about), st::boxLabel)); - SetupPickerAndConfirm(box, callback, startTtlPeriod); + SetupPickerAndConfirm(box, args.callback, args.startTtl); box->setTitle(tr::lng_manage_messages_ttl_title()); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); - if (startTtlPeriod) { + if (args.startTtl) { box->addLeftButton(tr::lng_manage_messages_ttl_disable(), [=] { - callback(0); + args.callback(0); }); } } -} // namespace - +#if 0 void FillTTLMenu(not_null menu, Args args) { const auto &st = menu->st().menu; const auto iconTextPosition = st.itemIconPosition @@ -306,10 +309,7 @@ void FillTTLMenu(not_null menu, Args args) { menu->addAction( tr::lng_manage_messages_ttl_after_custom(tr::now), - [a = args] { - a.show->showBox( - Box(TTLBox, std::move(a.about), a.callback, a.startTtl)); - }, + [a = args] { a.show->showBox(Box(TTLBox, a)); }, &st::menuIconCustomize); if (args.startTtl) { @@ -349,5 +349,6 @@ void SetupTTLMenu( state->menu->popup(QCursor::pos()); }, parent->lifetime()); } +#endif } // namespace TTLMenu diff --git a/Telegram/SourceFiles/menu/menu_ttl.h b/Telegram/SourceFiles/menu/menu_ttl.h index a1f5e0f786..e38ec8f0c6 100644 --- a/Telegram/SourceFiles/menu/menu_ttl.h +++ b/Telegram/SourceFiles/menu/menu_ttl.h @@ -8,9 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once namespace Ui { +#if 0 class PopupMenu; class RpWidget; +#endif class Show; +class GenericBox; } // namespace Ui namespace TTLMenu { @@ -22,11 +25,14 @@ struct Args { Fn callback; }; +void TTLBox(not_null box, Args args); +#if 0 void FillTTLMenu(not_null menu, Args args); void SetupTTLMenu( not_null parent, rpl::producer<> triggers, Args args); +#endif } // namespace TTLMenu diff --git a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp index 75b7ee1db6..2834b0c707 100644 --- a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "main/main_session.h" #include "menu/menu_ttl.h" +#include "ui/layers/generic_box.h" #include "ui/layers/show.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" @@ -101,7 +102,9 @@ Args TTLValidator::createArgs() const { } bool TTLValidator::can() const { - return _peer->isUser() + return (_peer->isUser() + && !_peer->isSelf() + && !_peer->isNotificationsUser()) || (_peer->isChat() && _peer->asChat()->canDeleteMessages()) || (_peer->isChannel() @@ -116,4 +119,8 @@ const style::icon *TTLValidator::icon() const { return &st::menuIconTTL; } +void TTLValidator::showBox() const { + _show->showBox(Box(TTLBox, createArgs())); +} + } // namespace TTLMenu diff --git a/Telegram/SourceFiles/menu/menu_ttl_validator.h b/Telegram/SourceFiles/menu/menu_ttl_validator.h index eb737baf35..4f0862c9a8 100644 --- a/Telegram/SourceFiles/menu/menu_ttl_validator.h +++ b/Telegram/SourceFiles/menu/menu_ttl_validator.h @@ -24,6 +24,7 @@ public: std::shared_ptr show, not_null peer); + void showBox() const; [[nodiscard]] bool can() const; [[nodiscard]] Args createArgs() const; void showToast() const; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 5ecb719348..8f5c34cbab 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -779,14 +779,11 @@ void Filler::addTTLSubmenu(bool addSeparator) { if (!validator.can()) { return; } - _addAction(PeerMenuCallback::Args{ - .text = tr::lng_manage_messages_ttl_menu(tr::now), - .handler = nullptr, - .icon = validator.icon(), - .fillSubmenu = [=](not_null menu) { - TTLMenu::FillTTLMenu(menu, validator.createArgs()); - }, - }); + const auto text = tr::lng_manage_messages_ttl_menu(tr::now) + + (_peer->messagesTTL() + ? ('\t' + Ui::FormatTTLTiny(_peer->messagesTTL())) + : QString()); + _addAction(text, [=] { validator.showBox(); }, validator.icon()); if (addSeparator) { _addAction(PeerMenuCallback::Args{ .isSeparator = true }); } @@ -836,7 +833,6 @@ void Filler::fillHistoryActions() { addThemeEdit(); addViewDiscussion(); addExportChat(); - addTTLSubmenu(false); addReport(); addClearHistory(); addDeleteChat(); @@ -844,8 +840,8 @@ void Filler::fillHistoryActions() { } void Filler::fillProfileActions() { - addSupportInfo(); addTTLSubmenu(true); + addSupportInfo(); addNewContact(); addShareContact(); addEditContact();