2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 22:46:10 +00:00

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

@@ -194,7 +194,7 @@ void ShowCallsBox(not_null<Window::SessionController*> window) {
class MainMenu::ToggleAccountsButton final : public Ui::AbstractButton {
public:
explicit ToggleAccountsButton(QWidget *parent);
ToggleAccountsButton(QWidget *parent, not_null<Main::Account*> current);
[[nodiscard]] int rightSkip() const {
return _rightSkip.current();
@@ -210,6 +210,7 @@ private:
void validateUnreadBadge();
[[nodiscard]] QString computeUnreadBadge() const;
const not_null<Main::Account*> _current;
rpl::variable<int> _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<Main::Account*> 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<Info::Profile::EmojiStatusPanel>())
, _badge(std::make_unique<Info::Profile::Badge>(
@@ -975,13 +979,13 @@ void MainMenu::initResetScaleButton() {
}, lifetime());
}
OthersUnreadState OtherAccountsUnreadStateCurrent() {
OthersUnreadState OtherAccountsUnreadStateCurrent(
not_null<Main::Account*> 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<OthersUnreadState> OtherAccountsUnreadState() {
rpl::producer<OthersUnreadState> OtherAccountsUnreadState(
not_null<Main::Account*> current) {
return rpl::single(rpl::empty) | rpl::then(
Core::App().unreadBadgeChanges()
) | rpl::map(OtherAccountsUnreadStateCurrent);
) | rpl::map([=] {
return OtherAccountsUnreadStateCurrent(current);
});
}
} // namespace Window