From cd5a6025f6f5764872bf2da78f253f2acc3a82cc Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 16 Dec 2023 23:52:55 +0000 Subject: [PATCH] Support pre-defined channel wallpapers resolving. --- Telegram/SourceFiles/data/data_wall_paper.cpp | 9 +++- Telegram/SourceFiles/data/data_wall_paper.h | 2 + .../SourceFiles/window/section_widget.cpp | 49 ++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/data/data_wall_paper.cpp b/Telegram/SourceFiles/data/data_wall_paper.cpp index 3f97d1e29..5b2ca28b5 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.cpp +++ b/Telegram/SourceFiles/data/data_wall_paper.cpp @@ -198,9 +198,14 @@ WallPaperId WallPaper::id() const { return _id; } +QString WallPaper::emojiId() const { + return _emojiId; +} + bool WallPaper::equals(const WallPaper &paper) const { return (_flags == paper._flags) && (_slug == paper._slug) + && (_emojiId == paper._emojiId) && (_backgroundColors == paper._backgroundColors) && (_rotation == paper._rotation) && (_intensity == paper._intensity) @@ -362,6 +367,7 @@ MTPWallPaperSettings WallPaper::mtpSettings() const { MTP_flags((_blurred ? Flag::f_blur : Flag(0)) | Flag::f_intensity | Flag::f_rotation + | (_emojiId.isEmpty() ? Flag() : Flag::f_emoticon) | flagForIndex(0) | flagForIndex(1) | flagForIndex(2) @@ -372,7 +378,7 @@ MTPWallPaperSettings WallPaper::mtpSettings() const { serializeForIndex(3), MTP_int(_intensity), MTP_int(_rotation), - MTPstring()); // emoticon + MTP_string(_emojiId)); } WallPaper WallPaper::withUrlParams( @@ -520,6 +526,7 @@ std::optional WallPaper::Create(const MTPDwallPaperNoFile &data) { if (const auto rotation = data.vrotation()) { result._rotation = rotation->v; } + result._emojiId = qs(data.vemoticon().value_or_empty()); }); } return result; diff --git a/Telegram/SourceFiles/data/data_wall_paper.h b/Telegram/SourceFiles/data/data_wall_paper.h index fb98eb9de..93da268cd 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.h +++ b/Telegram/SourceFiles/data/data_wall_paper.h @@ -45,6 +45,7 @@ public: [[nodiscard]] bool equals(const WallPaper &paper) const; [[nodiscard]] WallPaperId id() const; + [[nodiscard]] QString emojiId() const; [[nodiscard]] bool isNull() const; [[nodiscard]] QString key() const; [[nodiscard]] const std::vector backgroundColors() const; @@ -114,6 +115,7 @@ private: UserId _ownerId = 0; WallPaperFlags _flags; QString _slug; + QString _emojiId; std::vector _backgroundColors; int _rotation = 0; diff --git a/Telegram/SourceFiles/window/section_widget.cpp b/Telegram/SourceFiles/window/section_widget.cpp index d08a28c59..24032e00a 100644 --- a/Telegram/SourceFiles/window/section_widget.cpp +++ b/Telegram/SourceFiles/window/section_widget.cpp @@ -50,13 +50,58 @@ struct ResolvedPaper { std::shared_ptr media; }; -[[nodiscard]] rpl::producer> PeerWallPaperValue( +[[nodiscard]] rpl::producer PeerWallPaperMapped( not_null peer) { return peer->session().changes().peerFlagsValue( peer, Data::PeerUpdate::Flag::ChatWallPaper - ) | rpl::map([=]() -> rpl::producer> { + ) | rpl::map([=]() -> rpl::producer { const auto paper = peer->wallPaper(); + const auto id = paper ? paper->emojiId() : QString(); + if (id.isEmpty()) { + return rpl::single(paper); + } + const auto themes = &peer->owner().cloudThemes(); + auto fromThemes = [=](bool force) + -> rpl::producer { + if (themes->chatThemes().empty() && !force) { + return nullptr; + } + return Window::Theme::IsNightModeValue( + ) | rpl::map([=](bool dark) -> const Data::WallPaper* { + const auto &list = themes->chatThemes(); + const auto i = ranges::find( + list, + id, + &Data::CloudTheme::emoticon); + if (i != end(list)) { + using Type = Data::CloudThemeType; + const auto type = dark ? Type::Dark : Type::Light; + const auto j = i->settings.find(type); + if (j != end(i->settings) && j->second.paper) { + return &*j->second.paper; + } + } + return nullptr; + }); + }; + if (auto result = fromThemes(false)) { + return result; + } + themes->refreshChatThemes(); + return themes->chatThemesUpdated( + ) | rpl::take(1) | rpl::map([=] { + return fromThemes(true); + }) | rpl::flatten_latest(); + }) | rpl::flatten_latest(); +} + +[[nodiscard]] rpl::producer> PeerWallPaperValue( + not_null peer) { + return PeerWallPaperMapped( + peer + ) | rpl::map([=](const Data::WallPaper *paper) + -> rpl::producer> { const auto single = [](std::optional value) { return rpl::single(std::move(value)); };