mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Fix crash in MainMenu hiding on external logout.
This commit is contained in:
parent
7d0eb3ba8e
commit
d529c60081
1 changed files with 16 additions and 23 deletions
|
@ -101,7 +101,7 @@ private:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void paintUserpic(Painter &p);
|
void paintUserpic(Painter &p);
|
||||||
|
|
||||||
const not_null<Main::Account*> _account;
|
const not_null<Main::Session*> _session;
|
||||||
const style::Menu &_st;
|
const style::Menu &_st;
|
||||||
std::shared_ptr<Data::CloudImageView> _userpicView;
|
std::shared_ptr<Data::CloudImageView> _userpicView;
|
||||||
InMemoryKey _userpicKey = {};
|
InMemoryKey _userpicKey = {};
|
||||||
|
@ -153,7 +153,7 @@ MainMenu::AccountButton::AccountButton(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<Main::Account*> account)
|
not_null<Main::Account*> account)
|
||||||
: RippleButton(parent, st::defaultRippleAnimation)
|
: RippleButton(parent, st::defaultRippleAnimation)
|
||||||
, _account(account)
|
, _session(&account->session())
|
||||||
, _st(st::mainMenu){
|
, _st(st::mainMenu){
|
||||||
const auto height = _st.itemPadding.top()
|
const auto height = _st.itemPadding.top()
|
||||||
+ _st.itemStyle.font->height
|
+ _st.itemStyle.font->height
|
||||||
|
@ -167,33 +167,27 @@ MainMenu::AccountButton::AccountButton(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_account->sessionValue(
|
rpl::single(
|
||||||
) | rpl::filter([=](Main::Session *session) {
|
rpl::empty_value()
|
||||||
return (session != nullptr);
|
) | rpl::then(
|
||||||
}) | rpl::start_with_next([=](not_null<Main::Session*> session) {
|
_session->data().unreadBadgeChanges()
|
||||||
rpl::single(
|
) | rpl::start_with_next([=] {
|
||||||
rpl::empty_value()
|
_unreadBadge = _session->data().unreadBadge();
|
||||||
) | rpl::then(
|
_unreadBadgeMuted = _session->data().unreadBadgeMuted();
|
||||||
session->data().unreadBadgeChanges()
|
update();
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
_unreadBadge = session->data().unreadBadge();
|
|
||||||
_unreadBadgeMuted = session->data().unreadBadgeMuted();
|
|
||||||
update();
|
|
||||||
}, lifetime());
|
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::AccountButton::paintUserpic(Painter &p) {
|
void MainMenu::AccountButton::paintUserpic(Painter &p) {
|
||||||
Expects(_account->sessionExists());
|
|
||||||
|
|
||||||
const auto size = st::mainMenuAccountSize;
|
const auto size = st::mainMenuAccountSize;
|
||||||
const auto iconSize = height() - 2 * _st.itemIconPosition.y();
|
const auto iconSize = height() - 2 * _st.itemIconPosition.y();
|
||||||
const auto shift = (size - iconSize) / 2;
|
const auto shift = (size - iconSize) / 2;
|
||||||
const auto x = _st.itemIconPosition.x() - shift;
|
const auto x = _st.itemIconPosition.x() - shift;
|
||||||
const auto y = (height() - size) / 2;
|
const auto y = (height() - size) / 2;
|
||||||
|
|
||||||
const auto check = (_account == &Core::App().domain().active());
|
const auto check = (&_session->account()
|
||||||
const auto user = _account->session().user();
|
== &Core::App().domain().active());
|
||||||
|
const auto user = _session->user();
|
||||||
if (!check) {
|
if (!check) {
|
||||||
user->paintUserpicLeft(p, _userpicView, x, y, width(), size);
|
user->paintUserpicLeft(p, _userpicView, x, y, width(), size);
|
||||||
return;
|
return;
|
||||||
|
@ -234,8 +228,6 @@ void MainMenu::AccountButton::paintUserpic(Painter &p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
|
void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
|
||||||
Expects(_account->sessionExists());
|
|
||||||
|
|
||||||
auto p = Painter(this);
|
auto p = Painter(this);
|
||||||
const auto over = isOver();
|
const auto over = isOver();
|
||||||
p.fillRect(rect(), over ? _st.itemBgOver : _st.itemBg);
|
p.fillRect(rect(), over ? _st.itemBgOver : _st.itemBg);
|
||||||
|
@ -244,7 +236,8 @@ void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
|
||||||
paintUserpic(p);
|
paintUserpic(p);
|
||||||
|
|
||||||
auto available = width() - _st.itemPadding.left();
|
auto available = width() - _st.itemPadding.left();
|
||||||
if (_unreadBadge && _account != &Core::App().activeAccount()) {
|
if (_unreadBadge
|
||||||
|
&& (&_session->account() != &Core::App().activeAccount())) {
|
||||||
_unreadSt.muted = _unreadBadgeMuted;
|
_unreadSt.muted = _unreadBadgeMuted;
|
||||||
const auto string = (_unreadBadge > 99)
|
const auto string = (_unreadBadge > 99)
|
||||||
? "99+"
|
? "99+"
|
||||||
|
@ -267,7 +260,7 @@ void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.setPen(over ? _st.itemFgOver : _st.itemFg);
|
p.setPen(over ? _st.itemFgOver : _st.itemFg);
|
||||||
_account->session().user()->nameText().drawElided(
|
_session->user()->nameText().drawElided(
|
||||||
p,
|
p,
|
||||||
_st.itemPadding.left(),
|
_st.itemPadding.left(),
|
||||||
_st.itemPadding.top(),
|
_st.itemPadding.top(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue