diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 50deb411cf..f61c06fa57 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -553,12 +553,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_notification_title_private_chats" = "Notifications for private chats"; "lng_notification_about_private_chats#one" = "Please note that **{count} chat** is listed as an exception and won't be affected by this change."; "lng_notification_about_private_chats#other" = "Please note that **{count} chats** are listed as exceptions and won't be affected by this change."; +"lng_notification_volume_private_chats" = "Notifications volume for private chats"; "lng_notification_title_groups" = "Notifications for groups"; "lng_notification_about_groups#one" = "Please note that **{count} group** is listed as an exception and won't be affected by this change."; "lng_notification_about_groups#other" = "Please note that **{count} groups** are listed as exceptions and won't be affected by this change."; +"lng_notification_volume_groups" = "Notifications volume for groups"; "lng_notification_title_channels" = "Notifications for channels"; "lng_notification_about_channels#one" = "Please note that **{count} channel** is listed as an exception and won't be affected by this change."; "lng_notification_about_channels#other" = "Please note that **{count} channels** are listed as exceptions and won't be affected by this change."; +"lng_notification_volume_channel" = "Notifications volume for channels"; "lng_notification_exceptions_view" = "View exceptions"; "lng_notification_enable" = "Enable notifications"; "lng_notification_sound" = "Sound"; @@ -6335,6 +6338,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_ringtones_box_title" = "Notification Sound"; "lng_ringtones_box_cloud_subtitle" = "Choose your tone"; +"lng_ringtones_box_volume" = "Volume"; "lng_ringtones_box_upload_choose" = "Choose a tone"; "lng_ringtones_box_upload_button" = "Upload Sound"; "lng_ringtones_box_about" = "Right click on any short voice note or MP3 file in chat and select \"Save for Notifications\". It will appear here."; diff --git a/Telegram/SourceFiles/boxes/ringtones_box.cpp b/Telegram/SourceFiles/boxes/ringtones_box.cpp index 4c299c162b..9ae8685597 100644 --- a/Telegram/SourceFiles/boxes/ringtones_box.cpp +++ b/Telegram/SourceFiles/boxes/ringtones_box.cpp @@ -7,8 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/ringtones_box.h" +#include "data/notify/data_peer_notify_volume.h" +#include "data/notify/data_peer_notify_settings.h" #include "api/api_ringtones.h" #include "apiwrap.h" +#include "ui/widgets/continuous_sliders.h" #include "base/call_delayed.h" #include "base/event_filter.h" #include "base/timer_rpl.h" @@ -21,11 +24,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document_media.h" #include "data/data_document_resolver.h" #include "data/data_thread.h" +#include "data/data_peer.h" #include "data/data_session.h" #include "data/notify/data_notify_settings.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "main/main_session_settings.h" #include "media/audio/media_audio.h" +#include "ui/wrap/slide_wrap.h" #include "platform/platform_notifications_manager.h" #include "settings/settings_common.h" #include "ui/boxes/confirm_box.h" @@ -111,7 +117,8 @@ void RingtonesBox( not_null box, not_null session, Data::NotifySound selected, - Fn save) { + Fn save, + Data::VolumeController volumeController) { box->setTitle(tr::lng_ringtones_box_title()); const auto container = box->verticalLayout(); @@ -320,6 +327,14 @@ void RingtonesBox( })); }); + Ui::AddRingtonesVolumeSlider( + container, + state->group->value() | rpl::map([=](int value) { + return value != kNoSoundValue; + }), + tr::lng_ringtones_box_volume(), + volumeController); + box->addSkip(st::ringtonesBoxSkip); Ui::AddDividerText(container, tr::lng_ringtones_box_about()); @@ -345,5 +360,5 @@ void ThreadRingtonesBox( const auto now = thread->owner().notifySettings().sound(thread); RingtonesBox(box, &thread->session(), now, [=](Data::NotifySound sound) { thread->owner().notifySettings().update(thread, {}, {}, sound); - }); + }, Data::ThreadRingtonesVolumeController(thread)); } diff --git a/Telegram/SourceFiles/boxes/ringtones_box.h b/Telegram/SourceFiles/boxes/ringtones_box.h index 48783ce12e..bbc9349767 100644 --- a/Telegram/SourceFiles/boxes/ringtones_box.h +++ b/Telegram/SourceFiles/boxes/ringtones_box.h @@ -13,6 +13,7 @@ namespace Data { struct NotifySound; class Thread; enum class DefaultNotify : uint8_t; +struct VolumeController; } // namespace Data namespace Main { @@ -29,7 +30,8 @@ void RingtonesBox( not_null box, not_null session, Data::NotifySound selected, - Fn save); + Fn save, + Data::VolumeController volumeController); void ThreadRingtonesBox( not_null box, diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index 661ef06727..caf5964c18 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -253,6 +253,7 @@ Descriptor ThreadDescriptor(not_null thread) { .currentSound = currentSound, .updateSound = updateSound, .updateMutePeriod = updateMutePeriod, + .volumeController = Data::ThreadRingtonesVolumeController(thread), }; } @@ -290,6 +291,7 @@ Descriptor DefaultDescriptor( .currentSound = currentSound, .updateSound = updateSound, .updateMutePeriod = updateMutePeriod, + .volumeController = DefaultRingtonesVolumeController(session, type), }; } @@ -304,7 +306,8 @@ void FillMuteMenu( RingtonesBox, session, *currentSound, - descriptor.updateSound)); + descriptor.updateSound, + descriptor.volumeController)); } }; menu->addAction( diff --git a/Telegram/SourceFiles/menu/menu_mute.h b/Telegram/SourceFiles/menu/menu_mute.h index 3050126627..9599de209e 100644 --- a/Telegram/SourceFiles/menu/menu_mute.h +++ b/Telegram/SourceFiles/menu/menu_mute.h @@ -7,10 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "data/notify/data_peer_notify_volume.h" // VolumeController + namespace Data { class Thread; struct NotifySound; enum class DefaultNotify : uint8_t; +struct VolumeController; } // namespace Data namespace Main { @@ -31,6 +34,7 @@ struct Descriptor { Fn()> currentSound; Fn updateSound; Fn updateMutePeriod; + Data::VolumeController volumeController; }; [[nodiscard]] Descriptor ThreadDescriptor(not_null thread); diff --git a/Telegram/SourceFiles/settings/settings_notifications_type.cpp b/Telegram/SourceFiles/settings/settings_notifications_type.cpp index a6a6baf2ba..84dd876f21 100644 --- a/Telegram/SourceFiles/settings/settings_notifications_type.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications_type.cpp @@ -380,6 +380,15 @@ void ExceptionsController::sort() { Unexpected("Type in Title."); } +[[nodiscard]] rpl::producer VolumeSubtitle(Notify type) { + switch (type) { + case Notify::User: return tr::lng_notification_volume_private_chats(); + case Notify::Group: return tr::lng_notification_volume_groups(); + case Notify::Broadcast: return tr::lng_notification_volume_channel(); + } + Unexpected("Type in VolumeSubtitle."); +} + void SetupChecks( not_null container, not_null controller, @@ -479,9 +488,8 @@ void SetupChecks( Ui::AddRingtonesVolumeSlider( toneInner, - true, rpl::single(true), - rpl::single(u"Volume"_q), + VolumeSubtitle(type), DefaultRingtonesVolumeController(session, type)); enabled->toggledValue( diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index bad3f2182d..830652168b 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -36,8 +36,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_updates.h" #include "apiwrap.h" #include "main/main_account.h" -#include "main/main_session.h" #include "main/main_domain.h" +#include "main/main_session.h" +#include "main/main_session_settings.h" #include "ui/text/text_utilities.h" #include @@ -695,9 +696,18 @@ void System::showNext() { if (settings.soundNotify()) { const auto owner = &alertThread->owner(); const auto id = owner->notifySettings().sound(alertThread).id; + auto volume + = owner->session().settings().ringtoneVolume( + alertThread->peer()->id, + alertThread->topicRootId(), + alertThread->monoforumPeerId()); + if (!volume) { + volume = owner->session().settings().ringtoneVolume( + Data::DefaultNotifyType(alertThread->peer())); + } _manager->maybePlaySound(crl::guard(&owner->session(), [=] { const auto track = lookupSound(owner, id); - track->playOnce(); + track->playOnce(volume ? volume * 0.01 : 0); Media::Player::mixer()->suppressAll(track->getLengthMs()); Media::Player::mixer()->scheduleFaderCallback(); }));