2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Respect boosts restrictions lifting.

This commit is contained in:
John Preston
2024-02-06 17:32:25 +04:00
parent 180b14ea36
commit ea12c2f62c
6 changed files with 35 additions and 11 deletions

View File

@@ -787,7 +787,10 @@ void ChannelData::setSlowmodeSeconds(int seconds) {
}
TimeId ChannelData::slowmodeLastMessage() const {
return (hasAdminRights() || amCreator() || !mgInfo)
return (hasAdminRights()
|| amCreator()
|| unrestrictedByBoosts()
|| !mgInfo)
? 0
: mgInfo->slowmodeLastMessage;
}
@@ -822,20 +825,36 @@ int ChannelData::boostsUnrestrict() const {
return 0;
}
bool ChannelData::unrestrictedByBoosts() const {
if (const auto info = mgInfo.get()) {
return (info->boostsUnrestrict > 0)
&& (info->boostsApplied >= info->boostsUnrestrict);
}
return 0;
}
rpl::producer<bool> ChannelData::unrestrictedByBoostsValue() const {
return mgInfo
? mgInfo->unrestrictedByBoostsChanges.events_starting_with(
unrestrictedByBoosts())
: (rpl::single(false) | rpl::type_erased());
}
void ChannelData::setBoostsUnrestrict(int applied, int unrestrict) {
if (const auto info = mgInfo.get()) {
if (info->boostsApplied == applied
&& info->boostsUnrestrict == unrestrict) {
return;
}
const auto wasUnrestricted = (info->boostsApplied > 0)
&& (info->boostsApplied >= info->boostsUnrestrict);
const auto nowUnrestricted = (applied > 0)
&& (applied >= unrestrict);
const auto wasUnrestricted = unrestrictedByBoosts();
info->boostsApplied = applied;
info->boostsUnrestrict = unrestrict;
const auto nowUnrestricted = unrestrictedByBoosts();
if (wasUnrestricted != nowUnrestricted) {
session().changes().peerUpdated(this, UpdateFlag::Rights);
info->unrestrictedByBoostsChanges.fire_copy(nowUnrestricted);
session().changes().peerUpdated(
this,
UpdateFlag::Rights | UpdateFlag::Slowmode);
}
}
}