| 454 | } |
| 455 | |
| 456 | void Domain::activate(not_null<Main::Account*> account) { |
| 457 | if (const auto window = Core::App().separateWindowFor(account)) { |
| 458 | window->activate(); |
| 459 | } |
| 460 | if (_active.current() == account.get()) { |
| 461 | return; |
| 462 | } |
| 463 | const auto i = ranges::find(_accounts, account.get(), []( |
| 464 | const AccountWithIndex &value) { |
| 465 | return value.account.get(); |
| 466 | }); |
| 467 | Assert(i != end(_accounts)); |
| 468 | const auto changed = (_accountToActivate != i->index); |
| 469 | auto wasAuthed = false; |
| 470 | |
| 471 | _activeLifetime.destroy(); |
| 472 | if (_active.current()) { |
| 473 | _lastActiveIndex = _accountToActivate; |
| 474 | wasAuthed = _active.current()->sessionExists(); |
| 475 | } |
| 476 | _accountToActivate = i->index; |
| 477 | _active = account.get(); |
| 478 | _active.current()->sessionValue( |
| 479 | ) | rpl::start_to_stream(_activeSessions, _activeLifetime); |
| 480 | |
| 481 | if (changed) { |
| 482 | if (wasAuthed) { |
| 483 | scheduleWriteAccounts(); |
| 484 | } else { |
| 485 | crl::on_main(&Core::App(), [=] { |
| 486 | removeRedundantAccounts(); |
| 487 | }); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | void Domain::scheduleWriteAccounts() { |
| 493 | if (_writeAccountsScheduled) { |
no test coverage detected