Create notifications manager after reading settings.

This commit is contained in:
John Preston 2020-06-30 11:44:32 +04:00
parent 0db6fc4ffb
commit c3fa300b5c
3 changed files with 31 additions and 10 deletions

View file

@ -183,6 +183,7 @@ void Application::run() {
refreshGlobalProxy(); // Depends on Global::start(). refreshGlobalProxy(); // Depends on Global::start().
// Depends on OpenSSL on macOS, so on ThirdParty::start(). // Depends on OpenSSL on macOS, so on ThirdParty::start().
// Depends on notifications settings.
_notifications = std::make_unique<Window::Notifications::System>(); _notifications = std::make_unique<Window::Notifications::System>();
startLocalStorage(); startLocalStorage();

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/storage_account.h" #include "storage/storage_account.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "export/export_settings.h" #include "export/export_settings.h"
#include "window/notifications_manager.h"
#include "facades.h" #include "facades.h"
namespace Main { namespace Main {
@ -28,6 +29,7 @@ Domain::Domain(const QString &dataName)
_active.changes( _active.changes(
) | rpl::take(1) | rpl::start_with_next([] { ) | rpl::take(1) | rpl::start_with_next([] {
Local::rewriteSettingsIfNeeded(); Local::rewriteSettingsIfNeeded();
Core::App().notifications().createManager();
}, _lifetime); }, _lifetime);
} }

View file

@ -52,8 +52,6 @@ constexpr auto kSystemAlertDuration = crl::time(0);
System::System() System::System()
: _waitTimer([=] { showNext(); }) : _waitTimer([=] { showNext(); })
, _waitForAllGroupedTimer([=] { showGrouped(); }) { , _waitForAllGroupedTimer([=] { showGrouped(); }) {
createManager();
subscribe(settingsChanged(), [=](ChangeType type) { subscribe(settingsChanged(), [=](ChangeType type) {
if (type == ChangeType::DesktopEnabled) { if (type == ChangeType::DesktopEnabled) {
App::wnd()->updateTrayMenu(); App::wnd()->updateTrayMenu();
@ -174,7 +172,9 @@ void System::schedule(not_null<HistoryItem*> item) {
} }
void System::clearAll() { void System::clearAll() {
_manager->clearAll(); if (_manager) {
_manager->clearAll();
}
for (auto i = _whenMaps.cbegin(), e = _whenMaps.cend(); i != e; ++i) { for (auto i = _whenMaps.cbegin(), e = _whenMaps.cend(); i != e; ++i) {
i->first->clearNotifications(); i->first->clearNotifications();
@ -186,7 +186,9 @@ void System::clearAll() {
} }
void System::clearFromHistory(not_null<History*> history) { void System::clearFromHistory(not_null<History*> history) {
_manager->clearFromHistory(history); if (_manager) {
_manager->clearFromHistory(history);
}
history->clearNotifications(); history->clearNotifications();
_whenMaps.remove(history); _whenMaps.remove(history);
@ -199,7 +201,9 @@ void System::clearFromHistory(not_null<History*> history) {
} }
void System::clearFromSession(not_null<Main::Session*> session) { void System::clearFromSession(not_null<Main::Session*> session) {
_manager->clearFromSession(session); if (_manager) {
_manager->clearFromSession(session);
}
for (auto i = _whenMaps.begin(); i != _whenMaps.end();) { for (auto i = _whenMaps.begin(); i != _whenMaps.end();) {
const auto history = i->first; const auto history = i->first;
@ -228,17 +232,23 @@ void System::clearFromSession(not_null<Main::Session*> session) {
} }
void System::clearIncomingFromHistory(not_null<History*> history) { void System::clearIncomingFromHistory(not_null<History*> history) {
_manager->clearFromHistory(history); if (_manager) {
_manager->clearFromHistory(history);
}
history->clearIncomingNotifications(); history->clearIncomingNotifications();
_whenAlerts.remove(history); _whenAlerts.remove(history);
} }
void System::clearFromItem(not_null<HistoryItem*> item) { void System::clearFromItem(not_null<HistoryItem*> item) {
_manager->clearFromItem(item); if (_manager) {
_manager->clearFromItem(item);
}
} }
void System::clearAllFast() { void System::clearAllFast() {
_manager->clearAllFast(); if (_manager) {
_manager->clearAllFast();
}
_whenMaps.clear(); _whenMaps.clear();
_whenAlerts.clear(); _whenAlerts.clear();
@ -293,6 +303,8 @@ void System::checkDelayed() {
} }
void System::showGrouped() { void System::showGrouped() {
Expects(_manager != nullptr);
if (const auto session = findSession(_lastHistorySessionId)) { if (const auto session = findSession(_lastHistorySessionId)) {
if (const auto lastItem = session->data().message(_lastHistoryItemId)) { if (const auto lastItem = session->data().message(_lastHistoryItemId)) {
_waitForAllGroupedTimer.cancel(); _waitForAllGroupedTimer.cancel();
@ -305,7 +317,11 @@ void System::showGrouped() {
} }
void System::showNext() { void System::showNext() {
if (App::quitting()) return; Expects(_manager != nullptr);
if (App::quitting()) {
return;
}
const auto isSameGroup = [=](HistoryItem *item) { const auto isSameGroup = [=](HistoryItem *item) {
if (!_lastHistorySessionId || !_lastHistoryItemId || !item) { if (!_lastHistorySessionId || !_lastHistoryItemId || !item) {
@ -536,7 +552,9 @@ void System::ensureSoundCreated() {
} }
void System::updateAll() { void System::updateAll() {
_manager->updateAll(); if (_manager) {
_manager->updateAll();
}
} }
Manager::DisplayOptions Manager::GetNotificationOptions(HistoryItem *item) { Manager::DisplayOptions Manager::GetNotificationOptions(HistoryItem *item) {