From fa785b745bfb24fe14985e9b3f9df41932f8ea03 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 30 Jan 2026 10:50:23 +0300 Subject: [PATCH] Fixed wrong color index fallback when cloud peer color is missing. --- .../data/components/sponsored_messages.cpp | 2 +- Telegram/SourceFiles/data/data_peer.cpp | 24 +++++++++---------- Telegram/SourceFiles/data/data_peer.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/data/components/sponsored_messages.cpp b/Telegram/SourceFiles/data/components/sponsored_messages.cpp index dd79a84e26..4e68421fff 100644 --- a/Telegram/SourceFiles/data/components/sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/components/sponsored_messages.cpp @@ -544,7 +544,7 @@ void SponsoredMessages::append( .mediaPhotoId = (mediaPhoto ? mediaPhoto->id : 0), .mediaDocumentId = (mediaDocument ? mediaDocument->id : 0), .backgroundEmojiId = BackgroundEmojiIdFromColor(data.vcolor()), - .colorIndex = ColorIndexFromColor(data.vcolor()), + .colorIndex = ColorIndexFromColor(data.vcolor()).value_or(0), .isLinkInternal = !UrlRequiresConfirmation(qs(data.vurl())), .isRecommended = data.is_recommended(), .canReport = data.is_can_report(), diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 69b65a1298..06c73aaf94 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -1055,8 +1055,9 @@ bool PeerData::changeColorCollectible( bool PeerData::changeColor( const tl::conditional &cloudColor) { - const auto changed1 = cloudColor - ? changeColorIndex(Data::ColorIndexFromColor(cloudColor)) + const auto maybeColorIndex = Data::ColorIndexFromColor(cloudColor); + const auto changed1 = maybeColorIndex + ? changeColorIndex(*maybeColorIndex) : clearColorIndex(); const auto changed2 = changeBackgroundEmojiId( Data::BackgroundEmojiIdFromColor(cloudColor)); @@ -1066,8 +1067,9 @@ bool PeerData::changeColor( bool PeerData::changeColorProfile( const tl::conditional &cloudColor) { - const auto changed1 = cloudColor - ? changeColorProfileIndex(Data::ColorIndexFromColor(cloudColor)) + const auto maybeColorIndex = Data::ColorIndexFromColor(cloudColor); + const auto changed1 = maybeColorIndex + ? changeColorProfileIndex(*maybeColorIndex) : clearColorProfileIndex(); const auto changed2 = changeProfileBackgroundEmojiId( Data::BackgroundEmojiIdFromColor(cloudColor)); @@ -2207,16 +2209,14 @@ uint64 BackgroundEmojiIdFromColor(const MTPPeerColor *color) { }); } -uint8 ColorIndexFromColor(const MTPPeerColor *color) { +std::optional ColorIndexFromColor(const MTPPeerColor *color) { if (!color) { - return 0; + return std::nullopt; } - return color->match([](const MTPDpeerColor &data) -> uint8 { - return data.vcolor().value_or_empty(); - }, [](const MTPDpeerColorCollectible &data) -> uint8 { - return 0; - }, [](const MTPDinputPeerColorCollectible &) -> uint8 { - return 0; + return color->match([](const MTPDpeerColor &d) -> std::optional { + return d.vcolor() ? std::make_optional(d.vcolor()->v) : std::nullopt; + }, [](const auto &) -> std::optional { + return std::nullopt; }); } diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 44880d4d44..7a44bb6774 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -675,6 +675,6 @@ void SetTopPinnedMessageId( PeerData *migrated = nullptr); [[nodiscard]] uint64 BackgroundEmojiIdFromColor(const MTPPeerColor *color); -[[nodiscard]] uint8 ColorIndexFromColor(const MTPPeerColor *color); +[[nodiscard]] std::optional ColorIndexFromColor(const MTPPeerColor *); } // namespace Data