From 3a5ede534e5eee64e50e9812c07546f1efc8dee3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 18 Jun 2020 15:17:58 +0400 Subject: [PATCH] Count all accounts in Core::App().unreadBadge. --- Telegram/SourceFiles/apiwrap.cpp | 2 +- Telegram/SourceFiles/core/application.cpp | 18 ++--- Telegram/SourceFiles/core/application.h | 2 +- Telegram/SourceFiles/data/data_session.cpp | 12 +++- Telegram/SourceFiles/data/data_session.h | 13 ++-- Telegram/SourceFiles/facades.cpp | 18 ----- Telegram/SourceFiles/facades.h | 43 +++--------- .../admin_log/history_admin_log_section.cpp | 5 +- .../SourceFiles/history/history_widget.cpp | 17 +++-- .../view/history_view_top_bar_widget.cpp | 12 ++-- Telegram/SourceFiles/main/main_account.cpp | 25 +++---- Telegram/SourceFiles/main/main_account.h | 10 +-- Telegram/SourceFiles/main/main_accounts.cpp | 67 ++++++++++++++++++- Telegram/SourceFiles/main/main_accounts.h | 12 ++++ Telegram/SourceFiles/main/main_session.cpp | 2 - Telegram/SourceFiles/main/main_session.h | 7 -- Telegram/SourceFiles/main/main_settings.cpp | 35 +++++++--- Telegram/SourceFiles/main/main_settings.h | 17 ++++- Telegram/SourceFiles/mainwidget.cpp | 4 +- Telegram/SourceFiles/mainwidget.h | 7 ++ Telegram/SourceFiles/mainwindow.cpp | 2 +- .../SourceFiles/mtproto/mtproto_config.cpp | 4 +- .../platform/mac/main_window_mac.mm | 2 +- .../platform/mac/window_title_mac.mm | 10 ++- .../profile/profile_back_button.cpp | 22 ++++-- .../SourceFiles/profile/profile_back_button.h | 13 +++- .../SourceFiles/settings/settings_codes.cpp | 11 --- .../details/storage_settings_scheme.cpp | 10 ++- .../storage/details/storage_settings_scheme.h | 2 +- .../SourceFiles/storage/storage_account.cpp | 6 -- .../SourceFiles/storage/storage_accounts.cpp | 8 ++- Telegram/SourceFiles/window/main_window.cpp | 7 +- Telegram/SourceFiles/window/main_window.h | 2 +- .../window/notifications_manager.cpp | 3 +- 34 files changed, 255 insertions(+), 175 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index bcb3aaedb9..4a59480c31 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -245,7 +245,7 @@ ApiWrap::ApiWrap(not_null session) , _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); }) , _selfDestruct(std::make_unique(this)) , _sensitiveContent(std::make_unique(this)) { - crl::on_main([=] { + crl::on_main(session, [=] { // You can't use _session->lifetime() in the constructor, // only queued, because it is not constructed yet. _session->uploader().photoReady( diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index cd8f4eaef1..859684f0d8 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -512,10 +512,6 @@ void Application::handleAppDeactivated() { Ui::Tooltip::Hide(); } -void Application::call_handleUnreadCounterUpdate() { - Global::RefUnreadCounterUpdate().notify(true); -} - void Application::call_handleObservables() { base::HandleObservables(); } @@ -575,17 +571,15 @@ bool Application::exportPreventsQuit() { } int Application::unreadBadge() const { - if (const auto session = maybeActiveSession()) { - return session->data().unreadBadge(); - } - return 0; + return accounts().unreadBadge(); } bool Application::unreadBadgeMuted() const { - if (const auto session = maybeActiveSession()) { - return session->data().unreadBadgeMuted(); - } - return false; + return accounts().unreadBadgeMuted(); +} + +rpl::producer<> Application::unreadBadgeChanges() const { + return accounts().unreadBadgeChanges(); } bool Application::offerLegacyLangPackSwitch() const { diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index e85a3e49b4..9c34d99690 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -164,6 +164,7 @@ public: Main::Session *maybeActiveSession() const; [[nodiscard]] int unreadBadge() const; [[nodiscard]] bool unreadBadgeMuted() const; + [[nodiscard]] rpl::producer<> unreadBadgeChanges() const; // Media component. [[nodiscard]] Media::Audio::Instance &audio() { @@ -232,7 +233,6 @@ public: void switchFreeType(); void writeInstallBetaVersionsSetting(); - void call_handleUnreadCounterUpdate(); void call_handleObservables(); protected: diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index c4108d54dc..f9a8cc0c25 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -236,8 +236,8 @@ Session::Session(not_null session) setupUserIsContactViewer(); _chatsList.unreadStateChanges( - ) | rpl::start_with_next([] { - Notify::unreadCounterUpdated(); + ) | rpl::start_with_next([=] { + notifyUnreadBadgeChanged(); }, _lifetime); } @@ -2082,6 +2082,14 @@ int Session::unreadOnlyMutedBadge() const { : state.chatsMuted; } +rpl::producer<> Session::unreadBadgeChanges() const { + return _unreadBadgeChanges.events(); +} + +void Session::notifyUnreadBadgeChanged() { + _unreadBadgeChanges.fire({}); +} + int Session::computeUnreadBadge(const Dialogs::UnreadState &state) const { const auto all = _session->settings().includeMutedCounter(); return std::max(state.marks - (all ? 0 : state.marksMuted), 0) diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index fe060e8a0f..a024b3c516 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -391,11 +391,13 @@ public: -> rpl::producer; void updateSendActionAnimation(SendActionAnimationUpdate &&update); - int unreadBadge() const; - bool unreadBadgeMuted() const; - int unreadBadgeIgnoreOne(const Dialogs::Key &key) const; - bool unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const; - int unreadOnlyMutedBadge() const; + [[nodiscard]] int unreadBadge() const; + [[nodiscard]] bool unreadBadgeMuted() const; + [[nodiscard]] int unreadBadgeIgnoreOne(const Dialogs::Key &key) const; + [[nodiscard]] bool unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const; + [[nodiscard]] int unreadOnlyMutedBadge() const; + [[nodiscard]] rpl::producer<> unreadBadgeChanges() const; + void notifyUnreadBadgeChanged(); void selfDestructIn(not_null item, crl::time delay); @@ -809,6 +811,7 @@ private: rpl::event_stream _megagroupParticipantAdded; rpl::event_stream _dialogsRowReplacements; rpl::event_stream _chatListEntryRefreshes; + rpl::event_stream<> _unreadBadgeChanges; Dialogs::MainList _chatsList; Dialogs::IndexedList _contactsList; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 8e72aed3dc..dd878c9540 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -311,10 +311,6 @@ bool switchInlineBotButtonReceived( return false; } -void unreadCounterUpdated() { - Global::RefHandleUnreadCounterUpdate().call(); -} - } // namespace Notify #define DefineReadOnlyVar(Namespace, Type, Name) const Type &Name() { \ @@ -336,8 +332,6 @@ namespace Global { namespace internal { struct Data { - SingleQueuedInvokation HandleUnreadCounterUpdate = { [] { Core::App().call_handleUnreadCounterUpdate(); } }; - Adaptive::WindowLayout AdaptiveWindowLayout = Adaptive::WindowLayout::Normal; Adaptive::ChatLayout AdaptiveChatLayout = Adaptive::ChatLayout::Normal; bool AdaptiveForWide = true; @@ -348,16 +342,12 @@ struct Data { bool ScreenIsLocked = false; - int32 DebugLoggingFlags = 0; - float64 RememberedSongVolume = kDefaultVolume; float64 SongVolume = kDefaultVolume; base::Observable SongVolumeChanged; float64 VideoVolume = kDefaultVolume; base::Observable VideoVolumeChanged; - HiddenPinnedMessagesMap HiddenPinnedMessages; - bool AskDownloadPath = false; QString DownloadPath; QByteArray DownloadPathBookmark; @@ -388,7 +378,6 @@ struct Data { base::Variable WorkMode = { dbiwmWindowAndTray }; - base::Observable UnreadCounterUpdate; base::Observable PeerChooseCancel; QString CallOutputDeviceID = qsl("default"); @@ -418,8 +407,6 @@ void finish() { GlobalData = nullptr; } -DefineRefVar(Global, SingleQueuedInvokation, HandleUnreadCounterUpdate); - DefineVar(Global, Adaptive::WindowLayout, AdaptiveWindowLayout); DefineVar(Global, Adaptive::ChatLayout, AdaptiveChatLayout); DefineVar(Global, bool, AdaptiveForWide); @@ -430,16 +417,12 @@ DefineVar(Global, bool, ModerateModeEnabled); DefineVar(Global, bool, ScreenIsLocked); -DefineVar(Global, int32, DebugLoggingFlags); - DefineVar(Global, float64, RememberedSongVolume); DefineVar(Global, float64, SongVolume); DefineRefVar(Global, base::Observable, SongVolumeChanged); DefineVar(Global, float64, VideoVolume); DefineRefVar(Global, base::Observable, VideoVolumeChanged); -DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages); - DefineVar(Global, bool, AskDownloadPath); DefineVar(Global, QString, DownloadPath); DefineVar(Global, QByteArray, DownloadPathBookmark); @@ -470,7 +453,6 @@ DefineRefVar(Global, base::Observable, LocalPasscodeChanged); DefineRefVar(Global, base::Variable, WorkMode); -DefineRefVar(Global, base::Observable, UnreadCounterUpdate); DefineRefVar(Global, base::Observable, PeerChooseCancel); DefineVar(Global, QString, CallOutputDeviceID); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index f83201facc..56693bcf16 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -132,19 +132,13 @@ enum class ChatLayout { } // namespace Adaptive -namespace DebugLogging { -enum Flags { - FileLoaderFlag = 0x00000001, -}; -} // namespace DebugLogging - namespace Global { bool started(); void start(); void finish(); -DeclareRefVar(SingleQueuedInvokation, HandleUnreadCounterUpdate); +DeclareVar(bool, ScreenIsLocked); DeclareVar(Adaptive::WindowLayout, AdaptiveWindowLayout); DeclareVar(Adaptive::ChatLayout, AdaptiveChatLayout); @@ -154,26 +148,17 @@ DeclareRefVar(base::Observable, AdaptiveChanged); DeclareVar(bool, DialogsFiltersEnabled); DeclareVar(bool, ModerateModeEnabled); -DeclareVar(bool, ScreenIsLocked); - -DeclareVar(int32, DebugLoggingFlags); - -constexpr float64 kDefaultVolume = 0.9; +constexpr auto kDefaultVolume = 0.9; DeclareVar(float64, RememberedSongVolume); DeclareVar(float64, SongVolume); DeclareRefVar(base::Observable, SongVolumeChanged); DeclareVar(float64, VideoVolume); DeclareRefVar(base::Observable, VideoVolumeChanged); - -typedef QMap HiddenPinnedMessagesMap; -DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages); - DeclareVar(bool, AskDownloadPath); DeclareVar(QString, DownloadPath); DeclareVar(QByteArray, DownloadPathBookmark); DeclareRefVar(base::Observable, DownloadPathChanged); - DeclareVar(bool, VoiceMsgPlaybackDoubled); DeclareVar(bool, SoundNotify); DeclareVar(bool, DesktopNotify); @@ -181,9 +166,16 @@ DeclareVar(bool, FlashBounceNotify); DeclareVar(bool, RestoreSoundNotifyFromTray); DeclareVar(bool, RestoreFlashBounceNotifyFromTray); DeclareVar(DBINotifyView, NotifyView); -DeclareVar(bool, NativeNotifications); DeclareVar(int, NotificationsCount); DeclareVar(Notify::ScreenCorner, NotificationsCorner); + +DeclareVar(QString, CallOutputDeviceID); +DeclareVar(QString, CallInputDeviceID); +DeclareVar(int, CallOutputVolume); +DeclareVar(int, CallInputVolume); +DeclareVar(bool, CallAudioDuckingEnabled); + +DeclareVar(bool, NativeNotifications); DeclareVar(bool, NotificationsDemoIsShown); DeclareVar(bool, TryIPv6); @@ -199,15 +191,8 @@ DeclareRefVar(base::Observable, LocalPasscodeChanged); DeclareRefVar(base::Variable, WorkMode); -DeclareRefVar(base::Observable, UnreadCounterUpdate); DeclareRefVar(base::Observable, PeerChooseCancel); -DeclareVar(QString, CallOutputDeviceID); -DeclareVar(QString, CallInputDeviceID); -DeclareVar(int, CallOutputVolume); -DeclareVar(int, CallInputVolume); -DeclareVar(bool, CallAudioDuckingEnabled); - } // namespace Global namespace Adaptive { @@ -238,11 +223,3 @@ inline bool ChatWide() { } } // namespace Adaptive - -namespace DebugLogging { - -inline bool FileLoader() { - return (Global::DebugLoggingFlags() & FileLoaderFlag) != 0; -} - -} // namespace DebugLogging diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index d836c9d8a9..fb44bd9888 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -107,7 +107,10 @@ FixedBar::FixedBar( , _controller(controller) , _channel(channel) , _field(this, st::historyAdminLogSearchField, tr::lng_dlg_filter()) -, _backButton(this, tr::lng_admin_log_title_all(tr::now)) +, _backButton( + this, + &controller->session(), + tr::lng_admin_log_title_all(tr::now)) , _search(this, st::topBarSearch) , _cancel(this, st::historyAdminLogCancelSearch) , _filter(this, tr::lng_admin_log_filter(), st::topBarButton) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 5f3630eecf..3d603cc46a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5683,14 +5683,13 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() { auto result = false; auto pinnedId = _peer->pinnedMessageId(); if (pinnedId && !_peer->canPinMessages()) { - auto it = Global::HiddenPinnedMessages().constFind(_peer->id); - if (it != Global::HiddenPinnedMessages().cend()) { - if (it.value() == pinnedId) { - pinnedId = 0; - } else { - Global::RefHiddenPinnedMessages().remove(_peer->id); - session().local().writeSettings(); - } + const auto hiddenId = session().settings().hiddenPinnedMessageId( + _peer->id); + if (hiddenId == pinnedId) { + pinnedId = 0; + } else if (hiddenId) { + session().settings().setHiddenPinnedMessageId(_peer->id, 0); + session().local().writeSettings(); } } if (pinnedId) { @@ -6020,7 +6019,7 @@ void HistoryWidget::hidePinnedMessage() { _peer->isChannel() ? peerToChannel(_peer->id) : NoChannel, pinnedId)); } else { - Global::RefHiddenPinnedMessages().insert(_peer->id, pinnedId); + session().settings().setHiddenPinnedMessageId(_peer->id, pinnedId); session().local().writeSettings(); if (pinnedMsgVisibilityUpdated()) { updateControlsGeometry(); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 94c5928be5..1f16ba8280 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -747,10 +747,7 @@ void TopBarWidget::updateAdaptiveLayout() { void TopBarWidget::refreshUnreadBadge() { if (!Adaptive::OneColumn() && !_activeChat.folder()) { - if (_unreadBadge) { - unsubscribe(base::take(_unreadCounterSubscription)); - _unreadBadge.destroy(); - } + _unreadBadge.destroy(); return; } else if (_unreadBadge) { return; @@ -768,9 +765,10 @@ void TopBarWidget::refreshUnreadBadge() { _unreadBadge->show(); _unreadBadge->setAttribute(Qt::WA_TransparentForMouseEvents); - _unreadCounterSubscription = subscribe( - Global::RefUnreadCounterUpdate(), - [=] { updateUnreadBadge(); }); + _controller->session().data().unreadBadgeChanges( + ) | rpl::start_with_next([=] { + updateUnreadBadge(); + }, _unreadBadge->lifetime()); updateUnreadBadge(); } diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index 2e690139ae..5bcac3d19e 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -55,8 +55,6 @@ Account::~Account() { session().saveSettingsNowIfNeeded(); } destroySession(); - _mtpValue.reset(nullptr); - base::take(_mtp); } [[nodiscard]] Storage::StartResult Account::legacyStart( @@ -65,23 +63,17 @@ Account::~Account() { const auto result = _local->legacyStart(passcode); if (result == Storage::StartResult::Success) { - finishStarting(nullptr); + start(nullptr); } return result; } -void Account::start(std::shared_ptr localKey) { - finishStarting(_local->start(std::move(localKey))); +std::unique_ptr Account::prepareToStart( + std::shared_ptr localKey) { + return _local->start(std::move(localKey)); } -void Account::startAdded( - std::shared_ptr localKey, - std::unique_ptr config) { - _local->startAdded(std::move(localKey)); - finishStarting(std::move(config)); -} - -void Account::finishStarting(std::unique_ptr config) { +void Account::start(std::unique_ptr config) { startMtp(config ? std::move(config) : std::make_unique( @@ -91,6 +83,11 @@ void Account::finishStarting(std::unique_ptr config) { watchSessionChanges(); } +void Account::prepareToStartAdded( + std::shared_ptr localKey) { + _local->startAdded(std::move(localKey)); +} + void Account::watchProxyChanges() { using ProxyChange = Core::Application::ProxyChange; @@ -189,8 +186,6 @@ void Account::destroySession() { _sessionValue = nullptr; _session = nullptr; - - Notify::unreadCounterUpdated(); } bool Account::sessionExists() const { diff --git a/Telegram/SourceFiles/main/main_account.h b/Telegram/SourceFiles/main/main_account.h index eefdcd8a01..f4ffcbf166 100644 --- a/Telegram/SourceFiles/main/main_account.h +++ b/Telegram/SourceFiles/main/main_account.h @@ -37,10 +37,11 @@ public: [[nodiscard]] Storage::StartResult legacyStart( const QByteArray &passcode); - void start(std::shared_ptr localKey); - void startAdded( - std::shared_ptr localKey, - std::unique_ptr config); + [[nodiscard]] std::unique_ptr prepareToStart( + std::shared_ptr localKey); + void prepareToStartAdded( + std::shared_ptr localKey); + void start(std::unique_ptr config); [[nodiscard]] UserId willHaveUserId() const; void createSession(const MTPUser &user); @@ -105,7 +106,6 @@ private: QByteArray serialized, int streamVersion, Settings &&settings); - void finishStarting(std::unique_ptr config); void watchProxyChanges(); void watchSessionChanges(); bool checkForUpdates(const mtpPrime *from, const mtpPrime *end); diff --git a/Telegram/SourceFiles/main/main_accounts.cpp b/Telegram/SourceFiles/main/main_accounts.cpp index 27a86c356e..8979fd5ed1 100644 --- a/Telegram/SourceFiles/main/main_accounts.cpp +++ b/Telegram/SourceFiles/main/main_accounts.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/shortcuts.h" #include "main/main_account.h" #include "main/main_session.h" +#include "data/data_session.h" #include "mtproto/mtproto_config.h" #include "mtproto/mtproto_dc_options.h" #include "storage/storage_accounts.h" @@ -35,10 +36,10 @@ Storage::StartResult Accounts::start(const QByteArray &passcode) { const auto result = _local->start(passcode); if (result == Storage::StartResult::Success) { + activateAfterStarting(); if (Local::oldSettingsVersion() < AppVersion) { Local::writeSettings(); } - activateAfterStarting(); } else { Assert(!started()); } @@ -123,6 +124,52 @@ rpl::producer Accounts::activeSessionValue() const { return rpl::single(current) | rpl::then(_activeSessions.events()); } +int Accounts::unreadBadge() const { + return _unreadBadge; +} + +bool Accounts::unreadBadgeMuted() const { + return _unreadBadgeMuted; +} + +rpl::producer<> Accounts::unreadBadgeChanges() const { + return _unreadBadgeChanges.events(); +} + +void Accounts::notifyUnreadBadgeChanged() { + for (const auto &[index, account] : _accounts) { + if (account->sessionExists()) { + account->session().data().notifyUnreadBadgeChanged(); + } + } +} + +void Accounts::updateUnreadBadge() { + _unreadBadge = 0; + _unreadBadgeMuted = true; + for (const auto &[index, account] : _accounts) { + if (account->sessionExists()) { + const auto data = &account->session().data(); + _unreadBadge += data->unreadBadge(); + if (!data->unreadBadgeMuted()) { + _unreadBadgeMuted = false; + } + } + } + _unreadBadgeChanges.fire({}); +} + +void Accounts::scheduleUpdateUnreadBadge() { + if (_unreadBadgeUpdateScheduled) { + return; + } + _unreadBadgeUpdateScheduled = true; + Core::App().postponeCall(crl::guard(&Core::App(), [=] { + _unreadBadgeUpdateScheduled = false; + updateUnreadBadge(); + })); +} + int Accounts::add(MTP::Environment environment) { Expects(_active.current() != nullptr); @@ -159,10 +206,21 @@ int Accounts::add(MTP::Environment environment) { } void Accounts::watchSession(not_null account) { + account->sessionValue( + ) | rpl::filter([=](Session *session) { + return session != nullptr; + }) | rpl::start_with_next([=](Session *session) { + session->data().unreadBadgeChanges( + ) | rpl::start_with_next([=] { + scheduleUpdateUnreadBadge(); + }, session->lifetime()); + }, account->lifetime()); + account->sessionChanges( ) | rpl::filter([=](Session *session) { - return !session; // removeRedundantAccounts may remove passcode lock. + return !session; }) | rpl::start_with_next([=] { + scheduleUpdateUnreadBadge(); if (account == _active.current()) { activateAuthedAccount(); } @@ -238,13 +296,16 @@ void Accounts::checkForLastProductionConfig( void Accounts::activate(int index) { Expects(_accounts.contains(index)); + const auto changed = (_activeIndex != index); _activeLifetime.destroy(); _activeIndex = index; _active = _accounts.find(index)->second.get(); _active.current()->sessionValue( ) | rpl::start_to_stream(_activeSessions, _activeLifetime); - scheduleWriteAccounts(); + if (changed) { + scheduleWriteAccounts(); + } } void Accounts::scheduleWriteAccounts() { diff --git a/Telegram/SourceFiles/main/main_accounts.h b/Telegram/SourceFiles/main/main_accounts.h index e51d700d7b..53dd134375 100644 --- a/Telegram/SourceFiles/main/main_accounts.h +++ b/Telegram/SourceFiles/main/main_accounts.h @@ -47,6 +47,11 @@ public: [[nodiscard]] rpl::producer activeSessionValue() const; [[nodiscard]] rpl::producer activeSessionChanges() const; + [[nodiscard]] int unreadBadge() const; + [[nodiscard]] bool unreadBadgeMuted() const; + [[nodiscard]] rpl::producer<> unreadBadgeChanges() const; + void notifyUnreadBadgeChanged(); + [[nodiscard]] int add(MTP::Environment environment); void activate(int index); @@ -61,6 +66,8 @@ private: void watchSession(not_null account); void scheduleWriteAccounts(); void checkForLastProductionConfig(not_null account); + void updateUnreadBadge(); + void scheduleUpdateUnreadBadge(); const QString _dataName; const std::unique_ptr _local; @@ -72,6 +79,11 @@ private: rpl::event_stream _activeSessions; + rpl::event_stream<> _unreadBadgeChanges; + int _unreadBadge = 0; + bool _unreadBadgeMuted = true; + bool _unreadBadgeUpdateScheduled = false; + rpl::lifetime _activeLifetime; rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index e9e72babe5..8855c6febe 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "api/api_updates.h" #include "core/application.h" -#include "core/changelogs.h" #include "main/main_account.h" #include "mtproto/mtproto_config.h" #include "chat_helpers/stickers_emoji_pack.h" @@ -81,7 +80,6 @@ Session::Session( , _user(_data->processUser(user)) , _emojiStickersPack(std::make_unique(this)) , _diceStickersPacks(std::make_unique(this)) -, _changelogs(Core::Changelogs::Create(this)) , _supportHelper(Support::Helper::Create(this)) { Core::App().lockChanges( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index 43d3cf47a6..5dc5aedce1 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -57,10 +57,6 @@ class EmojiPack; class DicePacks; } // namespace Stickers; -namespace Core { -class Changelogs; -} // namespace Core - namespace Main { class Account; @@ -180,9 +176,6 @@ private: const std::unique_ptr _emojiStickersPack; const std::unique_ptr _diceStickersPacks; - // _changelogs depends on _data, subscribes on chats loading event. - const std::unique_ptr _changelogs; - const std::unique_ptr _supportHelper; base::flat_set> _windows; diff --git a/Telegram/SourceFiles/main/main_settings.cpp b/Telegram/SourceFiles/main/main_settings.cpp index 37f3db2782..895783ee6a 100644 --- a/Telegram/SourceFiles/main/main_settings.cpp +++ b/Telegram/SourceFiles/main/main_settings.cpp @@ -52,13 +52,14 @@ bool Settings::ThirdColumnByDefault() { QByteArray Settings::serialize() const { const auto autoDownload = _variables.autoDownload.serialize(); auto size = sizeof(qint32) * 38; - for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) { - size += Serialize::stringSize(i.key()) + Serialize::stringSize(i.value()); + for (const auto &[key, value] : _variables.soundOverrides) { + size += Serialize::stringSize(key) + Serialize::stringSize(value); } size += _variables.groupStickersSectionHidden.size() * sizeof(quint64); size += _variables.mediaLastPlaybackPosition.size() * 2 * sizeof(quint64); size += Serialize::bytearraySize(autoDownload); size += Serialize::bytearraySize(_variables.videoPipGeometry); + size += sizeof(qint32) + _variables.hiddenPinnedMessages.size() * (sizeof(quint64) + sizeof(qint32)); auto result = QByteArray(); result.reserve(size); @@ -70,8 +71,8 @@ QByteArray Settings::serialize() const { stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0); stream << qint32(_variables.tabbedSelectorSectionEnabled ? 1 : 0); stream << qint32(_variables.soundOverrides.size()); - for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) { - stream << i.key() << i.value(); + for (const auto &[key, value] : _variables.soundOverrides) { + stream << key << value; } stream << qint32(_variables.tabbedSelectorSectionTooltipShown); stream << qint32(_variables.floatPlayerColumn); @@ -122,6 +123,10 @@ QByteArray Settings::serialize() const { stream << quint64(i); } stream << qint32(_variables.autoDownloadDictionaries.current() ? 1 : 0); + stream << qint32(_variables.hiddenPinnedMessages.size()); + for (const auto &[key, value] : _variables.hiddenPinnedMessages) { + stream << quint64(key) << qint32(value); + } } return result; } @@ -141,7 +146,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { qint32 tabbedSelectorSectionTooltipShown = 0; qint32 floatPlayerColumn = static_cast(Window::Column::Second); qint32 floatPlayerCorner = static_cast(RectPart::TopRight); - QMap soundOverrides; + base::flat_map soundOverrides; base::flat_set groupStickersSectionHidden; qint32 thirdSectionInfoEnabled = 0; qint32 smallDialogsList = 0; @@ -176,6 +181,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { QByteArray videoPipGeometry = _variables.videoPipGeometry; std::vector dictionariesEnabled; qint32 autoDownloadDictionaries = _variables.autoDownloadDictionaries.current() ? 1 : 0; + base::flat_map hiddenPinnedMessages; stream >> versionTag; if (versionTag == kVersionTag) { @@ -195,7 +201,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { for (auto i = 0; i != count; ++i) { QString key, value; stream >> key >> value; - soundOverrides[key] = value; + soundOverrides.emplace(key, value); } } } @@ -316,6 +322,18 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> autoDownloadDictionaries; } + if (!stream.atEnd()) { + auto count = qint32(0); + stream >> count; + if (stream.status() == QDataStream::Ok) { + for (auto i = 0; i != count; ++i) { + auto key = quint64(); + auto value = qint32(); + stream >> key >> value; + hiddenPinnedMessages.emplace(key, value); + } + } + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Main::Settings::constructFromSerialized()")); @@ -407,6 +425,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { _variables.videoPipGeometry = videoPipGeometry; _variables.dictionariesEnabled = std::move(dictionariesEnabled); _variables.autoDownloadDictionaries = (autoDownloadDictionaries == 1); + _variables.hiddenPinnedMessages = std::move(hiddenPinnedMessages); } void Settings::setSupportChatsTimeSlice(int slice) { @@ -470,9 +489,9 @@ void Settings::setTabbedReplacedWithInfo(bool enabled) { } QString Settings::getSoundPath(const QString &key) const { - auto it = _variables.soundOverrides.constFind(key); + auto it = _variables.soundOverrides.find(key); if (it != _variables.soundOverrides.end()) { - return it.value(); + return it->second; } return qsl(":/sounds/") + key + qsl(".mp3"); } diff --git a/Telegram/SourceFiles/main/main_settings.h b/Telegram/SourceFiles/main/main_settings.h index 264f51f05a..cd874a491f 100644 --- a/Telegram/SourceFiles/main/main_settings.h +++ b/Telegram/SourceFiles/main/main_settings.h @@ -112,7 +112,7 @@ public: return _variables.smallDialogsList; } void setSoundOverride(const QString &key, const QString &path) { - _variables.soundOverrides.insert(key, path); + _variables.soundOverrides.emplace(key, path); } void clearSoundOverrides() { _variables.soundOverrides.clear(); @@ -279,6 +279,18 @@ public: _variables.videoPipGeometry = geometry; } + [[nodiscard]] MsgId hiddenPinnedMessageId(PeerId peerId) const { + const auto i = _variables.hiddenPinnedMessages.find(peerId); + return (i != end(_variables.hiddenPinnedMessages)) ? i->second : 0; + } + void setHiddenPinnedMessageId(PeerId peerId, MsgId msgId) { + if (msgId) { + _variables.hiddenPinnedMessages[peerId] = msgId; + } else { + _variables.hiddenPinnedMessages.remove(peerId); + } + } + [[nodiscard]] static bool ThirdColumnByDefault(); private: @@ -294,7 +306,7 @@ private: ChatHelpers::SelectorTab selectorTab; // per-window bool tabbedSelectorSectionEnabled = false; // per-window int tabbedSelectorSectionTooltipShown = 0; - QMap soundOverrides; + base::flat_map soundOverrides; Window::Column floatPlayerColumn; // per-window RectPart floatPlayerCorner; // per-window base::flat_set groupStickersSectionHidden; @@ -325,6 +337,7 @@ private: QByteArray videoPipGeometry; rpl::variable> dictionariesEnabled; rpl::variable autoDownloadDictionaries = true; + base::flat_map hiddenPinnedMessages; static constexpr auto kDefaultSupportChatsLimitSlice = 7 * 24 * 60 * 60; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 0441df09fb..67cd656ce0 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -90,6 +90,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "core/shortcuts.h" #include "core/application.h" +#include "core/changelogs.h" #include "base/unixtime.h" #include "calls/calls_instance.h" #include "calls/calls_top_bar.h" @@ -233,7 +234,8 @@ MainWidget::MainWidget( , _history(this, _controller) , _playerPlaylist(this, _controller) , _cacheBackgroundTimer([=] { cacheBackground(); }) -, _viewsIncrementTimer([=] { viewsIncrement(); }) { +, _viewsIncrementTimer([=] { viewsIncrement(); }) +, _changelogs(Core::Changelogs::Create(&controller->session())) { _controller->setDefaultFloatPlayerDelegate(floatPlayerDelegate()); _controller->floatPlayerClosed( ) | rpl::start_with_next([=](FullMsgId itemId) { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 6c9033a3ee..217ed65b44 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -88,6 +88,10 @@ class Call; class TopBar; } // namespace Calls +namespace Core { +class Changelogs; +} // namespace Core + namespace InlineBots { namespace Layout { class ItemBase; @@ -410,6 +414,9 @@ private: bool _firstColumnResizing = false; int _firstColumnResizingShift = 0; + // _changelogs depends on _data, subscribes on chats loading event. + const std::unique_ptr _changelogs; + }; namespace App { diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 01d166aa7b..fd5816331b 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -737,7 +737,7 @@ void MainWindow::showFromTray(QSystemTrayIcon::ActivationReason reason) { updateGlobalMenu(); }); activate(); - Notify::unreadCounterUpdated(); + updateUnreadCounter(); } } diff --git a/Telegram/SourceFiles/mtproto/mtproto_config.cpp b/Telegram/SourceFiles/mtproto/mtproto_config.cpp index 8b862ac6d6..7d8a050772 100644 --- a/Telegram/SourceFiles/mtproto/mtproto_config.cpp +++ b/Telegram/SourceFiles/mtproto/mtproto_config.cpp @@ -110,7 +110,7 @@ std::unique_ptr Config::FromSerialized(const QByteArray &serialized) { auto dcOptionsSerialized = QByteArray(); const auto read = [&](auto &field) { - using Type = std::decay_t(); + using Type = std::remove_reference_t; if constexpr (std::is_same_v || std::is_same_v>) { auto value = qint32(); @@ -123,6 +123,8 @@ std::unique_ptr Config::FromSerialized(const QByteArray &serialized) { field = (value == 1); } else if constexpr (std::is_same_v || std::is_same_v) { + stream >> field; + } else { static_assert(false_(field), "Bad read() call."); } }; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 64ee4253ab..4a3f2ec62e 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -196,7 +196,7 @@ private: } - (void) darkModeChanged:(NSNotification *)aNotification { - Notify::unreadCounterUpdated(); + Core::App().accounts().notifyUnreadBadgeChanged(); } - (void) screenIsLocked:(NSNotification *)aNotification { diff --git a/Telegram/SourceFiles/platform/mac/window_title_mac.mm b/Telegram/SourceFiles/platform/mac/window_title_mac.mm index 339af9ba97..b5428524f2 100644 --- a/Telegram/SourceFiles/platform/mac/window_title_mac.mm +++ b/Telegram/SourceFiles/platform/mac/window_title_mac.mm @@ -10,17 +10,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "ui/widgets/shadow.h" #include "ui/image/image_prepare.h" +#include "core/application.h" #include "styles/style_window.h" #include "styles/style_media_view.h" #include "platform/platform_main_window.h" -#include "facades.h" #include #include namespace Platform { -TitleWidget::TitleWidget(MainWindow *parent, int height) : Window::TitleWidget(parent) +TitleWidget::TitleWidget(MainWindow *parent, int height) +: Window::TitleWidget(parent) , _shadow(this, st::titleShadow) { setAttribute(Qt::WA_OpaquePaintEvent); resize(width(), height); @@ -41,7 +42,10 @@ TitleWidget::TitleWidget(MainWindow *parent, int height) : Window::TitleWidget(p _font = st::normalFont; } - subscribe(Global::RefUnreadCounterUpdate(), [this] { update(); }); + Core::App().unreadBadgeValue( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); } void TitleWidget::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/profile/profile_back_button.cpp b/Telegram/SourceFiles/profile/profile_back_button.cpp index 709026c6fc..2e6158653b 100644 --- a/Telegram/SourceFiles/profile/profile_back_button.cpp +++ b/Telegram/SourceFiles/profile/profile_back_button.cpp @@ -8,19 +8,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "profile/profile_back_button.h" //#include "history/view/history_view_top_bar_widget.h" -#include "facades.h" +#include "main/main_session.h" +#include "data/data_session.h" #include "styles/style_widgets.h" #include "styles/style_window.h" #include "styles/style_profile.h" #include "styles/style_info.h" +#include "facades.h" namespace Profile { -BackButton::BackButton(QWidget *parent, const QString &text) : Ui::AbstractButton(parent) +BackButton::BackButton( + QWidget *parent, + not_null session, + const QString &text) +: Ui::AbstractButton(parent) +, _session(session) , _text(text.toUpper()) { setCursor(style::cur_pointer); - subscribe(Adaptive::Changed(), [this] { updateAdaptiveLayout(); }); + subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); }); updateAdaptiveLayout(); } @@ -52,11 +59,12 @@ void BackButton::onStateChanged(State was, StateChangeSource source) { void BackButton::updateAdaptiveLayout() { if (!Adaptive::OneColumn()) { - unsubscribe(base::take(_unreadCounterSubscription)); - } else if (!_unreadCounterSubscription) { - _unreadCounterSubscription = subscribe(Global::RefUnreadCounterUpdate(), [this] { + _unreadBadgeLifetime.destroy(); + } else if (!_unreadBadgeLifetime) { + _session->data().unreadBadgeChanges( + ) | rpl::start_with_next([=] { rtlupdate(0, 0, st::titleUnreadCounterRight, st::titleUnreadCounterTop); - }); + }, _unreadBadgeLifetime); } } diff --git a/Telegram/SourceFiles/profile/profile_back_button.h b/Telegram/SourceFiles/profile/profile_back_button.h index 8a45a5fac9..a3037fce2e 100644 --- a/Telegram/SourceFiles/profile/profile_back_button.h +++ b/Telegram/SourceFiles/profile/profile_back_button.h @@ -9,11 +9,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/abstract_button.h" +namespace Main { +class Session; +} // namespace Main + namespace Profile { class BackButton final : public Ui::AbstractButton, private base::Subscriber { public: - BackButton(QWidget *parent, const QString &text); + BackButton( + QWidget *parent, + not_null session, + const QString &text); void setText(const QString &text); @@ -26,7 +33,9 @@ protected: private: void updateAdaptiveLayout(); - int _unreadCounterSubscription = 0; + const not_null _session; + + rpl::lifetime _unreadBadgeLifetime; QString _text; }; diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index a1d72d1f39..2d43386c76 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -58,17 +58,6 @@ auto GenerateCodes() { codes.emplace(qsl("loadlang"), [](SessionController *window) { Lang::CurrentCloudManager().switchToLanguage({ qsl("#custom") }); }); - codes.emplace(qsl("debugfiles"), [](SessionController *window) { - if (!Logs::DebugEnabled()) { - return; - } - if (DebugLogging::FileLoader()) { - Global::RefDebugLoggingFlags() &= ~DebugLogging::FileLoaderFlag; - } else { - Global::RefDebugLoggingFlags() |= DebugLogging::FileLoaderFlag; - } - Ui::show(Box(DebugLogging::FileLoader() ? qsl("Enabled file download logging") : qsl("Disabled file download logging"))); - }); codes.emplace(qsl("crashplease"), [](SessionController *window) { Unexpected("Crashed in Settings!"); }); diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 70686c5b36..8f1e6808fb 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -955,12 +955,16 @@ bool ReadSetting( cSetEmojiVariants(v); } break; - case dbiHiddenPinnedMessages: { - Global::HiddenPinnedMessagesMap v; + case dbiHiddenPinnedMessagesOld: { + auto v = QMap(); stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetHiddenPinnedMessages(v); + for (auto i = v.begin(), e = v.end(); i != e; ++i) { + context.sessionSettings().setHiddenPinnedMessageId( + i.key(), + i.value()); + } } break; case dbiDialogLastPath: { diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h index 654f23b2f5..b4bc1a6de4 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h @@ -124,7 +124,7 @@ enum { dbiShowingSavedGifsOld = 0x36, dbiAutoPlayOld = 0x37, dbiAdaptiveForWide = 0x38, - dbiHiddenPinnedMessages = 0x39, + dbiHiddenPinnedMessagesOld = 0x39, dbiRecentEmoji = 0x3a, dbiEmojiVariants = 0x3b, dbiDialogsModeOld = 0x40, diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 8daa289aa7..36a6567ce1 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -798,9 +798,6 @@ void Account::writeSettings(Main::Settings *stored) { size += sizeof(quint32) + 3 * sizeof(qint32); size += sizeof(quint32) + 2 * sizeof(qint32); size += sizeof(quint32) + sizeof(qint64) + sizeof(qint32); - if (!Global::HiddenPinnedMessages().isEmpty()) { - size += sizeof(quint32) + sizeof(qint32) + Global::HiddenPinnedMessages().size() * (sizeof(PeerId) + sizeof(MsgId)); - } if (!userData.isEmpty()) { size += sizeof(quint32) + Serialize::bytearraySize(userData); } @@ -837,9 +834,6 @@ void Account::writeSettings(Main::Settings *stored) { data.stream << quint32(dbiRecentEmoji) << recentEmojiPreloadData; data.stream << quint32(dbiEmojiVariants) << cEmojiVariants(); data.stream << quint32(dbiRecentStickers) << recentStickers; - if (!Global::HiddenPinnedMessages().isEmpty()) { - data.stream << quint32(dbiHiddenPinnedMessages) << Global::HiddenPinnedMessages(); - } data.stream << qint32(dbiCallSettings) << callSettings; FileWriteDescriptor file(_settingsKey, _basePath); diff --git a/Telegram/SourceFiles/storage/storage_accounts.cpp b/Telegram/SourceFiles/storage/storage_accounts.cpp index 09e06bf91e..5626226a18 100644 --- a/Telegram/SourceFiles/storage/storage_accounts.cpp +++ b/Telegram/SourceFiles/storage/storage_accounts.cpp @@ -73,7 +73,8 @@ void Accounts::startAdded( std::unique_ptr config) { Expects(_localKey != nullptr); - account->startAdded(_localKey, std::move(config)); + account->prepareToStartAdded(_localKey); + account->start(std::move(config)); } void Accounts::startWithSingleAccount( @@ -86,7 +87,7 @@ void Accounts::startWithSingleAccount( encryptLocalKey(passcode); } else { generateLocalKey(); - account->start(_localKey); + account->start(account->prepareToStart(_localKey)); } _owner->accountAddedInStorage(0, std::move(account)); writeAccounts(); @@ -178,10 +179,11 @@ Accounts::StartModernResult Accounts::startModern( && index < kMaxAccounts && tried.emplace(index).second) { auto account = std::make_unique(_dataName, index); - account->start(_localKey); + auto config = account->prepareToStart(_localKey); const auto userId = account->willHaveUserId(); if (!users.contains(userId) && (userId != 0 || (users.empty() && i + 1 == count))) { + account->start(std::move(config)); _owner->accountAddedInStorage(index, std::move(account)); users.emplace(userId); } diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 195c67e5c6..64051c4f28 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -133,9 +133,12 @@ MainWindow::MainWindow(not_null controller) updatePalette(); } }); - subscribe(Global::RefUnreadCounterUpdate(), [=] { + + Core::App().unreadBadgeChanges( + ) | rpl::start_with_next([=] { updateUnreadCounter(); - }); + }, lifetime()); + subscribe(Global::RefWorkMode(), [=](DBIWorkMode mode) { workmodeUpdated(mode); }); diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 43e28f7281..ad95a91a37 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -170,10 +170,10 @@ protected: void attachToTrayIcon(not_null icon); virtual void handleTrayIconActication( QSystemTrayIcon::ActivationReason reason) = 0; + void updateUnreadCounter(); private: void updatePalette(); - void updateUnreadCounter(); void initSize(); bool computeIsActive() const; diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 8902445b9d..cbb36adeba 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_updates.h" #include "apiwrap.h" #include "main/main_session.h" +#include "main/main_accounts.h" #include "facades.h" #include "app.h" @@ -60,7 +61,7 @@ System::System(not_null session) updateAll(); } else if (type == ChangeType::IncludeMuted || type == ChangeType::CountMessages) { - Notify::unreadCounterUpdated(); + Core::App().accounts().notifyUnreadBadgeChanged(); } }); }