diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 6f772e5d2..13bb1d7d6 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" +#include "data/data_cloud_themes.h" #include "dialogs/dialogs_key.h" #include "core/core_cloud_password.h" #include "core/application.h" @@ -3063,6 +3064,13 @@ void ApiWrap::refreshFileReference( MTP_inputWallPaper( MTP_long(data.paperId), MTP_long(data.accessHash)))); + }, [&](Data::FileOriginTheme data) { + request(MTPaccount_GetTheme( + MTP_string(Data::CloudThemes::Format()), + MTP_inputTheme( + MTP_long(data.themeId), + MTP_long(data.accessHash)), + MTP_long(0))); }, [&](std::nullopt_t) { fail(); }); diff --git a/Telegram/SourceFiles/data/data_cloud_themes.cpp b/Telegram/SourceFiles/data/data_cloud_themes.cpp index 79cf7136a..4b3d25229 100644 --- a/Telegram/SourceFiles/data/data_cloud_themes.cpp +++ b/Telegram/SourceFiles/data/data_cloud_themes.cpp @@ -182,7 +182,7 @@ void CloudThemes::showPreview(const CloudTheme &cloud) { void CloudThemes::updateFromDocument( const CloudTheme &cloud, not_null document) { - loadDocumentAndInvoke(_updatingFrom, document, [=] { + loadDocumentAndInvoke(_updatingFrom, cloud, document, [=] { auto preview = Window::Theme::PreviewFromFile( document->data(), document->location().name(), @@ -197,13 +197,14 @@ void CloudThemes::updateFromDocument( void CloudThemes::previewFromDocument( const CloudTheme &cloud, not_null document) { - loadDocumentAndInvoke(_previewFrom, document, [=] { + loadDocumentAndInvoke(_previewFrom, cloud, document, [=] { Core::App().showTheme(document, cloud); }); } void CloudThemes::loadDocumentAndInvoke( LoadingDocument &value, + const CloudTheme &cloud, not_null document, Fn callback) { const auto alreadyWaiting = (value.document != nullptr); @@ -211,7 +212,9 @@ void CloudThemes::loadDocumentAndInvoke( value.document->cancel(); } value.document = document; - value.document->save(Data::FileOrigin(), QString()); // #TODO themes + value.document->save( + Data::FileOriginTheme(cloud.id, cloud.accessHash), + QString()); value.callback = std::move(callback); if (document->loaded()) { invokeForLoaded(value); diff --git a/Telegram/SourceFiles/data/data_cloud_themes.h b/Telegram/SourceFiles/data/data_cloud_themes.h index fcaa036ab..9f1f58033 100644 --- a/Telegram/SourceFiles/data/data_cloud_themes.h +++ b/Telegram/SourceFiles/data/data_cloud_themes.h @@ -50,6 +50,7 @@ public: private: struct LoadingDocument { + CloudTheme theme; DocumentData *document = nullptr; rpl::lifetime subscription; Fn callback; @@ -71,6 +72,7 @@ private: not_null document); void loadDocumentAndInvoke( LoadingDocument &value, + const CloudTheme &cloud, not_null document, Fn callback); void invokeForLoaded(LoadingDocument &value); diff --git a/Telegram/SourceFiles/data/data_file_origin.cpp b/Telegram/SourceFiles/data/data_file_origin.cpp index 93ddb6f2b..9ff88180c 100644 --- a/Telegram/SourceFiles/data/data_file_origin.cpp +++ b/Telegram/SourceFiles/data/data_file_origin.cpp @@ -38,6 +38,14 @@ struct FileReferenceAccumulator { push(data.vdocument()); }); } + void push(const MTPTheme &data) { + data.match([&](const MTPDtheme &data) { + if (const auto document = data.vdocument()) { + push(*document); + } + }, [&](const MTPDthemeDocumentNotModified &data) { + }); + } void push(const MTPWebPage &data) { data.match([&](const MTPDwebPage &data) { if (const auto document = data.vdocument()) { @@ -165,4 +173,8 @@ UpdatedFileReferences GetFileReferences(const MTPWallPaper &data) { return GetFileReferencesHelper(data); } +UpdatedFileReferences GetFileReferences(const MTPTheme &data) { + return GetFileReferencesHelper(data); +} + } // namespace Data diff --git a/Telegram/SourceFiles/data/data_file_origin.h b/Telegram/SourceFiles/data/data_file_origin.h index 940496c51..6c8a0d5f7 100644 --- a/Telegram/SourceFiles/data/data_file_origin.h +++ b/Telegram/SourceFiles/data/data_file_origin.h @@ -74,6 +74,20 @@ struct FileOriginWallpaper { } }; +struct FileOriginTheme { + FileOriginTheme(uint64 themeId, uint64 accessHash) + : themeId(themeId) + , accessHash(accessHash) { + } + + uint64 themeId = 0; + uint64 accessHash = 0; + + inline bool operator<(const FileOriginTheme &other) const { + return themeId < other.themeId; + } +}; + struct FileOrigin { using Variant = base::optional_variant< FileOriginMessage, @@ -81,7 +95,8 @@ struct FileOrigin { FileOriginPeerPhoto, FileOriginStickerSet, FileOriginSavedGifs, - FileOriginWallpaper>; + FileOriginWallpaper, + FileOriginTheme>; FileOrigin() = default; FileOrigin(FileOriginMessage data) : data(data) { @@ -96,6 +111,8 @@ struct FileOrigin { } FileOrigin(FileOriginWallpaper data) : data(data) { } + FileOrigin(FileOriginTheme data) : data(data) { + } explicit operator bool() const { return data.has_value(); @@ -140,5 +157,6 @@ UpdatedFileReferences GetFileReferences( UpdatedFileReferences GetFileReferences(const MTPmessages_StickerSet &data); UpdatedFileReferences GetFileReferences(const MTPmessages_SavedGifs &data); UpdatedFileReferences GetFileReferences(const MTPWallPaper &data); +UpdatedFileReferences GetFileReferences(const MTPTheme &data); } // namespace Data diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 7a2103084..1a15a1e69 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -520,16 +520,18 @@ void CloudList::refreshElementUsing( void CloudList::refreshColors(Element &element) { const auto currentId = Background()->themeObject().cloud.id; - const auto documentId = element.theme.documentId; - const auto document = documentId - ? _window->session().data().document(documentId).get() + const auto &theme = element.theme; + const auto document = theme.documentId + ? _window->session().data().document(theme.documentId).get() : nullptr; if (element.id() == kFakeCloudThemeId || ((element.id() == currentId) && (!document || !document->isTheme()))) { element.check->setColors(ColorsFromCurrentTheme()); } else if (document) { - document->save(Data::FileOrigin(), QString()); // #TODO themes + document->save( + Data::FileOriginTheme(theme.id, theme.accessHash), + QString()); if (document->loaded()) { refreshColorsFromDocument(element, document); } else {