tdesktop/Telegram/SourceFiles/main/main_domain.h

102 lines
2.6 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;
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]] Storage::Domain &local() const {
2020-06-15 16:25:02 +00:00
return *_local;
}
[[nodiscard]] auto accounts() const
-> const std::vector<AccountWithIndex> &;
2020-06-15 16:25:02 +00:00
[[nodiscard]] rpl::producer<Account*> activeValue() const;
// 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 activate(not_null<Main::Account*> account);
2020-06-15 16:25:02 +00:00
// Interface for Storage::Domain.
void accountAddedInStorage(AccountWithIndex accountWithIndex);
void activateFromStorage(int index);
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 activateAuthedAccount();
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-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;
2020-06-15 16:25:02 +00:00
rpl::variable<Account*> _active = nullptr;
int _accountToActivate = -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;
2020-06-15 16:25:02 +00:00
rpl::lifetime _activeLifetime;
rpl::lifetime _lifetime;
};
} // namespace Main