Replaced observable in Window::Notifications::System with rpl.

This commit is contained in:
23rd 2021-05-25 16:51:59 +03:00
parent 2c50d3d87b
commit aad38c2809
7 changed files with 38 additions and 23 deletions

View File

@ -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([=] {

View File

@ -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 &notifications = 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);
}
}

View File

@ -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());

View File

@ -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<ChangeType> 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()

View File

@ -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<ChangeType> &settingsChanged() {
return _settingsChanged;
[[nodiscard]] rpl::producer<ChangeType> settingsChanged() const;
void notifySettingsChanged(ChangeType type);
[[nodiscard]] rpl::lifetime &lifetime() {
return _lifetime;
}
private:
@ -132,7 +135,7 @@ private:
std::unique_ptr<Manager> _manager;
base::Observable<ChangeType> _settingsChanged;
rpl::event_stream<ChangeType> _settingsChanged;
std::unique_ptr<Media::Audio::Track> _soundTrack;
@ -140,6 +143,8 @@ private:
uint64 _lastHistorySessionId = 0;
FullMsgId _lastHistoryItemId;
rpl::lifetime _lifetime;
};
class Manager {

View File

@ -73,9 +73,10 @@ std::unique_ptr<Manager> 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(

View File

@ -38,7 +38,7 @@ class HideAllButton;
class Manager;
std::unique_ptr<Manager> Create(System *system);
class Manager final : public Notifications::Manager, private base::Subscriber {
class Manager final : public Notifications::Manager {
public:
Manager(System *system);
~Manager();