/* 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 "base/timer.h" #include "data/data_wall_paper.h" class DocumentData; namespace Main { class Session; } // namespace Main namespace Window { class Controller; } // namespace Window namespace Data { class DocumentMedia; struct CloudTheme { uint64 id = 0; uint64 accessHash = 0; QString slug; QString title; DocumentId documentId = 0; UserId createdBy = 0; int usersCount = 0; std::optional paper; std::optional accentColor; std::optional outgoingAccentColor; std::vector outgoingMessagesColors; bool basedOnDark = false; static CloudTheme Parse( not_null session, const MTPDtheme &data, bool parseSettings = false); static CloudTheme Parse( not_null session, const MTPTheme &data, bool parseSettings = false); }; struct ChatTheme { QString emoji; CloudTheme light; CloudTheme dark; }; class CloudThemes final { public: explicit CloudThemes(not_null session); [[nodiscard]] static QString Format(); void refresh(); [[nodiscard]] rpl::producer<> updated() const; [[nodiscard]] const std::vector &list() const; void savedFromEditor(const CloudTheme &data); void remove(uint64 cloudThemeId); void refreshChatThemes(); [[nodiscard]] const std::vector &chatThemes() const; [[nodiscard]] rpl::producer<> chatThemesUpdated() const; [[nodiscard]] std::optional themeForEmoji( const QString &emoji) const; [[nodiscard]] rpl::producer> themeForEmojiValue( const QString &emoji); [[nodiscard]] static bool TestingColors(); static void SetTestingColors(bool testing); [[nodiscard]] QString prepareTestingLink(const CloudTheme &theme) const; [[nodiscard]] std::optional updateThemeFromLink( const QString &emoji, const QMap ¶ms); void applyUpdate(const MTPTheme &theme); void resolve( not_null controller, const QString &slug, const FullMsgId &clickFromMessageId); void showPreview( not_null controller, const MTPTheme &data); void showPreview( not_null controller, const CloudTheme &cloud); void applyFromDocument(const CloudTheme &cloud); private: struct LoadingDocument { CloudTheme theme; DocumentData *document = nullptr; std::shared_ptr documentMedia; rpl::lifetime subscription; Fn)> callback; }; void parseThemes(const QVector &list); void checkCurrentTheme(); void install(); void setupReload(); [[nodiscard]] bool needReload() const; void scheduleReload(); void reloadCurrent(); void previewFromDocument( not_null controller, const CloudTheme &cloud); void loadDocumentAndInvoke( LoadingDocument &value, const CloudTheme &cloud, not_null document, Fn)> callback); void invokeForLoaded(LoadingDocument &value); void parseChatThemes(const QVector &list); const not_null _session; uint64 _hash = 0; mtpRequestId _refreshRequestId = 0; mtpRequestId _resolveRequestId = 0; std::vector _list; rpl::event_stream<> _updates; int32 _chatThemesHash = 0; mtpRequestId _chatThemesRequestId = 0; std::vector _chatThemes; rpl::event_stream<> _chatThemesUpdates; base::Timer _reloadCurrentTimer; LoadingDocument _updatingFrom; LoadingDocument _previewFrom; uint64 _installedDayThemeId = 0; uint64 _installedNightThemeId = 0; rpl::lifetime _lifetime; }; } // namespace Data