tdesktop/Telegram/SourceFiles/main/main_session.h

173 lines
3.8 KiB
C
Raw Normal View History

/*
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 <rpl/event_stream.h>
#include <rpl/filter.h>
#include <rpl/variable.h>
2019-08-23 13:52:59 +00:00
#include "main/main_settings.h"
#include "base/timer.h"
class ApiWrap;
2019-11-13 08:31:12 +00:00
namespace MTP {
class Instance;
} // namespace MTP
namespace Support {
class Helper;
class Templates;
} // namespace Support
2018-01-04 09:40:58 +00:00
namespace Data {
class Session;
2018-01-04 09:40:58 +00:00
} // namespace Data
namespace Storage {
class DownloadManagerMtproto;
class Uploader;
class Facade;
} // namespace Storage
namespace Window {
namespace Notifications {
class System;
} // namespace Notifications
} // namespace Window
namespace Calls {
class Instance;
} // namespace Calls
2019-08-01 14:13:02 +00:00
namespace Stickers {
class EmojiPack;
} // namespace Stickers;
namespace Core {
class Changelogs;
} // namespace Core
2019-07-24 11:45:24 +00:00
namespace Main {
class Account;
class Session final
: public base::has_weak_ptr
, private base::Subscriber {
public:
Session(
not_null<Main::Account*> account,
const MTPUser &user,
Settings &&other);
2019-07-24 11:45:24 +00:00
~Session();
2019-07-24 11:45:24 +00:00
Session(const Session &other) = delete;
Session &operator=(const Session &other) = delete;
2019-08-23 13:52:59 +00:00
[[nodiscard]] static bool Exists();
2019-08-23 13:52:59 +00:00
[[nodiscard]] Main::Account &account() const;
2019-08-23 13:52:59 +00:00
[[nodiscard]] UserId userId() const;
[[nodiscard]] PeerId userPeerId() const;
[[nodiscard]] not_null<UserData*> user() const {
return _user;
}
bool validateSelf(const MTPUser &user);
[[nodiscard]] Storage::DownloadManagerMtproto &downloader() {
return *_downloader;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] Storage::Uploader &uploader() {
return *_uploader;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] Storage::Facade &storage() {
return *_storage;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] Stickers::EmojiPack &emojiStickersPack() {
2019-08-01 14:13:02 +00:00
return *_emojiStickersPack;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] base::Observable<void> &downloaderTaskFinished();
2019-08-23 13:52:59 +00:00
[[nodiscard]] Window::Notifications::System &notifications() {
return *_notifications;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] Data::Session &data() {
return *_data;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] Settings &settings() {
return _settings;
}
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
void saveSettingsNowIfNeeded();
2019-08-23 13:52:59 +00:00
[[nodiscard]] not_null<MTP::Instance*> mtp();
[[nodiscard]] ApiWrap &api() {
return *_api;
}
2019-08-23 13:52:59 +00:00
[[nodiscard]] Calls::Instance &calls() {
return *_calls;
}
void checkAutoLock();
void checkAutoLockIn(crl::time time);
2019-03-04 18:40:21 +00:00
void localPasscodeChanged();
2019-03-27 08:37:25 +00:00
void termsDeleteNow();
2019-08-23 13:52:59 +00:00
[[nodiscard]] rpl::lifetime &lifetime() {
return _lifetime;
}
base::Observable<DocumentData*> documentUpdated;
base::Observable<std::pair<not_null<HistoryItem*>, MsgId>> messageIdChanging;
2018-09-28 11:56:21 +00:00
bool supportMode() const;
Support::Helper &supportHelper() const;
Support::Templates &supportTemplates() const;
2018-09-28 11:56:21 +00:00
private:
static constexpr auto kDefaultSaveDelay = crl::time(1000);
const not_null<Main::Account*> _account;
2019-07-24 11:45:24 +00:00
Settings _settings;
2019-08-23 13:52:59 +00:00
base::Timer _saveSettingsTimer;
crl::time _shouldLockAt = 0;
base::Timer _autoLockTimer;
const std::unique_ptr<ApiWrap> _api;
const std::unique_ptr<Calls::Instance> _calls;
const std::unique_ptr<Storage::DownloadManagerMtproto> _downloader;
const std::unique_ptr<Storage::Uploader> _uploader;
const std::unique_ptr<Storage::Facade> _storage;
const std::unique_ptr<Window::Notifications::System> _notifications;
2019-01-03 12:36:01 +00:00
// _data depends on _downloader / _uploader / _notifications.
const std::unique_ptr<Data::Session> _data;
2019-01-03 12:36:01 +00:00
const not_null<UserData*> _user;
2019-08-01 14:13:02 +00:00
// _emojiStickersPack depends on _data.
const std::unique_ptr<Stickers::EmojiPack> _emojiStickersPack;
// _changelogs depends on _data, subscribes on chats loading event.
const std::unique_ptr<Core::Changelogs> _changelogs;
const std::unique_ptr<Support::Helper> _supportHelper;
rpl::lifetime _lifetime;
};
2019-07-24 11:45:24 +00:00
} // namespace Main
Main::Session &Auth();