tdesktop/Telegram/SourceFiles/main/main_accounts.h

74 lines
1.8 KiB
C
Raw Normal View History

2020-06-15 16:25:02 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace Storage {
class Accounts;
enum class StartResult : uchar;
} // namespace Storage
namespace Main {
class Account;
class Session;
class Accounts final {
public:
explicit Accounts(const QString &dataName);
~Accounts();
[[nodiscard]] bool started() const;
2020-06-16 09:40:43 +00:00
[[nodiscard]] Storage::StartResult start(const QByteArray &passcode);
void resetWithForgottenPasscode();
2020-06-15 16:25:02 +00:00
[[nodiscard]] Storage::Accounts &local() const {
return *_local;
}
[[nodiscard]] auto list() const
-> const base::flat_map<int, std::unique_ptr<Account>> &;
[[nodiscard]] rpl::producer<Account*> activeValue() const;
// Expects(started());
2020-06-16 06:42:47 +00:00
[[nodiscard]] int activeIndex() const;
2020-06-15 16:25:02 +00:00
[[nodiscard]] Account &active() const;
[[nodiscard]] rpl::producer<not_null<Account*>> activeChanges() const;
[[nodiscard]] rpl::producer<Session*> activeSessionValue() const;
[[nodiscard]] rpl::producer<Session*> activeSessionChanges() const;
[[nodiscard]] int add();
void activate(int index);
2020-06-16 09:40:43 +00:00
// Interface for Storage::Accounts.
void accountAddedInStorage(int index, std::unique_ptr<Account> account);
2020-06-15 16:25:02 +00:00
private:
2020-06-16 09:40:43 +00:00
void activateAfterStarting();
void activateAuthedAccount();
void removeRedundantAccounts();
void watchSession(not_null<Account*> account);
void scheduleWriteAccounts();
2020-06-15 16:25:02 +00:00
const QString _dataName;
const std::unique_ptr<Storage::Accounts> _local;
base::flat_map<int, std::unique_ptr<Account>> _accounts;
rpl::variable<Account*> _active = nullptr;
int _activeIndex = 0;
2020-06-16 09:40:43 +00:00
bool _writeAccountsScheduled = false;
2020-06-15 16:25:02 +00:00
rpl::event_stream<Session*> _activeSessions;
rpl::lifetime _activeLifetime;
rpl::lifetime _lifetime;
};
} // namespace Main