From 80aef75ea58c812c699ea8d10183c287b77a14fa Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 25 Oct 2025 14:22:38 +0300 Subject: [PATCH] Added ability to retrieve color data from index for profile to api. --- Telegram/SourceFiles/api/api_peer_colors.cpp | 27 +++++++++++++++----- Telegram/SourceFiles/api/api_peer_colors.h | 4 +++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/api/api_peer_colors.cpp b/Telegram/SourceFiles/api/api_peer_colors.cpp index 7490ee27a3..5dbdb93e17 100644 --- a/Telegram/SourceFiles/api/api_peer_colors.cpp +++ b/Telegram/SourceFiles/api/api_peer_colors.cpp @@ -244,14 +244,29 @@ void PeerColors::applyProfile(const MTPDhelp_peerColors &data) { std::optional PeerColors::colorProfileFor( not_null peer) const { if (const auto colorProfileIndex = peer->colorProfileIndex()) { - const auto i = _profileColors.find(*colorProfileIndex); - if (i != end(_profileColors)) { - return Window::Theme::IsNightMode() - ? i->second.data.dark - : i->second.data.light; - } + return colorProfileFor(*colorProfileIndex); } return std::nullopt; } +std::optional PeerColors::colorProfileFor( + uint8 index) const { + const auto i = _profileColors.find(index); + if (i != end(_profileColors)) { + return Window::Theme::IsNightMode() + ? i->second.data.dark + : i->second.data.light; + } + return std::nullopt; +} + +std::vector PeerColors::profileColorIndices() const { + auto result = std::vector(); + result.reserve(_profileColors.size()); + for (const auto &[index, option] : _profileColors) { + result.push_back(index); + } + return result; +} + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_peer_colors.h b/Telegram/SourceFiles/api/api_peer_colors.h index 2a1fbd501d..7682bc7173 100644 --- a/Telegram/SourceFiles/api/api_peer_colors.h +++ b/Telegram/SourceFiles/api/api_peer_colors.h @@ -44,6 +44,10 @@ public: [[nodiscard]] std::optional colorProfileFor( not_null peer) const; + [[nodiscard]] std::optional colorProfileFor( + uint8 index) const; + + [[nodiscard]] std::vector profileColorIndices() const; private: struct ProfileColorOption {