mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Correctly count 'other accounts unread' in menu.
This commit is contained in:
parent
592d46c8f2
commit
3658b32db5
4 changed files with 23 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -108,7 +108,9 @@ struct OthersUnreadState {
|
|||
bool allMuted = false;
|
||||
};
|
||||
|
||||
[[nodiscard]] OthersUnreadState OtherAccountsUnreadStateCurrent();
|
||||
[[nodiscard]] rpl::producer<OthersUnreadState> OtherAccountsUnreadState();
|
||||
[[nodiscard]] OthersUnreadState OtherAccountsUnreadStateCurrent(
|
||||
not_null<Main::Account*> current);
|
||||
[[nodiscard]] rpl::producer<OthersUnreadState> OtherAccountsUnreadState(
|
||||
not_null<Main::Account*> current);
|
||||
|
||||
} // namespace Window
|
||||
|
|
Loading…
Add table
Reference in a new issue