/* 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 #include #include "base/timer.h" class ApiWrap; namespace Api { class Updates; class SendProgressManager; } // namespace Api namespace MTP { class Instance; struct ConfigFields; } // namespace MTP namespace Support { class Helper; class Templates; } // namespace Support namespace Data { class Session; class Changes; } // namespace Data namespace Storage { class DownloadManagerMtproto; class Uploader; class Facade; class Account; class Domain; } // namespace Storage namespace Window { class SessionController; struct TermsLock; } // namespace Window namespace Stickers { class EmojiPack; class DicePacks; class GiftBoxPack; } // namespace Stickers; namespace InlineBots { class AttachWebView; } // namespace InlineBots namespace Ui { struct ColorIndicesCompressed; } // namespace Ui namespace Main { class Account; class Domain; class SessionSettings; class SendAsPeers; class Session final : public base::has_weak_ptr { public: Session( not_null account, const MTPUser &user, std::unique_ptr settings); ~Session(); Session(const Session &other) = delete; Session &operator=(const Session &other) = delete; [[nodiscard]] Account &account() const; [[nodiscard]] Storage::Account &local() const; [[nodiscard]] Domain &domain() const; [[nodiscard]] Storage::Domain &domainLocal() const; [[nodiscard]] bool premium() const; [[nodiscard]] bool premiumPossible() const; [[nodiscard]] rpl::producer premiumPossibleValue() const; [[nodiscard]] bool premiumBadgesShown() const; [[nodiscard]] bool premiumCanBuy() const; [[nodiscard]] bool isTestMode() const; [[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift. [[nodiscard]] UserId userId() const; [[nodiscard]] PeerId userPeerId() const; [[nodiscard]] not_null user() const { return _user; } bool validateSelf(UserId id); [[nodiscard]] Data::Changes &changes() const { return *_changes; } [[nodiscard]] Api::Updates &updates() const { return *_updates; } [[nodiscard]] Api::SendProgressManager &sendProgressManager() const { return *_sendProgressManager; } [[nodiscard]] Storage::DownloadManagerMtproto &downloader() const { return *_downloader; } [[nodiscard]] Storage::Uploader &uploader() const { return *_uploader; } [[nodiscard]] Storage::Facade &storage() const { return *_storage; } [[nodiscard]] Stickers::EmojiPack &emojiStickersPack() const { return *_emojiStickersPack; } [[nodiscard]] Stickers::DicePacks &diceStickersPacks() const { return *_diceStickersPacks; } [[nodiscard]] Stickers::GiftBoxPack &giftBoxStickersPacks() const { return *_giftBoxStickersPacks; } [[nodiscard]] Data::Session &data() const { return *_data; } [[nodiscard]] SessionSettings &settings() const { return *_settings; } [[nodiscard]] SendAsPeers &sendAsPeers() const { return *_sendAsPeers; } [[nodiscard]] InlineBots::AttachWebView &attachWebView() const { return *_attachWebView; } void saveSettings(); void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay); void saveSettingsNowIfNeeded(); void addWindow(not_null controller); [[nodiscard]] auto windows() const -> const base::flat_set> &; [[nodiscard]] Window::SessionController *tryResolveWindow() const; // Shortcuts. void notifyDownloaderTaskFinished(); [[nodiscard]] rpl::producer<> downloaderTaskFinished() const; [[nodiscard]] MTP::DcId mainDcId() const; [[nodiscard]] MTP::Instance &mtp() const; [[nodiscard]] const MTP::ConfigFields &serverConfig() const; [[nodiscard]] ApiWrap &api() { return *_api; } // Terms lock. void lockByTerms(const Window::TermsLock &data); void unlockTerms(); void termsDeleteNow(); [[nodiscard]] std::optional termsLocked() const; rpl::producer termsLockChanges() const; rpl::producer termsLockValue() const; [[nodiscard]] QString createInternalLink(const QString &query) const; [[nodiscard]] QString createInternalLinkFull(const QString &query) const; [[nodiscard]] TextWithEntities createInternalLink( const TextWithEntities &query) const; [[nodiscard]] TextWithEntities createInternalLinkFull( TextWithEntities query) const; void setTmpPassword(const QByteArray &password, TimeId validUntil); [[nodiscard]] QByteArray validTmpPassword() const; // Can be called only right before ~Session. void finishLogout(); // Uploads cancel with confirmation. [[nodiscard]] bool uploadsInProgress() const; void uploadsStopWithConfirmation(Fn done); void uploadsStop(); [[nodiscard]] rpl::lifetime &lifetime() { return _lifetime; } [[nodiscard]] bool supportMode() const; [[nodiscard]] Support::Helper &supportHelper() const; [[nodiscard]] Support::Templates &supportTemplates() const; [[nodiscard]] auto colorIndicesValue() -> rpl::producer; private: static constexpr auto kDefaultSaveDelay = crl::time(1000); void parseColorIndices(const MTPDhelp_peerColors &data); const not_null _account; const std::unique_ptr _settings; const std::unique_ptr _changes; const std::unique_ptr _api; const std::unique_ptr _updates; const std::unique_ptr _sendProgressManager; const std::unique_ptr _downloader; const std::unique_ptr _uploader; const std::unique_ptr _storage; // _data depends on _downloader / _uploader. const std::unique_ptr _data; const UserId _userId; const not_null _user; // _emojiStickersPack depends on _data. const std::unique_ptr _emojiStickersPack; const std::unique_ptr _diceStickersPacks; const std::unique_ptr _giftBoxStickersPacks; const std::unique_ptr _sendAsPeers; const std::unique_ptr _attachWebView; const std::unique_ptr _supportHelper; std::shared_ptr _selfUserpicView; rpl::variable _premiumPossible = false; rpl::event_stream _termsLockChanges; std::unique_ptr _termsLock; base::flat_set> _windows; base::Timer _saveSettingsTimer; QByteArray _tmpPassword; TimeId _tmpPasswordValidUntil = 0; rpl::lifetime _lifetime; }; } // namespace Main