diff --git a/Telegram/SourceFiles/window/themes/window_themes_chat.cpp b/Telegram/SourceFiles/window/themes/window_themes_chat.cpp index f00c12cad4..7f6378f00a 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_chat.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_chat.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/crc32hash.h" #include "mainwidget.h" +#include "mainwindow.h" #include "ui/chat/chat_theme.h" #include "window/themes/window_theme.h" #include "window/themes/window_theme_editor.h" @@ -130,4 +131,35 @@ void ApplyChatTheme( }); } +void CheckChatThemeWallPaper(not_null controller) { + if (!controller->widget()->sessionContent()) { + return; + } + const auto &cloud = Background()->themeObject().cloud; + if (cloud.emoticon.isEmpty() || cloud.settings.empty()) { + return; + } + const auto used = SettingsTypeFor(cloud, IsNightMode()); + if (!used) { + return; + } + const auto &paper = cloud.settings.find(*used)->second.paper; + if (!paper) { + return; + } + const auto ¤t = Background()->paper(); + if (current.equals(*paper)) { + return; + } + const auto owned = Data::IsDefaultWallPaper(current) + || Data::IsThemeWallPaper(current) + || ranges::any_of(cloud.settings, [&](const auto &entry) { + return entry.second.paper + && entry.second.paper->equals(current); + }); + if (owned) { + controller->content()->setChatBackground(*paper); + } +} + } // namespace Window::Theme diff --git a/Telegram/SourceFiles/window/themes/window_themes_chat.h b/Telegram/SourceFiles/window/themes/window_themes_chat.h index 7f2e82b446..86a00524b2 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_chat.h +++ b/Telegram/SourceFiles/window/themes/window_themes_chat.h @@ -34,4 +34,6 @@ void ApplyChatTheme( const Data::CloudTheme &theme, bool dark); +void CheckChatThemeWallPaper(not_null controller); + } // namespace Window::Theme diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 45ba762b6a..52cf6d7177 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1571,8 +1571,18 @@ SessionController::SessionController( if (update.type == Theme::BackgroundUpdate::Type::New || update.type == Theme::BackgroundUpdate::Type::Changed) { pushDefaultChatBackground(); + } else if (update.type + == Theme::BackgroundUpdate::Type::ApplyingTheme) { + if (_isPrimary) { + Theme::CheckChatThemeWallPaper(this); + } } }, _lifetime); + if (_isPrimary) { + crl::on_main(base::make_weak(this), [=] { + Theme::CheckChatThemeWallPaper(this); + }); + } style::PaletteChanged( ) | rpl::on_next([=] { for (auto &[key, value] : _customChatThemes) {