Added ability to retrieve color data from index for profile to api.

This commit is contained in:
23rd
2025-10-25 14:22:38 +03:00
parent c940062787
commit 80aef75ea5
2 changed files with 25 additions and 6 deletions
+21 -6
View File
@@ -244,14 +244,29 @@ void PeerColors::applyProfile(const MTPDhelp_peerColors &data) {
std::optional<Data::ColorProfileSet> PeerColors::colorProfileFor(
not_null<PeerData*> 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<Data::ColorProfileSet> 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<uint8> PeerColors::profileColorIndices() const {
auto result = std::vector<uint8>();
result.reserve(_profileColors.size());
for (const auto &[index, option] : _profileColors) {
result.push_back(index);
}
return result;
}
} // namespace Api
@@ -44,6 +44,10 @@ public:
[[nodiscard]] std::optional<Data::ColorProfileSet> colorProfileFor(
not_null<PeerData*> peer) const;
[[nodiscard]] std::optional<Data::ColorProfileSet> colorProfileFor(
uint8 index) const;
[[nodiscard]] std::vector<uint8> profileColorIndices() const;
private:
struct ProfileColorOption {