From 2c1fdbe55b6b569694201ba04662998a0d7414d9 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 26 Oct 2025 16:57:22 +0300 Subject: [PATCH] Added ability to retrieve required boost level for peer colors to api. --- Telegram/SourceFiles/api/api_peer_colors.cpp | 30 +++++++++++-------- Telegram/SourceFiles/api/api_peer_colors.h | 9 +++--- .../boxes/peers/edit_peer_color_box.cpp | 12 ++++---- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/api/api_peer_colors.cpp b/Telegram/SourceFiles/api/api_peer_colors.cpp index 5dbdb93e17..330863d90d 100644 --- a/Telegram/SourceFiles/api/api_peer_colors.cpp +++ b/Telegram/SourceFiles/api/api_peer_colors.cpp @@ -97,21 +97,27 @@ const base::flat_map &PeerColors::requiredLevelsChannel() const { return _requiredLevelsChannel; } -int PeerColors::requiredGroupLevelFor(PeerId channel, uint8 index) const { +int PeerColors::requiredLevelFor( + PeerId channel, + uint8 index, + bool isMegagroup, + bool profile) const { if (Data::DecideColorIndex(channel) == index) { return 0; - } else if (const auto i = _requiredLevelsGroup.find(index) - ; i != end(_requiredLevelsGroup)) { - return i->second; } - return 1; -} - -int PeerColors::requiredChannelLevelFor(PeerId channel, uint8 index) const { - if (Data::DecideColorIndex(channel) == index) { - return 0; - } else if (const auto i = _requiredLevelsChannel.find(index) - ; i != end(_requiredLevelsChannel)) { + if (profile) { + const auto it = _profileColors.find(index); + if (it != end(_profileColors)) { + return isMegagroup + ? it->second.requiredLevelsGroup + : it->second.requiredLevelsChannel; + } + return 1; + } + const auto &levels = isMegagroup + ? _requiredLevelsGroup + : _requiredLevelsChannel; + if (const auto i = levels.find(index); i != end(levels)) { return i->second; } return 1; diff --git a/Telegram/SourceFiles/api/api_peer_colors.h b/Telegram/SourceFiles/api/api_peer_colors.h index 7682bc7173..690073d856 100644 --- a/Telegram/SourceFiles/api/api_peer_colors.h +++ b/Telegram/SourceFiles/api/api_peer_colors.h @@ -35,12 +35,11 @@ public: [[nodiscard]] auto requiredLevelsChannel() const -> const base::flat_map &; - [[nodiscard]] int requiredGroupLevelFor( + [[nodiscard]] int requiredLevelFor( PeerId channel, - uint8 index) const; - [[nodiscard]] int requiredChannelLevelFor( - PeerId channel, - uint8 index) const; + uint8 index, + bool isMegagroup, + bool profile) const; [[nodiscard]] std::optional colorProfileFor( not_null peer) const; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp index f3ded56d5b..97997cd8a1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp @@ -572,13 +572,11 @@ void Apply( } else { CheckBoostLevel(show, peer, [=](int level) { const auto peerColors = &peer->session().api().peerColors(); - const auto colorRequired = peer->isMegagroup() - ? peerColors->requiredGroupLevelFor( - peer->id, - values.colorIndex) - : peerColors->requiredChannelLevelFor( - peer->id, - values.colorIndex); + const auto colorRequired = peerColors->requiredLevelFor( + peer->id, + values.colorIndex, + peer->isMegagroup(), + values.forProfile); const auto limits = Data::LevelLimits(&peer->session()); const auto iconRequired = values.backgroundEmojiId ? limits.channelBgIconLevelMin()