Correctly count 'other accounts unread' in menu.

This commit is contained in:
John Preston 2024-09-16 13:02:38 +04:00
parent 592d46c8f2
commit 3658b32db5
4 changed files with 23 additions and 12 deletions

View file

@ -891,6 +891,7 @@ void Widget::setupMainMenuToggle() {
}, lifetime()); }, lifetime());
Window::OtherAccountsUnreadState( Window::OtherAccountsUnreadState(
&controller()->session().account()
) | rpl::start_with_next([=](const Window::OthersUnreadState &state) { ) | rpl::start_with_next([=](const Window::OthersUnreadState &state) {
const auto icon = !state.count const auto icon = !state.count
? nullptr ? nullptr

View file

@ -160,6 +160,7 @@ void FiltersMenu::setup() {
void FiltersMenu::setupMainMenuIcon() { void FiltersMenu::setupMainMenuIcon() {
OtherAccountsUnreadState( OtherAccountsUnreadState(
&_session->session().account()
) | rpl::start_with_next([=](const OthersUnreadState &state) { ) | rpl::start_with_next([=](const OthersUnreadState &state) {
const auto icon = !state.count const auto icon = !state.count
? nullptr ? nullptr

View file

@ -194,7 +194,7 @@ void ShowCallsBox(not_null<Window::SessionController*> window) {
class MainMenu::ToggleAccountsButton final : public Ui::AbstractButton { class MainMenu::ToggleAccountsButton final : public Ui::AbstractButton {
public: public:
explicit ToggleAccountsButton(QWidget *parent); ToggleAccountsButton(QWidget *parent, not_null<Main::Account*> current);
[[nodiscard]] int rightSkip() const { [[nodiscard]] int rightSkip() const {
return _rightSkip.current(); return _rightSkip.current();
@ -210,6 +210,7 @@ private:
void validateUnreadBadge(); void validateUnreadBadge();
[[nodiscard]] QString computeUnreadBadge() const; [[nodiscard]] QString computeUnreadBadge() const;
const not_null<Main::Account*> _current;
rpl::variable<int> _rightSkip = 0; rpl::variable<int> _rightSkip = 0;
Ui::Animations::Simple _toggledAnimation; Ui::Animations::Simple _toggledAnimation;
bool _toggled = false; bool _toggled = false;
@ -230,8 +231,11 @@ protected:
}; };
MainMenu::ToggleAccountsButton::ToggleAccountsButton(QWidget *parent) MainMenu::ToggleAccountsButton::ToggleAccountsButton(
: AbstractButton(parent) { QWidget *parent,
not_null<Main::Account*> current)
: AbstractButton(parent)
, _current(current) {
rpl::single(rpl::empty) | rpl::then( rpl::single(rpl::empty) | rpl::then(
Core::App().unreadBadgeChanges() Core::App().unreadBadgeChanges()
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
@ -320,7 +324,7 @@ void MainMenu::ToggleAccountsButton::validateUnreadBadge() {
} }
QString MainMenu::ToggleAccountsButton::computeUnreadBadge() const { QString MainMenu::ToggleAccountsButton::computeUnreadBadge() const {
const auto state = OtherAccountsUnreadStateCurrent(); const auto state = OtherAccountsUnreadStateCurrent(_current);
return state.allMuted return state.allMuted
? QString() ? QString()
: (state.count > 0) : (state.count > 0)
@ -381,7 +385,7 @@ MainMenu::MainMenu(
this, this,
_controller->session().user(), _controller->session().user(),
st::mainMenuUserpic) st::mainMenuUserpic)
, _toggleAccounts(this) , _toggleAccounts(this, &controller->session().account())
, _setEmojiStatus(this, SetStatusLabel(&controller->session())) , _setEmojiStatus(this, SetStatusLabel(&controller->session()))
, _emojiStatusPanel(std::make_unique<Info::Profile::EmojiStatusPanel>()) , _emojiStatusPanel(std::make_unique<Info::Profile::EmojiStatusPanel>())
, _badge(std::make_unique<Info::Profile::Badge>( , _badge(std::make_unique<Info::Profile::Badge>(
@ -975,13 +979,13 @@ void MainMenu::initResetScaleButton() {
}, lifetime()); }, lifetime());
} }
OthersUnreadState OtherAccountsUnreadStateCurrent() { OthersUnreadState OtherAccountsUnreadStateCurrent(
not_null<Main::Account*> current) {
auto &domain = Core::App().domain(); auto &domain = Core::App().domain();
const auto active = &domain.active();
auto counter = 0; auto counter = 0;
auto allMuted = true; auto allMuted = true;
for (const auto &[index, account] : domain.accounts()) { for (const auto &[index, account] : domain.accounts()) {
if (account.get() == active) { if (account.get() == current) {
continue; continue;
} else if (const auto session = account->maybeSession()) { } else if (const auto session = account->maybeSession()) {
counter += session->data().unreadBadge(); counter += session->data().unreadBadge();
@ -996,10 +1000,13 @@ OthersUnreadState OtherAccountsUnreadStateCurrent() {
}; };
} }
rpl::producer<OthersUnreadState> OtherAccountsUnreadState() { rpl::producer<OthersUnreadState> OtherAccountsUnreadState(
not_null<Main::Account*> current) {
return rpl::single(rpl::empty) | rpl::then( return rpl::single(rpl::empty) | rpl::then(
Core::App().unreadBadgeChanges() Core::App().unreadBadgeChanges()
) | rpl::map(OtherAccountsUnreadStateCurrent); ) | rpl::map([=] {
return OtherAccountsUnreadStateCurrent(current);
});
} }
} // namespace Window } // namespace Window

View file

@ -108,7 +108,9 @@ struct OthersUnreadState {
bool allMuted = false; bool allMuted = false;
}; };
[[nodiscard]] OthersUnreadState OtherAccountsUnreadStateCurrent(); [[nodiscard]] OthersUnreadState OtherAccountsUnreadStateCurrent(
[[nodiscard]] rpl::producer<OthersUnreadState> OtherAccountsUnreadState(); not_null<Main::Account*> current);
[[nodiscard]] rpl::producer<OthersUnreadState> OtherAccountsUnreadState(
not_null<Main::Account*> current);
} // namespace Window } // namespace Window