diff --git a/Telegram/Resources/icons/menu/sound_disable.png b/Telegram/Resources/icons/menu/sound_disable.png new file mode 100644 index 0000000000..75b6855f67 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_disable.png differ diff --git a/Telegram/Resources/icons/menu/sound_disable@2x.png b/Telegram/Resources/icons/menu/sound_disable@2x.png new file mode 100644 index 0000000000..61cd255845 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_disable@2x.png differ diff --git a/Telegram/Resources/icons/menu/sound_disable@3x.png b/Telegram/Resources/icons/menu/sound_disable@3x.png new file mode 100644 index 0000000000..7206794581 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_disable@3x.png differ diff --git a/Telegram/Resources/icons/menu/sound_enable.png b/Telegram/Resources/icons/menu/sound_enable.png new file mode 100644 index 0000000000..ae80664c20 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_enable.png differ diff --git a/Telegram/Resources/icons/menu/sound_enable@2x.png b/Telegram/Resources/icons/menu/sound_enable@2x.png new file mode 100644 index 0000000000..57f11693c9 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_enable@2x.png differ diff --git a/Telegram/Resources/icons/menu/sound_enable@3x.png b/Telegram/Resources/icons/menu/sound_enable@3x.png new file mode 100644 index 0000000000..c91d56032b Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_enable@3x.png differ diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6902ec66a2..e21f026faf 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -899,11 +899,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_mute_menu_duration" = "Mute for..."; "lng_mute_menu_duration_forever" = "Mute forever"; "lng_mute_menu_duration_unmute" = "Unmute"; -"lng_mute_menu_sound_on" = "Sound On"; -"lng_mute_menu_sound_off" = "Sound Off"; +"lng_mute_menu_sound_on" = "Enable sound"; +"lng_mute_menu_sound_off" = "Disable sound"; "lng_mute_box_title" = "Mute notifications for..."; -"lng_mute_box_no_notifications" = "No notifications"; -"lng_mute_box_silent_notifications" = "Silent notifications"; "lng_mute_box_days#one" = "{count} day"; "lng_mute_box_days#other" = "{count} days"; "lng_mute_box_hours#one" = "{count} hour"; diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index 928a5d1f7b..cc21e1550c 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "info/profile/info_profile_values.h" #include "lang/lang_keys.h" -#include "menu/menu_check_item.h" #include "ui/boxes/choose_time.h" #include "ui/effects/animation_value.h" #include "ui/layers/generic_box.h" @@ -99,99 +98,28 @@ void MuteItem::paintEvent(QPaintEvent *e) { icon.paint(p, _itemIconPosition, width(), color); } -void FillSoundMenu( - not_null menu, - not_null peer, - rpl::producer &&soundOnText, - rpl::producer &&soundOffText, - Fn notifySound) { - const auto createView = [&](rpl::producer &&text, bool checked) { - auto item = base::make_unique_q( - menu->menu(), - st::popupMenuWithIcons.menu, - new QAction(QString(), menu->menu()), - nullptr, - nullptr); - std::move( - text - ) | rpl::start_with_next([action = item->action()](QString text) { - action->setText(text); - }, item->lifetime()); - item->init(checked); - const auto view = item->checkView(); - menu->addAction(std::move(item)); - return view; - }; - - const auto soundIsNone = peer->owner().notifySoundIsNone(peer); - const auto soundOn = createView(std::move(soundOnText), !soundIsNone); - const auto soundOff = createView(std::move(soundOffText), soundIsNone); - - soundOn->checkedChanges( - ) | rpl::start_with_next([=](bool checked) { - soundOff->setChecked(!checked, anim::type::normal); - notifySound(!checked); - }, menu->lifetime()); - soundOff->checkedChanges( - ) | rpl::start_with_next([=](bool checked) { - soundOn->setChecked(!checked, anim::type::normal); - notifySound(checked); - }, menu->lifetime()); -} - void MuteBox(not_null box, not_null peer) { struct State { - base::unique_qptr menu; - rpl::variable noSoundChanges; int lastSeconds = 0; }; auto chooseTimeResult = ChooseTimeWidget(box, kMuteDurSecondsDefault); box->addRow(std::move(chooseTimeResult.widget)); - const auto state = box->lifetime().make_state(State{ - .noSoundChanges = false, - }); + const auto state = box->lifetime().make_state(); box->setTitle(tr::lng_mute_box_title()); - const auto topButton = box->addTopButton(st::infoTopBarMenu); - topButton->setClickedCallback([=] { - if (state->menu) { - return; - } - state->menu = base::make_unique_q( - topButton, - st::popupMenuWithIcons); - FillSoundMenu( - state->menu.get(), - peer, - tr::lng_mute_box_no_notifications(), - tr::lng_mute_box_silent_notifications(), - [=](bool silent) { - state->noSoundChanges = silent; - }); - state->menu->popup(QCursor::pos()); - return; - }); - - auto confirmText = rpl::combine( - std::move(chooseTimeResult.secondsValue), - state->noSoundChanges.value() - ) | rpl::map([=](int seconds, bool noSound) { + auto confirmText = std::move( + chooseTimeResult.secondsValue + ) | rpl::map([=](int seconds) { state->lastSeconds = seconds; return !seconds ? tr::lng_mute_menu_unmute() - : noSound - ? tr::lng_mute_box_silent_notifications() : tr::lng_mute_menu_mute(); }) | rpl::flatten_latest(); const auto confirm = box->addButton(std::move(confirmText), [=] { - peer->owner().updateNotifySettings( - peer, - state->lastSeconds, - std::nullopt, - state->noSoundChanges.current()); + peer->owner().updateNotifySettings(peer, state->lastSeconds); box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); @@ -204,16 +132,16 @@ void FillMuteMenu( Args args) { const auto peer = args.peer; - FillSoundMenu( - menu, - peer, - tr::lng_mute_menu_sound_on(), - tr::lng_mute_menu_sound_off(), - [peer](bool silent) { - peer->owner().updateNotifySettings(peer, {}, {}, silent); - }); - - menu->addSeparator(); + const auto soundIsNone = peer->owner().notifySoundIsNone(peer); + menu->addAction( + soundIsNone + ? tr::lng_mute_menu_sound_on(tr::now) + : tr::lng_mute_menu_sound_off(tr::now), + [=] { + const auto soundIsNone = peer->owner().notifySoundIsNone(peer); + peer->owner().updateNotifySettings(peer, {}, {}, !soundIsNone); + }, + soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff); menu->addAction( tr::lng_mute_menu_duration(tr::now), diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index f2f95e0c8f..ff6aec0a4c 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -97,6 +97,8 @@ menuIconViolence: icon {{ "menu/violence", menuIconColor }}; menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }}; menuIconSilent: icon {{ "menu/silent", menuIconColor }}; menuIconCustomize: icon {{ "menu/customize", menuIconColor }}; +menuIconSoundOn: icon {{ "menu/sound_enable", menuIconColor }}; +menuIconSoundOff: icon {{ "menu/sound_disable", menuIconColor }}; menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }}; menuIconTTLAnyTextPosition: point(11px, 22px); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 5f12f764e8..5ecb719348 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -133,7 +133,7 @@ void PeerMenuAddMuteSubmenuAction( peer->owner().requestNotifySettings(peer); const auto isMuted = peer->owner().notifyIsMuted(peer); if (isMuted) { - const auto text = tr::lng_mute_menu_unmute(tr::now) + const auto text = tr::lng_context_unmute(tr::now) + '\t' + Ui::FormatMuteForTiny(peer->notifyMuteUntil().value_or(0) - base::unixtime::now()); @@ -143,7 +143,7 @@ void PeerMenuAddMuteSubmenuAction( } else { const auto show = std::make_shared(controller); addAction(PeerMenuCallback::Args{ - .text = tr::lng_mute_menu_mute(tr::now), + .text = tr::lng_context_mute(tr::now), .handler = nullptr, .icon = peer->owner().notifySoundIsNone(peer) ? &st::menuIconSilent