diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 226242206e..d45013a876 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -133,13 +133,13 @@ InnerWidget::InnerWidget( update(); }, lifetime()); - subscribe(Core::App().notifications().settingsChanged(), [=]( - Window::Notifications::ChangeType change) { + Core::App().notifications().settingsChanged( + ) | rpl::start_with_next([=](Window::Notifications::ChangeType change) { if (change == Window::Notifications::ChangeType::CountMessages) { // Folder rows change their unread badge with this setting. update(); } - }); + }, lifetime()); session().data().contactsLoaded().changes( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index bb39fb390c..6c4341cdb6 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -756,13 +756,13 @@ void MainWindow::toggleDisplayNotifyFromTray() { } account().session().saveSettings(); using Change = Window::Notifications::ChangeType; - auto &changes = Core::App().notifications().settingsChanged(); - changes.notify(Change::DesktopEnabled); + auto ¬ifications = Core::App().notifications(); + notifications.notifySettingsChanged(Change::DesktopEnabled); if (soundNotifyChanged) { - changes.notify(Change::SoundEnabled); + notifications.notifySettingsChanged(Change::SoundEnabled); } if (flashBounceNotifyChanged) { - changes.notify(Change::FlashBounceEnabled); + notifications.notifySettingsChanged(Change::FlashBounceEnabled); } } diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index cca41e9c0a..5a7ae8052d 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -193,7 +193,7 @@ void NotificationsCount::setCount(int count) { if (count != Core::App().settings().notificationsCount()) { Core::App().settings().setNotificationsCount(count); Core::App().saveSettingsDelayed(); - Core::App().notifications().settingsChanged().notify( + Core::App().notifications().notifySettingsChanged( ChangeType::MaxCount); } } @@ -357,7 +357,7 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) { _isOverCorner = true; setCursor(style::cur_pointer); Global::SetNotificationsDemoIsShown(true); - Core::App().notifications().settingsChanged().notify( + Core::App().notifications().notifySettingsChanged( ChangeType::DemoIsShown); } _overCorner = corner; @@ -393,7 +393,8 @@ void NotificationsCount::clearOverCorner() { _isOverCorner = false; setCursor(style::cur_default); Global::SetNotificationsDemoIsShown(false); - Core::App().notifications().settingsChanged().notify(ChangeType::DemoIsShown); + Core::App().notifications().notifySettingsChanged( + ChangeType::DemoIsShown); for_const (const auto &samples, _cornerSamples) { for_const (const auto widget, samples) { @@ -420,7 +421,7 @@ void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) { if (_chosenCorner != Core::App().settings().notificationsCorner()) { Core::App().settings().setNotificationsCorner(_chosenCorner); Core::App().saveSettingsDelayed(); - Core::App().notifications().settingsChanged().notify( + Core::App().notifications().notifySettingsChanged( ChangeType::Corner); } } @@ -740,7 +741,7 @@ void SetupNotificationsContent( using Change = Window::Notifications::ChangeType; const auto changed = [=](Change change) { Core::App().saveSettingsDelayed(); - Core::App().notifications().settingsChanged().notify(change); + Core::App().notifications().notifySettingsChanged(change); }; desktop->checkedChanges( ) | rpl::filter([](bool checked) { @@ -812,8 +813,7 @@ void SetupNotificationsContent( changed(Change::CountMessages); }, count->lifetime()); - base::ObservableViewer( - Core::App().notifications().settingsChanged() + Core::App().notifications().settingsChanged( ) | rpl::start_with_next([=](Change change) { if (change == Change::DesktopEnabled) { desktop->setChecked(Core::App().settings().desktopNotify()); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index f2d6896d1c..d8a755b6e6 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -52,7 +52,8 @@ constexpr auto kSystemAlertDuration = crl::time(0); System::System() : _waitTimer([=] { showNext(); }) , _waitForAllGroupedTimer([=] { showGrouped(); }) { - subscribe(settingsChanged(), [=](ChangeType type) { + settingsChanged( + ) | rpl::start_with_next([=](ChangeType type) { if (type == ChangeType::DesktopEnabled) { clearAll(); } else if (type == ChangeType::ViewParams) { @@ -61,7 +62,7 @@ System::System() || type == ChangeType::CountMessages) { Core::App().domain().notifyUnreadBadgeChanged(); } - }); + }, lifetime()); } void System::createManager() { @@ -578,6 +579,14 @@ void System::updateAll() { } } +rpl::producer System::settingsChanged() const { + return _settingsChanged.events(); +} + +void System::notifySettingsChanged(ChangeType type) { + return _settingsChanged.fire(std::move(type)); +} + Manager::DisplayOptions Manager::getNotificationOptions( HistoryItem *item) const { const auto hideEverything = Core::App().passcodeLocked() diff --git a/Telegram/SourceFiles/window/notifications_manager.h b/Telegram/SourceFiles/window/notifications_manager.h index 3bba4b872d..998618cf4c 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -71,7 +71,7 @@ namespace Notifications { class Manager; -class System final : private base::Subscriber { +class System final { public: System(); ~System(); @@ -92,8 +92,11 @@ public: void clearAllFast(); void updateAll(); - base::Observable &settingsChanged() { - return _settingsChanged; + [[nodiscard]] rpl::producer settingsChanged() const; + void notifySettingsChanged(ChangeType type); + + [[nodiscard]] rpl::lifetime &lifetime() { + return _lifetime; } private: @@ -132,7 +135,7 @@ private: std::unique_ptr _manager; - base::Observable _settingsChanged; + rpl::event_stream _settingsChanged; std::unique_ptr _soundTrack; @@ -140,6 +143,8 @@ private: uint64 _lastHistorySessionId = 0; FullMsgId _lastHistoryItemId; + rpl::lifetime _lifetime; + }; class Manager { diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index d13a3cf8b9..48f937b0ea 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -73,9 +73,10 @@ std::unique_ptr Create(System *system) { Manager::Manager(System *system) : Notifications::Manager(system) , _inputCheckTimer([=] { checkLastInput(); }) { - subscribe(system->settingsChanged(), [this](ChangeType change) { + system->settingsChanged( + ) | rpl::start_with_next([=](ChangeType change) { settingsChanged(change); - }); + }, system->lifetime()); } Manager::QueuedNotification::QueuedNotification( diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index b418a943c5..6d973c317f 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -38,7 +38,7 @@ class HideAllButton; class Manager; std::unique_ptr Create(System *system); -class Manager final : public Notifications::Manager, private base::Subscriber { +class Manager final : public Notifications::Manager { public: Manager(System *system); ~Manager();