Added ability to retrieve required boost level for peer colors to api.

This commit is contained in:
23rd
2025-10-26 16:57:22 +03:00
parent b5bce29514
commit 2c1fdbe55b
3 changed files with 27 additions and 24 deletions
+18 -12
View File
@@ -97,21 +97,27 @@ const base::flat_map<uint8, int> &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;
+4 -5
View File
@@ -35,12 +35,11 @@ public:
[[nodiscard]] auto requiredLevelsChannel() const
-> const base::flat_map<uint8, int> &;
[[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<Data::ColorProfileSet> colorProfileFor(
not_null<PeerData*> peer) const;
@@ -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()