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>
|
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
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
namespace Api {
|
|
|
|
class Updates;
|
2020-07-06 09:58:18 +00:00
|
|
|
class SendProgressManager;
|
2020-06-11 09:41:03 +00:00
|
|
|
} // namespace Api
|
|
|
|
|
2019-11-13 08:31:12 +00:00
|
|
|
namespace MTP {
|
|
|
|
class Instance;
|
2020-06-17 09:36:25 +00:00
|
|
|
struct ConfigFields;
|
2019-11-13 08:31:12 +00:00
|
|
|
} // 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;
|
2020-06-12 12:12:34 +00:00
|
|
|
class Changes;
|
2020-06-23 09:20:38 +00:00
|
|
|
class CloudImageView;
|
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;
|
2020-06-09 16:57:05 +00:00
|
|
|
class Account;
|
2020-06-18 18:04:16 +00:00
|
|
|
class Domain;
|
2017-03-04 19:36:59 +00:00
|
|
|
} // namespace Storage
|
|
|
|
|
|
|
|
namespace Window {
|
2020-06-11 09:41:03 +00:00
|
|
|
class SessionController;
|
2020-06-24 07:56:16 +00:00
|
|
|
struct TermsLock;
|
2017-03-04 19:36:59 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
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;
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
namespace InlineBots {
|
|
|
|
class AttachWebView;
|
|
|
|
} // namespace InlineBots
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
|
|
|
|
class Account;
|
2020-06-18 18:04:16 +00:00
|
|
|
class Domain;
|
2020-06-18 12:47:09 +00:00
|
|
|
class SessionSettings;
|
2021-11-09 12:10:51 +00:00
|
|
|
class SendAsPeers;
|
2019-07-24 11:45:24 +00:00
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
class Session final : public base::has_weak_ptr {
|
2017-02-23 09:32:28 +00:00
|
|
|
public:
|
2019-10-02 10:46:02 +00:00
|
|
|
Session(
|
2020-06-18 18:04:16 +00:00
|
|
|
not_null<Account*> account,
|
2019-10-02 10:46:02 +00:00
|
|
|
const MTPUser &user,
|
2020-06-18 12:47:09 +00:00
|
|
|
std::unique_ptr<SessionSettings> settings);
|
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
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
[[nodiscard]] Account &account() const;
|
2020-06-09 16:57:05 +00:00
|
|
|
[[nodiscard]] Storage::Account &local() const;
|
2020-06-18 18:04:16 +00:00
|
|
|
[[nodiscard]] Domain &domain() const;
|
|
|
|
[[nodiscard]] Storage::Domain &domainLocal() const;
|
2019-06-05 20:41:51 +00:00
|
|
|
|
2022-05-20 14:57:01 +00:00
|
|
|
[[nodiscard]] bool premium() const;
|
2022-06-07 05:48:33 +00:00
|
|
|
[[nodiscard]] bool premiumPossible() const;
|
2022-06-08 12:53:16 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> premiumPossibleValue() const;
|
|
|
|
|
2020-06-24 09:05:56 +00:00
|
|
|
[[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift.
|
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
|
|
|
}
|
2021-11-19 19:04:40 +00:00
|
|
|
bool validateSelf(UserId id);
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2021-10-12 12:50:18 +00:00
|
|
|
[[nodiscard]] Data::Changes &changes() const {
|
|
|
|
return *_changes;
|
|
|
|
}
|
2020-06-11 09:41:03 +00:00
|
|
|
[[nodiscard]] Api::Updates &updates() const {
|
|
|
|
return *_updates;
|
|
|
|
}
|
2020-07-06 09:58:18 +00:00
|
|
|
[[nodiscard]] Api::SendProgressManager &sendProgressManager() const {
|
|
|
|
return *_sendProgressManager;
|
|
|
|
}
|
2020-06-11 09:41:03 +00:00
|
|
|
[[nodiscard]] Storage::DownloadManagerMtproto &downloader() const {
|
2017-03-15 16:24:06 +00:00
|
|
|
return *_downloader;
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
2020-06-11 09:41:03 +00:00
|
|
|
[[nodiscard]] Storage::Uploader &uploader() const {
|
2017-08-04 14:54:32 +00:00
|
|
|
return *_uploader;
|
|
|
|
}
|
2020-06-11 09:41:03 +00:00
|
|
|
[[nodiscard]] Storage::Facade &storage() const {
|
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
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
[[nodiscard]] Data::Session &data() const {
|
2018-01-04 10:22:53 +00:00
|
|
|
return *_data;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
[[nodiscard]] SessionSettings &settings() const {
|
2020-06-18 12:47:09 +00:00
|
|
|
return *_settings;
|
2017-03-14 14:16:03 +00:00
|
|
|
}
|
2021-11-09 12:10:51 +00:00
|
|
|
[[nodiscard]] SendAsPeers &sendAsPeers() const {
|
|
|
|
return *_sendAsPeers;
|
|
|
|
}
|
2022-03-29 09:00:10 +00:00
|
|
|
[[nodiscard]] InlineBots::AttachWebView &attachWebView() const {
|
|
|
|
return *_attachWebView;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
void saveSettings();
|
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
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
void addWindow(not_null<Window::SessionController*> controller);
|
|
|
|
[[nodiscard]] auto windows() const
|
|
|
|
-> const base::flat_set<not_null<Window::SessionController*>> &;
|
2022-01-26 09:41:27 +00:00
|
|
|
[[nodiscard]] Window::SessionController *tryResolveWindow() const;
|
2020-06-11 09:41:03 +00:00
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
// Shortcuts.
|
2020-07-01 08:03:34 +00:00
|
|
|
void notifyDownloaderTaskFinished();
|
|
|
|
[[nodiscard]] rpl::producer<> downloaderTaskFinished() const;
|
2020-06-11 16:09:46 +00:00
|
|
|
[[nodiscard]] MTP::DcId mainDcId() const;
|
2020-06-17 09:36:25 +00:00
|
|
|
[[nodiscard]] MTP::Instance &mtp() const;
|
|
|
|
[[nodiscard]] const MTP::ConfigFields &serverConfig() const;
|
2019-08-23 13:52:59 +00:00
|
|
|
[[nodiscard]] ApiWrap &api() {
|
2017-04-06 19:02:40 +00:00
|
|
|
return *_api;
|
|
|
|
}
|
|
|
|
|
2020-06-24 07:56:16 +00:00
|
|
|
// Terms lock.
|
|
|
|
void lockByTerms(const Window::TermsLock &data);
|
|
|
|
void unlockTerms();
|
2019-03-27 08:37:25 +00:00
|
|
|
void termsDeleteNow();
|
2020-06-24 07:56:16 +00:00
|
|
|
[[nodiscard]] std::optional<Window::TermsLock> termsLocked() const;
|
|
|
|
rpl::producer<bool> termsLockChanges() const;
|
|
|
|
rpl::producer<bool> termsLockValue() const;
|
2017-04-15 18:48:54 +00:00
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
[[nodiscard]] QString createInternalLink(const QString &query) const;
|
|
|
|
[[nodiscard]] QString createInternalLinkFull(const QString &query) const;
|
2022-01-16 09:23:53 +00:00
|
|
|
[[nodiscard]] TextWithEntities createInternalLink(
|
|
|
|
const TextWithEntities &query) const;
|
|
|
|
[[nodiscard]] TextWithEntities createInternalLinkFull(
|
|
|
|
TextWithEntities query) const;
|
2020-06-17 09:36:25 +00:00
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
void setTmpPassword(const QByteArray &password, TimeId validUntil);
|
|
|
|
[[nodiscard]] QByteArray validTmpPassword() const;
|
|
|
|
|
2020-06-26 10:36:22 +00:00
|
|
|
// Can be called only right before ~Session.
|
|
|
|
void finishLogout();
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
// Uploads cancel with confirmation.
|
|
|
|
[[nodiscard]] bool uploadsInProgress() const;
|
|
|
|
void uploadsStopWithConfirmation(Fn<void()> done);
|
|
|
|
void uploadsStop();
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
[[nodiscard]] rpl::lifetime &lifetime() {
|
2018-09-06 11:13:54 +00:00
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
2022-03-01 14:32:39 +00:00
|
|
|
[[nodiscard]] bool supportMode() const;
|
|
|
|
[[nodiscard]] Support::Helper &supportHelper() const;
|
|
|
|
[[nodiscard]] 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
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
const not_null<Account*> _account;
|
2019-06-05 20:41:51 +00:00
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
const std::unique_ptr<SessionSettings> _settings;
|
2021-10-12 12:50:18 +00:00
|
|
|
const std::unique_ptr<Data::Changes> _changes;
|
2017-04-06 19:02:40 +00:00
|
|
|
const std::unique_ptr<ApiWrap> _api;
|
2020-06-11 09:41:03 +00:00
|
|
|
const std::unique_ptr<Api::Updates> _updates;
|
2020-07-06 09:58:18 +00:00
|
|
|
const std::unique_ptr<Api::SendProgressManager> _sendProgressManager;
|
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
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
// _data depends on _downloader / _uploader.
|
2018-01-27 09:21:57 +00:00
|
|
|
const std::unique_ptr<Data::Session> _data;
|
2021-12-01 14:51:18 +00:00
|
|
|
const UserId _userId;
|
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;
|
2021-11-09 12:10:51 +00:00
|
|
|
const std::unique_ptr<SendAsPeers> _sendAsPeers;
|
2022-03-29 09:00:10 +00:00
|
|
|
const std::unique_ptr<InlineBots::AttachWebView> _attachWebView;
|
2019-08-01 14:13:02 +00:00
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
const std::unique_ptr<Support::Helper> _supportHelper;
|
2018-10-02 20:39:54 +00:00
|
|
|
|
2020-06-23 09:20:38 +00:00
|
|
|
std::shared_ptr<Data::CloudImageView> _selfUserpicView;
|
2022-06-08 12:53:16 +00:00
|
|
|
rpl::variable<bool> _premiumPossible = false;
|
2020-06-23 09:20:38 +00:00
|
|
|
|
2020-06-24 07:56:16 +00:00
|
|
|
rpl::event_stream<bool> _termsLockChanges;
|
|
|
|
std::unique_ptr<Window::TermsLock> _termsLock;
|
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
base::flat_set<not_null<Window::SessionController*>> _windows;
|
2020-06-18 12:47:09 +00:00
|
|
|
base::Timer _saveSettingsTimer;
|
2020-06-11 09:41:03 +00:00
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
QByteArray _tmpPassword;
|
|
|
|
TimeId _tmpPasswordValidUntil = 0;
|
|
|
|
|
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
|