diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index 30da9fadc..dc10deb78 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -15,9 +15,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/choose_time.h" #include "ui/effects/animation_value.h" #include "ui/layers/generic_box.h" +#include "ui/text/format_values.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/menu/menu_action.h" #include "ui/widgets/popup_menu.h" +#include "ui/boxes/time_picker_box.h" #include "styles/style_boxes.h" #include "styles/style_info.h" // infoTopBarMenu #include "styles/style_layers.h" @@ -123,11 +125,72 @@ void MuteBox(not_null box, not_null peer) { peer->owner().notifySettings().updateNotifySettings( peer, state->lastSeconds); - box->closeBox(); + box->getDelegate()->hideLayer(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } +void PickMuteBox(not_null box, not_null peer) { + struct State { + base::unique_qptr menu; + }; + const auto seconds = std::vector{ + (60 * 15), + (60 * 30), + (3600 * 1), + (3600 * 2), + (3600 * 3), + (3600 * 4), + (3600 * 8), + (3600 * 12), + (84600 * 1), + (84600 * 2), + (84600 * 3), + (84600 * 7 * 1), + (84600 * 7 * 2), + (84600 * 30 * 1), + (84600 * 30 * 2), + (84600 * 30 * 3), + }; + const auto phrases = ranges::views::all( + seconds + ) | ranges::views::transform(Ui::FormatMuteFor) | ranges::to_vector; + + const auto state = box->lifetime().make_state(); + + const auto pickerCallback = TimePickerBox(box, seconds, phrases, 0); + + box->addButton(tr::lng_mute_menu_mute(), [=] { + peer->owner().notifySettings().updateNotifySettings( + peer, + pickerCallback()); + box->closeBox(); + }); + + box->setTitle(tr::lng_mute_box_title()); + + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); + + const auto top = box->addTopButton(st::infoTopBarMenu); + top->setClickedCallback([=] { + if (state->menu) { + return; + } + state->menu = base::make_unique_q( + top, + st::popupMenuWithIcons); + state->menu->addAction( + tr::lng_manage_messages_ttl_after_custom(tr::now), + [=] { box->getDelegate()->show(Box(MuteBox, peer)); }, + &st::menuIconCustomize); + state->menu->setDestroyedCallback(crl::guard(top, [=] { + top->setForceRippled(false); + })); + top->setForceRippled(true); + state->menu->popup(QCursor::pos()); + }); +} + } // namespace void FillMuteMenu( @@ -149,7 +212,7 @@ void FillMuteMenu( menu->addAction( tr::lng_mute_menu_duration(tr::now), - [=, show = args.show] { show->showBox(Box(MuteBox, peer)); }, + [=, show = args.show] { show->showBox(Box(PickMuteBox, peer)); }, &st::menuIconMuteFor); menu->addAction( diff --git a/Telegram/SourceFiles/ui/text/format_values.cpp b/Telegram/SourceFiles/ui/text/format_values.cpp index 2358cd7fa..19bce1887 100644 --- a/Telegram/SourceFiles/ui/text/format_values.cpp +++ b/Telegram/SourceFiles/ui/text/format_values.cpp @@ -408,6 +408,14 @@ QString FormatTTLTiny(float64 ttl) { : tr::lng_years_tiny({}, lt_count, std::ceil(ttl / (86400 * 360))); } +QString FormatMuteFor(float64 sec) { + return (sec <= 60) + ? tr::lng_seconds(tr::now, lt_count, sec) + : (sec <= 60 * 59) + ? tr::lng_minutes(tr::now, lt_count, std::ceil(sec / 60)) + : FormatTTL(sec); +} + QString FormatMuteForTiny(float64 sec) { return (sec <= 60) ? QString() diff --git a/Telegram/SourceFiles/ui/text/format_values.h b/Telegram/SourceFiles/ui/text/format_values.h index bb77e8078..47adafb97 100644 --- a/Telegram/SourceFiles/ui/text/format_values.h +++ b/Telegram/SourceFiles/ui/text/format_values.h @@ -29,6 +29,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2; [[nodiscard]] QString FormatPhone(const QString &phone); [[nodiscard]] QString FormatTTL(float64 ttl); [[nodiscard]] QString FormatTTLTiny(float64 ttl); +[[nodiscard]] QString FormatMuteFor(float64 sec); [[nodiscard]] QString FormatMuteForTiny(float64 sec); struct CurrencyRule {