2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Several working accounts together.

This commit is contained in:
John Preston
2020-06-16 10:42:47 +04:00
parent 6fc5e22882
commit ab5796c117
14 changed files with 97 additions and 60 deletions

View File

@@ -66,6 +66,12 @@ rpl::producer<Account*> Accounts::activeValue() const {
return _active.value();
}
int Accounts::activeIndex() const {
Expects(_accounts.contains(_activeIndex));
return _activeIndex;
}
Account &Accounts::active() const {
Expects(!_accounts.empty());
@@ -91,11 +97,18 @@ rpl::producer<Session*> Accounts::activeSessionValue() const {
}
int Accounts::add() {
Expects(!Core::App().locked());
auto index = 0;
while (_accounts.contains(index)) {
++index;
}
_accounts.emplace(index, std::make_unique<Account>(_dataName, index));
const auto account = _accounts.emplace(
index,
std::make_unique<Account>(_dataName, index)
).first->second.get();
_local->startAdded(account);
account->startMtp();
return index;
}
@@ -107,6 +120,10 @@ void Accounts::activate(int index) {
_active = _accounts.find(index)->second.get();
_active.current()->sessionValue(
) | rpl::start_to_stream(_activeSessions, _activeLifetime);
crl::on_main(&Core::App(), [=] {
_local->writeAccounts();
});
}
} // namespace Main