Fixed online status stuck when switching between accounts one more time.

The first attempt to fix this bug is here: 8171ed6c12.
It caused crash so it was reverted here: 2ef47222f4.
This commit is contained in:
23rd 2020-07-15 18:37:25 +03:00
parent 65e2bbee3e
commit 972bbbce6a
2 changed files with 20 additions and 0 deletions

View file

@ -157,6 +157,7 @@ Session::Session(
// Can be called only right before ~Session. // Can be called only right before ~Session.
void Session::finishLogout() { void Session::finishLogout() {
updates().updateOnline();
unlockTerms(); unlockTerms();
data().clear(); data().clear();
data().clearLocalStorage(); data().clearLocalStorage();

View file

@ -51,9 +51,26 @@ Controller::~Controller() {
} }
void Controller::showAccount(not_null<Main::Account*> account) { void Controller::showAccount(not_null<Main::Account*> account) {
const auto prevSessionUniqueId = (_account && _account->sessionExists())
? _account->session().uniqueId()
: 0;
_accountLifetime.destroy(); _accountLifetime.destroy();
_account = account; _account = account;
const auto updateOnlineOfPrevSesssion = crl::guard(_account, [=] {
if (!prevSessionUniqueId) {
return;
}
for (auto &[index, account] : _account->domain().accounts()) {
if (const auto anotherSession = account->maybeSession()) {
if (anotherSession->uniqueId() == prevSessionUniqueId) {
anotherSession->updates().updateOnline();
return;
}
}
}
});
_account->sessionValue( _account->sessionValue(
) | rpl::start_with_next([=](Main::Session *session) { ) | rpl::start_with_next([=](Main::Session *session) {
const auto was = base::take(_sessionController); const auto was = base::take(_sessionController);
@ -84,6 +101,8 @@ void Controller::showAccount(not_null<Main::Account*> account) {
setupIntro(); setupIntro();
_widget.updateGlobalMenu(); _widget.updateGlobalMenu();
} }
crl::on_main(updateOnlineOfPrevSesssion);
}, _accountLifetime); }, _accountLifetime);
} }