From 3658b32db59fb0a4c4024d76a152f158745c2abf Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 16 Sep 2024 13:02:38 +0400 Subject: [PATCH] Correctly count 'other accounts unread' in menu. --- .../SourceFiles/dialogs/dialogs_widget.cpp | 1 + .../window/window_filters_menu.cpp | 1 + .../SourceFiles/window/window_main_menu.cpp | 27 ++++++++++++------- .../SourceFiles/window/window_main_menu.h | 6 +++-- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 44f558c10..5e734ce1c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -891,6 +891,7 @@ void Widget::setupMainMenuToggle() { }, lifetime()); Window::OtherAccountsUnreadState( + &controller()->session().account() ) | rpl::start_with_next([=](const Window::OthersUnreadState &state) { const auto icon = !state.count ? nullptr diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index fe8e6ec86..8578ef3b2 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -160,6 +160,7 @@ void FiltersMenu::setup() { void FiltersMenu::setupMainMenuIcon() { OtherAccountsUnreadState( + &_session->session().account() ) | rpl::start_with_next([=](const OthersUnreadState &state) { const auto icon = !state.count ? nullptr diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 0d222894a..2f97454dd 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -194,7 +194,7 @@ void ShowCallsBox(not_null window) { class MainMenu::ToggleAccountsButton final : public Ui::AbstractButton { public: - explicit ToggleAccountsButton(QWidget *parent); + ToggleAccountsButton(QWidget *parent, not_null current); [[nodiscard]] int rightSkip() const { return _rightSkip.current(); @@ -210,6 +210,7 @@ private: void validateUnreadBadge(); [[nodiscard]] QString computeUnreadBadge() const; + const not_null _current; rpl::variable _rightSkip = 0; Ui::Animations::Simple _toggledAnimation; bool _toggled = false; @@ -230,8 +231,11 @@ protected: }; -MainMenu::ToggleAccountsButton::ToggleAccountsButton(QWidget *parent) -: AbstractButton(parent) { +MainMenu::ToggleAccountsButton::ToggleAccountsButton( + QWidget *parent, + not_null current) +: AbstractButton(parent) +, _current(current) { rpl::single(rpl::empty) | rpl::then( Core::App().unreadBadgeChanges() ) | rpl::start_with_next([=] { @@ -320,7 +324,7 @@ void MainMenu::ToggleAccountsButton::validateUnreadBadge() { } QString MainMenu::ToggleAccountsButton::computeUnreadBadge() const { - const auto state = OtherAccountsUnreadStateCurrent(); + const auto state = OtherAccountsUnreadStateCurrent(_current); return state.allMuted ? QString() : (state.count > 0) @@ -381,7 +385,7 @@ MainMenu::MainMenu( this, _controller->session().user(), st::mainMenuUserpic) -, _toggleAccounts(this) +, _toggleAccounts(this, &controller->session().account()) , _setEmojiStatus(this, SetStatusLabel(&controller->session())) , _emojiStatusPanel(std::make_unique()) , _badge(std::make_unique( @@ -975,13 +979,13 @@ void MainMenu::initResetScaleButton() { }, lifetime()); } -OthersUnreadState OtherAccountsUnreadStateCurrent() { +OthersUnreadState OtherAccountsUnreadStateCurrent( + not_null current) { auto &domain = Core::App().domain(); - const auto active = &domain.active(); auto counter = 0; auto allMuted = true; for (const auto &[index, account] : domain.accounts()) { - if (account.get() == active) { + if (account.get() == current) { continue; } else if (const auto session = account->maybeSession()) { counter += session->data().unreadBadge(); @@ -996,10 +1000,13 @@ OthersUnreadState OtherAccountsUnreadStateCurrent() { }; } -rpl::producer OtherAccountsUnreadState() { +rpl::producer OtherAccountsUnreadState( + not_null current) { return rpl::single(rpl::empty) | rpl::then( Core::App().unreadBadgeChanges() - ) | rpl::map(OtherAccountsUnreadStateCurrent); + ) | rpl::map([=] { + return OtherAccountsUnreadStateCurrent(current); + }); } } // namespace Window diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index 6356f4103..3089151e4 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -108,7 +108,9 @@ struct OthersUnreadState { bool allMuted = false; }; -[[nodiscard]] OthersUnreadState OtherAccountsUnreadStateCurrent(); -[[nodiscard]] rpl::producer OtherAccountsUnreadState(); +[[nodiscard]] OthersUnreadState OtherAccountsUnreadStateCurrent( + not_null current); +[[nodiscard]] rpl::producer OtherAccountsUnreadState( + not_null current); } // namespace Window