2017-02-23 12:32:28 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-02-23 12:32:28 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-02-23 12:32:28 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-16 19:53:41 +03:00
|
|
|
#include <rpl/event_stream.h>
|
2017-10-22 20:06:57 +03:00
|
|
|
#include <rpl/filter.h>
|
2017-11-05 17:57:51 +04:00
|
|
|
#include <rpl/variable.h>
|
2019-08-23 16:52:59 +03:00
|
|
|
#include "main/main_settings.h"
|
2017-04-09 21:06:06 +03:00
|
|
|
#include "base/timer.h"
|
|
|
|
|
2017-12-25 14:13:27 +03:00
|
|
|
class ApiWrap;
|
2018-09-29 15:18:26 +03:00
|
|
|
|
|
|
|
namespace Support {
|
2018-11-15 19:36:04 +04:00
|
|
|
class Helper;
|
2018-10-02 23:39:54 +03:00
|
|
|
class Templates;
|
2018-09-29 15:18:26 +03:00
|
|
|
} // namespace Support
|
|
|
|
|
2018-01-04 12:40:58 +03:00
|
|
|
namespace Data {
|
2018-01-04 13:22:53 +03:00
|
|
|
class Session;
|
2018-01-04 12:40:58 +03:00
|
|
|
} // namespace Data
|
|
|
|
|
2017-03-04 22:36:59 +03:00
|
|
|
namespace Storage {
|
|
|
|
class Downloader;
|
2017-08-04 16:54:32 +02:00
|
|
|
class Uploader;
|
2017-09-04 14:40:02 +03:00
|
|
|
class Facade;
|
2017-03-04 22:36:59 +03:00
|
|
|
} // namespace Storage
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
|
|
|
class System;
|
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|
|
|
|
|
2017-04-19 12:44:07 +03:00
|
|
|
namespace Calls {
|
|
|
|
class Instance;
|
|
|
|
} // namespace Calls
|
|
|
|
|
2019-08-01 15:13:02 +01:00
|
|
|
namespace Stickers {
|
|
|
|
class EmojiPack;
|
|
|
|
} // namespace Stickers;
|
|
|
|
|
2017-12-29 21:17:07 +03:00
|
|
|
namespace Core {
|
|
|
|
class Changelogs;
|
|
|
|
} // namespace Core
|
|
|
|
|
2019-07-24 13:45:24 +02:00
|
|
|
namespace Main {
|
|
|
|
|
|
|
|
class Account;
|
2019-08-01 15:50:24 +01:00
|
|
|
class AppConfig;
|
2019-07-24 13:45:24 +02:00
|
|
|
|
|
|
|
class Session final
|
2018-01-17 19:21:01 +03:00
|
|
|
: public base::has_weak_ptr
|
|
|
|
, private base::Subscriber {
|
2017-02-23 12:32:28 +03:00
|
|
|
public:
|
2019-07-24 13:45:24 +02:00
|
|
|
Session(not_null<Main::Account*> account, const MTPUser &user);
|
|
|
|
~Session();
|
2017-02-23 12:32:28 +03:00
|
|
|
|
2019-07-24 13:45:24 +02:00
|
|
|
Session(const Session &other) = delete;
|
|
|
|
Session &operator=(const Session &other) = delete;
|
2017-02-23 12:32:28 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] static bool Exists();
|
2017-03-04 22:36:59 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Main::Account &account() const;
|
2019-06-05 23:41:51 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] UserId userId() const;
|
|
|
|
[[nodiscard]] PeerId userPeerId() const;
|
|
|
|
[[nodiscard]] not_null<UserData*> user() const {
|
2018-09-11 15:50:40 +03:00
|
|
|
return _user;
|
2017-08-04 16:54:32 +02:00
|
|
|
}
|
2017-03-04 22:36:59 +03:00
|
|
|
bool validateSelf(const MTPUser &user);
|
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Storage::Downloader &downloader() {
|
2017-03-15 19:24:06 +03:00
|
|
|
return *_downloader;
|
2017-03-04 22:36:59 +03:00
|
|
|
}
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Storage::Uploader &uploader() {
|
2017-08-04 16:54:32 +02:00
|
|
|
return *_uploader;
|
|
|
|
}
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Storage::Facade &storage() {
|
2017-09-04 14:40:02 +03:00
|
|
|
return *_storage;
|
|
|
|
}
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Stickers::EmojiPack &emojiStickersPack() {
|
2019-08-01 15:13:02 +01:00
|
|
|
return *_emojiStickersPack;
|
|
|
|
}
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] AppConfig &appConfig() {
|
2019-08-01 15:50:24 +01:00
|
|
|
return *_appConfig;
|
|
|
|
}
|
2017-03-04 22:36:59 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] base::Observable<void> &downloaderTaskFinished();
|
2017-03-04 22:36:59 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Window::Notifications::System ¬ifications() {
|
2017-03-15 19:24:06 +03:00
|
|
|
return *_notifications;
|
2017-03-04 22:36:59 +03:00
|
|
|
}
|
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Data::Session &data() {
|
2018-01-04 13:22:53 +03:00
|
|
|
return *_data;
|
|
|
|
}
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Settings &settings() {
|
2018-01-04 13:22:53 +03:00
|
|
|
return _settings;
|
2017-03-14 17:16:03 +03:00
|
|
|
}
|
2019-07-24 13:45:24 +02:00
|
|
|
void moveSettingsFrom(Settings &&other);
|
2019-02-19 10:57:53 +04:00
|
|
|
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
2017-03-14 17:16:03 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] not_null<MTP::Instance*> mtp();
|
|
|
|
[[nodiscard]] ApiWrap &api() {
|
2017-04-06 22:02:40 +03:00
|
|
|
return *_api;
|
|
|
|
}
|
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] Calls::Instance &calls() {
|
2017-04-19 12:44:07 +03:00
|
|
|
return *_calls;
|
|
|
|
}
|
|
|
|
|
2017-04-15 21:48:54 +03:00
|
|
|
void checkAutoLock();
|
2019-02-19 10:57:53 +04:00
|
|
|
void checkAutoLockIn(crl::time time);
|
2019-03-04 22:40:21 +04:00
|
|
|
void localPasscodeChanged();
|
2019-03-27 12:37:25 +04:00
|
|
|
void termsDeleteNow();
|
2017-04-15 21:48:54 +03:00
|
|
|
|
2019-08-23 16:52:59 +03:00
|
|
|
[[nodiscard]] rpl::lifetime &lifetime() {
|
2018-09-06 14:13:54 +03:00
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
2017-08-08 11:31:48 +02:00
|
|
|
base::Observable<DocumentData*> documentUpdated;
|
2017-08-18 22:14:31 +03:00
|
|
|
base::Observable<std::pair<not_null<HistoryItem*>, MsgId>> messageIdChanging;
|
2017-08-08 11:31:48 +02:00
|
|
|
|
2018-09-28 14:56:21 +03:00
|
|
|
bool supportMode() const;
|
2018-11-15 19:36:04 +04:00
|
|
|
Support::Helper &supportHelper() const;
|
|
|
|
Support::Templates &supportTemplates() const;
|
2018-09-28 14:56:21 +03:00
|
|
|
|
2017-02-23 12:32:28 +03:00
|
|
|
private:
|
2019-02-19 10:57:53 +04:00
|
|
|
static constexpr auto kDefaultSaveDelay = crl::time(1000);
|
2017-09-30 21:26:45 +03:00
|
|
|
|
2019-06-05 23:41:51 +03:00
|
|
|
const not_null<Main::Account*> _account;
|
|
|
|
|
2019-07-24 13:45:24 +02:00
|
|
|
Settings _settings;
|
2019-08-23 16:52:59 +03:00
|
|
|
base::Timer _saveSettingsTimer;
|
2017-02-23 12:32:28 +03:00
|
|
|
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::time _shouldLockAt = 0;
|
2017-04-15 21:48:54 +03:00
|
|
|
base::Timer _autoLockTimer;
|
|
|
|
|
2017-04-06 22:02:40 +03:00
|
|
|
const std::unique_ptr<ApiWrap> _api;
|
2019-08-01 15:50:24 +01:00
|
|
|
const std::unique_ptr<AppConfig> _appConfig;
|
2017-04-19 12:44:07 +03:00
|
|
|
const std::unique_ptr<Calls::Instance> _calls;
|
2017-03-04 22:36:59 +03:00
|
|
|
const std::unique_ptr<Storage::Downloader> _downloader;
|
2017-08-04 16:54:32 +02:00
|
|
|
const std::unique_ptr<Storage::Uploader> _uploader;
|
2017-09-04 14:40:02 +03:00
|
|
|
const std::unique_ptr<Storage::Facade> _storage;
|
2017-03-04 22:36:59 +03:00
|
|
|
const std::unique_ptr<Window::Notifications::System> _notifications;
|
|
|
|
|
2019-01-03 16:36:01 +04:00
|
|
|
// _data depends on _downloader / _uploader / _notifications.
|
2018-01-27 12:21:57 +03:00
|
|
|
const std::unique_ptr<Data::Session> _data;
|
2019-01-03 16:36:01 +04:00
|
|
|
const not_null<UserData*> _user;
|
2018-01-27 12:21:57 +03:00
|
|
|
|
2019-08-01 15:13:02 +01:00
|
|
|
// _emojiStickersPack depends on _data.
|
|
|
|
const std::unique_ptr<Stickers::EmojiPack> _emojiStickersPack;
|
|
|
|
|
2018-02-18 16:26:28 +03:00
|
|
|
// _changelogs depends on _data, subscribes on chats loading event.
|
|
|
|
const std::unique_ptr<Core::Changelogs> _changelogs;
|
|
|
|
|
2018-11-15 19:36:04 +04:00
|
|
|
const std::unique_ptr<Support::Helper> _supportHelper;
|
2018-10-02 23:39:54 +03:00
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-02-23 12:32:28 +03:00
|
|
|
};
|
2019-07-24 13:45:24 +02:00
|
|
|
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
Main::Session &Auth();
|