tdesktop/Telegram/SourceFiles/main/main_domain.h

118 lines
3.3 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
#include "base/timer.h"
2020-06-15 16:25:02 +00:00
namespace Storage {
class Domain;
2020-06-15 16:25:02 +00:00
enum class StartResult : uchar;
} // namespace Storage
namespace MTP {
enum class Environment : uchar;
} // namespace MTP
2020-06-15 16:25:02 +00:00
namespace Main {
class Account;
class Session;
class Domain final {
2020-06-15 16:25:02 +00:00
public:
struct AccountWithIndex {
int index = 0;
std::unique_ptr<Account> account;
};
static constexpr auto kMaxAccounts = 3;
static constexpr auto kPremiumMaxAccounts = 6;
explicit Domain(const QString &dataName);
~Domain();
2020-06-15 16:25:02 +00:00
[[nodiscard]] bool started() const;
2020-06-16 09:40:43 +00:00
[[nodiscard]] Storage::StartResult start(const QByteArray &passcode);
void resetWithForgottenPasscode();
void finish();
2020-06-15 16:25:02 +00:00
[[nodiscard]] int maxAccounts() const;
[[nodiscard]] rpl::producer<int> maxAccountsChanges() const;
[[nodiscard]] Storage::Domain &local() const {
2020-06-15 16:25:02 +00:00
return *_local;
}
[[nodiscard]] auto accounts() const
-> const std::vector<AccountWithIndex> &;
[[nodiscard]] std::vector<not_null<Account*>> orderedAccounts() const;
2020-06-15 16:25:02 +00:00
[[nodiscard]] rpl::producer<Account*> activeValue() const;
[[nodiscard]] rpl::producer<> accountsChanges() const;
[[nodiscard]] Account *maybeLastOrSomeAuthedAccount();
[[nodiscard]] int accountsAuthedCount() const;
2020-06-15 16:25:02 +00:00
// Expects(started());
[[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 unreadBadge() const;
[[nodiscard]] bool unreadBadgeMuted() const;
[[nodiscard]] rpl::producer<> unreadBadgeChanges() const;
void notifyUnreadBadgeChanged();
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
void maybeActivate(not_null<Main::Account*> account);
void activate(not_null<Main::Account*> account);
void addActivated(MTP::Environment environment, bool newWindow = false);
2020-06-15 16:25:02 +00:00
// Interface for Storage::Domain.
void accountAddedInStorage(AccountWithIndex accountWithIndex);
void activateFromStorage(int index);
2020-06-19 17:13:43 +00:00
[[nodiscard]] int activeForStorage() const;
2020-06-16 09:40:43 +00:00
2020-06-15 16:25:02 +00:00
private:
2020-06-16 09:40:43 +00:00
void activateAfterStarting();
void closeAccountWindows(not_null<Main::Account*> account);
2020-06-16 14:19:23 +00:00
bool removePasscodeIfEmpty();
2020-06-16 09:40:43 +00:00
void removeRedundantAccounts();
void watchSession(not_null<Account*> account);
void scheduleWriteAccounts();
void checkForLastProductionConfig(not_null<Main::Account*> account);
void updateUnreadBadge();
void scheduleUpdateUnreadBadge();
2020-06-29 16:07:56 +00:00
void suggestExportIfNeeded();
2020-06-16 09:40:43 +00:00
2020-06-15 16:25:02 +00:00
const QString _dataName;
const std::unique_ptr<Storage::Domain> _local;
2020-06-15 16:25:02 +00:00
std::vector<AccountWithIndex> _accounts;
rpl::event_stream<> _accountsChanges;
2020-06-15 16:25:02 +00:00
rpl::variable<Account*> _active = nullptr;
int _accountToActivate = -1;
int _lastActiveIndex = -1;
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::event_stream<> _unreadBadgeChanges;
int _unreadBadge = 0;
bool _unreadBadgeMuted = true;
bool _unreadBadgeUpdateScheduled = false;
rpl::variable<int> _lastMaxAccounts;
2020-06-15 16:25:02 +00:00
rpl::lifetime _activeLifetime;
rpl::lifetime _lifetime;
};
} // namespace Main