From 68ddaae984cfa40648c5fffeac211554fc77d71e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 14 Jul 2026 09:29:54 +0300 Subject: [PATCH] Added applying of wallpaper pattern from theme settings. --- .../SourceFiles/data/data_cloud_themes.cpp | 43 +++++++++++++------ Telegram/SourceFiles/storage/localstorage.cpp | 2 +- .../window/themes/window_theme_editor_box.cpp | 2 +- .../window/themes/window_themes_chat.cpp | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/data/data_cloud_themes.cpp b/Telegram/SourceFiles/data/data_cloud_themes.cpp index 504de7a39e..7bcc3e412c 100644 --- a/Telegram/SourceFiles/data/data_cloud_themes.cpp +++ b/Telegram/SourceFiles/data/data_cloud_themes.cpp @@ -63,6 +63,19 @@ constexpr auto kGiftThemesLimit = 24; bool IsTestingColors/* = false*/; +[[nodiscard]] Window::SessionController *ChatThemeWindow( + not_null session) { + const auto &windows = session->windows(); + if (windows.empty()) { + return nullptr; + } + const auto primary = ranges::find_if(windows, []( + not_null window) { + return window->isPrimary(); + }); + return (primary != end(windows)) ? *primary : windows.front(); +} + } // namespace CloudTheme CloudTheme::Parse( @@ -308,14 +321,23 @@ void CloudThemes::reloadCurrent() { void CloudThemes::applyUpdate(const MTPTheme &theme) { theme.match([&](const MTPDtheme &data) { - const auto cloud = CloudTheme::Parse(_session, data); + const auto cloud = CloudTheme::Parse(_session, data, true); const auto &object = Window::Theme::Background()->themeObject(); - if ((cloud.id != object.cloud.id) - || (cloud.documentId == object.cloud.documentId) - || !cloud.documentId) { + if (cloud.id != object.cloud.id) { + return; + } else if (cloud.documentId + && (cloud.documentId != object.cloud.documentId)) { + applyFromDocument(cloud); + return; + } else if (cloud.settings.empty()) { return; } - applyFromDocument(cloud); + auto updated = object; + updated.cloud = cloud; + Window::Theme::Background()->setThemeObject(updated); + if (const auto controller = ChatThemeWindow(_session)) { + Window::Theme::CheckChatThemeWallPaper(controller); + } }); scheduleReload(); } @@ -819,17 +841,10 @@ void CloudThemes::checkAppliedChatTheme() { if (!fresh) { return; } - const auto &windows = _session->windows(); - if (windows.empty()) { + const auto controller = ChatThemeWindow(_session); + if (!controller) { return; } - const auto primary = ranges::find_if(windows, []( - not_null window) { - return window->isPrimary(); - }); - const auto controller = (primary != end(windows)) - ? *primary - : windows.front(); if (!SameThemeSettings(cloud.settings, fresh->settings)) { ApplyChatTheme( controller, diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index cf24826568..88b564424e 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -1069,7 +1069,7 @@ void writeTheme(const Window::Theme::Saved &saved) { const auto &cache = saved.cache; const auto tag = QString(kThemeNewPathRelativeTag); auto chatTheme = QByteArray(); - if (!object.cloud.emoticon.isEmpty() && !object.cloud.settings.empty()) { + if (!object.cloud.settings.empty()) { auto stream = QDataStream(&chatTheme, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_1); stream diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 8e01d2c498..b458a0d702 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -516,7 +516,7 @@ Fn SavePreparedTheme( done(); const auto cloud = result.match([&](const MTPDtheme &data) { - const auto result = Data::CloudTheme::Parse(session, data); + const auto result = Data::CloudTheme::Parse(session, data, true); session->data().cloudThemes().savedFromEditor(result); return result; }); diff --git a/Telegram/SourceFiles/window/themes/window_themes_chat.cpp b/Telegram/SourceFiles/window/themes/window_themes_chat.cpp index 38bed4e554..e332c0678b 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_chat.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_chat.cpp @@ -359,7 +359,7 @@ void CheckChatThemeWallPaper(not_null controller) { } const auto background = Background(); auto cloud = background->themeObject().cloud; - if (cloud.emoticon.isEmpty() || cloud.settings.empty()) { + if (cloud.settings.empty()) { return; } auto used = ChatThemeVariant(cloud, IsNightMode());