2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-05 08:55:59 +00:00

Added initial api support of reactions limit in channels and groups.

This commit is contained in:
23rd
2024-04-12 14:22:57 +03:00
committed by John Preston
parent 5543927042
commit 225c0e0af3
5 changed files with 50 additions and 12 deletions

View File

@@ -75,6 +75,10 @@ std::optional<QString> OnlineTextCommon(LastseenStatus status, TimeId now) {
return std::nullopt;
}
[[nodiscard]] int UniqueReactionsLimit(not_null<Main::AppConfig*> config) {
return config->get<int>("reactions_uniq_max", 11);
}
} // namespace
inline auto AdminRightsValue(not_null<ChannelData*> channel) {
@@ -562,21 +566,45 @@ const AllowedReactions &PeerAllowedReactions(not_null<PeerData*> peer) {
});
}
int UniqueReactionsLimit(not_null<Main::AppConfig*> config) {
return config->get<int>("reactions_uniq_max", 11);
}
int UniqueReactionsLimit(not_null<PeerData*> peer) {
if (const auto channel = peer->asChannel()) {
if (const auto limit = channel->allowedReactions().maxCount) {
return limit;
}
} else if (const auto chat = peer->asChat()) {
if (const auto limit = chat->allowedReactions().maxCount) {
return limit;
}
}
return UniqueReactionsLimit(&peer->session().appConfig());
}
rpl::producer<int> UniqueReactionsLimitValue(
not_null<PeerData*> peer) {
const auto config = &peer->session().appConfig();
return config->value(
) | rpl::map([=] {
auto configValue = peer->session().appConfig().value(
) | rpl::map([config = &peer->session().appConfig()] {
return UniqueReactionsLimit(config);
}) | rpl::distinct_until_changed();
if (const auto channel = peer->asChannel()) {
return rpl::combine(
PeerAllowedReactionsValue(peer),
std::move(configValue)
) | rpl::map([=](const auto &allowedReactions, int limit) {
return allowedReactions.maxCount
? allowedReactions.maxCount
: limit;
});
} else if (const auto chat = peer->asChat()) {
return rpl::combine(
PeerAllowedReactionsValue(peer),
std::move(configValue)
) | rpl::map([=](const auto &allowedReactions, int limit) {
return allowedReactions.maxCount
? allowedReactions.maxCount
: limit;
});
}
return configValue;
}
} // namespace Data