Fix crash in MainMenu hiding on external logout.

This commit is contained in:
John Preston 2020-06-30 19:13:57 +04:00
parent 7d0eb3ba8e
commit d529c60081
1 changed files with 16 additions and 23 deletions

View File

@ -101,7 +101,7 @@ private:
void paintEvent(QPaintEvent *e) override;
void paintUserpic(Painter &p);
const not_null<Main::Account*> _account;
const not_null<Main::Session*> _session;
const style::Menu &_st;
std::shared_ptr<Data::CloudImageView> _userpicView;
InMemoryKey _userpicKey = {};
@ -153,7 +153,7 @@ MainMenu::AccountButton::AccountButton(
QWidget *parent,
not_null<Main::Account*> account)
: RippleButton(parent, st::defaultRippleAnimation)
, _account(account)
, _session(&account->session())
, _st(st::mainMenu){
const auto height = _st.itemPadding.top()
+ _st.itemStyle.font->height
@ -167,33 +167,27 @@ MainMenu::AccountButton::AccountButton(
}
});
_account->sessionValue(
) | rpl::filter([=](Main::Session *session) {
return (session != nullptr);
}) | rpl::start_with_next([=](not_null<Main::Session*> session) {
rpl::single(
rpl::empty_value()
) | rpl::then(
session->data().unreadBadgeChanges()
) | rpl::start_with_next([=] {
_unreadBadge = session->data().unreadBadge();
_unreadBadgeMuted = session->data().unreadBadgeMuted();
update();
}, lifetime());
rpl::single(
rpl::empty_value()
) | rpl::then(
_session->data().unreadBadgeChanges()
) | rpl::start_with_next([=] {
_unreadBadge = _session->data().unreadBadge();
_unreadBadgeMuted = _session->data().unreadBadgeMuted();
update();
}, lifetime());
}
void MainMenu::AccountButton::paintUserpic(Painter &p) {
Expects(_account->sessionExists());
const auto size = st::mainMenuAccountSize;
const auto iconSize = height() - 2 * _st.itemIconPosition.y();
const auto shift = (size - iconSize) / 2;
const auto x = _st.itemIconPosition.x() - shift;
const auto y = (height() - size) / 2;
const auto check = (_account == &Core::App().domain().active());
const auto user = _account->session().user();
const auto check = (&_session->account()
== &Core::App().domain().active());
const auto user = _session->user();
if (!check) {
user->paintUserpicLeft(p, _userpicView, x, y, width(), size);
return;
@ -234,8 +228,6 @@ void MainMenu::AccountButton::paintUserpic(Painter &p) {
}
void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
Expects(_account->sessionExists());
auto p = Painter(this);
const auto over = isOver();
p.fillRect(rect(), over ? _st.itemBgOver : _st.itemBg);
@ -244,7 +236,8 @@ void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
paintUserpic(p);
auto available = width() - _st.itemPadding.left();
if (_unreadBadge && _account != &Core::App().activeAccount()) {
if (_unreadBadge
&& (&_session->account() != &Core::App().activeAccount())) {
_unreadSt.muted = _unreadBadgeMuted;
const auto string = (_unreadBadge > 99)
? "99+"
@ -267,7 +260,7 @@ void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
}
p.setPen(over ? _st.itemFgOver : _st.itemFg);
_account->session().user()->nameText().drawElided(
_session->user()->nameText().drawElided(
p,
_st.itemPadding.left(),
_st.itemPadding.top(),