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