From 5ba918d2134d59c27393fc2fe94706351e2e2c6a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 14 Jan 2024 04:00:59 +0300 Subject: [PATCH] Added support of chat themes to viewer widget for messages with ttl. --- .../chat_helpers/ttl_media_layer_widget.cpp | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp b/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp index baf5c1be6..e6a71d509 100644 --- a/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/widgets/tooltip.h" +#include "window/section_widget.h" // Window::ChatThemeValueFromPeer. #include "window/themes/window_theme.h" #include "window/window_session_controller.h" #include "styles/style_chat.h" @@ -81,7 +82,10 @@ bool PreviewDelegate::elementIsChatWide() { class PreviewWrap final : public Ui::RpWidget { public: - PreviewWrap(not_null parent, not_null item); + PreviewWrap( + not_null parent, + not_null item, + rpl::producer> theme); ~PreviewWrap(); [[nodiscard]] rpl::producer<> closeRequests() const; @@ -91,9 +95,9 @@ private: [[nodiscard]] QRect elementRect() const; const not_null _item; - const std::unique_ptr _theme; const std::unique_ptr _style; const std::unique_ptr _delegate; + std::shared_ptr _theme; std::unique_ptr _element; rpl::lifetime _elementLifetime; @@ -108,17 +112,23 @@ private: PreviewWrap::PreviewWrap( not_null parent, - not_null item) + not_null item, + rpl::producer> theme) : RpWidget(parent) , _item(item) -, _theme(Window::Theme::DefaultChatThemeOn(lifetime())) , _style(std::make_unique( item->history()->session().colorIndicesValue())) , _delegate(std::make_unique( parent, _style.get(), [=] { update(elementRect()); })) { - _style->apply(_theme.get()); + + std::move( + theme + ) | rpl::start_with_next([=](std::shared_ptr theme) { + _theme = std::move(theme); + _style->apply(_theme.get()); + }, lifetime()); const auto session = &_item->history()->session(); session->data().viewRepaintRequest( @@ -269,7 +279,12 @@ void ShowTTLMediaLayerWidget( not_null item) { const auto parent = controller->content(); const auto show = controller->uiShow(); - auto preview = base::make_unique_q(parent, item); + auto preview = base::make_unique_q( + parent, + item, + Window::ChatThemeValueFromPeer( + controller, + item->history()->peer)); preview->closeRequests( ) | rpl::start_with_next([=] { show->hideLayer();