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

@ -1198,10 +1198,14 @@ void ApplyChannelUpdate(
}
channel->setThemeEmoji(qs(update.vtheme_emoticon().value_or_empty()));
channel->setTranslationDisabled(update.is_translations_disabled());
const auto reactionsLimit = update.vreactions_limit().value_or_empty();
if (const auto allowed = update.vavailable_reactions()) {
channel->setAllowedReactions(Data::Parse(*allowed));
auto parsed = Data::Parse(*allowed);
parsed.maxCount = reactionsLimit;
channel->setAllowedReactions(std::move(parsed));
} else {
channel->setAllowedReactions({});
channel->setAllowedReactions({ .maxCount = reactionsLimit });
}
channel->owner().stories().apply(channel, update.vstories());
channel->fullUpdated();

View File

@ -471,10 +471,13 @@ void ApplyChatUpdate(not_null<ChatData*> chat, const MTPDchatFull &update) {
chat->checkFolder(update.vfolder_id().value_or_empty());
chat->setThemeEmoji(qs(update.vtheme_emoticon().value_or_empty()));
chat->setTranslationDisabled(update.is_translations_disabled());
const auto reactionsLimit = update.vreactions_limit().value_or_empty();
if (const auto allowed = update.vavailable_reactions()) {
chat->setAllowedReactions(Data::Parse(*allowed));
auto parsed = Data::Parse(*allowed);
parsed.maxCount = reactionsLimit;
chat->setAllowedReactions(std::move(parsed));
} else {
chat->setAllowedReactions({});
chat->setAllowedReactions({ .maxCount = reactionsLimit });
}
chat->fullUpdated();
chat->setAbout(qs(update.vabout()));

View File

@ -104,7 +104,9 @@ bool operator<(
bool operator==(
const AllowedReactions &a,
const AllowedReactions &b) {
return (a.type == b.type) && (a.some == b.some);
return (a.type == b.type)
&& (a.some == b.some)
&& (a.maxCount == b.maxCount);
}
AllowedReactions Parse(const MTPChatReactions &value) {

View File

@ -110,6 +110,7 @@ enum class AllowedReactionsType {
struct AllowedReactions {
std::vector<ReactionId> some;
AllowedReactionsType type = AllowedReactionsType::Some;
int maxCount = 0;
};
bool operator<(const AllowedReactions &a, const AllowedReactions &b);

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