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

@ -1742,8 +1742,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_action_giveaway_results#other" = "{count} winners of the giveaway were randomly selected by Telegram and received private messages with giftcodes."; "lng_action_giveaway_results#other" = "{count} winners of the giveaway were randomly selected by Telegram and received private messages with giftcodes.";
"lng_action_giveaway_results_some" = "Some winners of the giveaway were randomly selected by Telegram and received private messages with giftcodes."; "lng_action_giveaway_results_some" = "Some winners of the giveaway were randomly selected by Telegram and received private messages with giftcodes.";
"lng_action_giveaway_results_none" = "No winners of the giveaway could be selected."; "lng_action_giveaway_results_none" = "No winners of the giveaway could be selected.";
"lng_action_boost_apply#one" = "{from} boosted the group."; "lng_action_boost_apply#one" = "{from} boosted the group";
"lng_action_boost_apply#other" = "{from} boosted the group {count} times."; "lng_action_boost_apply#other" = "{from} boosted the group {count} times";
"lng_similar_channels_title" = "Similar channels"; "lng_similar_channels_title" = "Similar channels";
"lng_similar_channels_view_all" = "View all"; "lng_similar_channels_view_all" = "View all";

View file

@ -889,7 +889,7 @@ void AddBoostsUnrestrictLabels(
labels, labels,
st::boostsUnrestrictLabel); st::boostsUnrestrictLabel);
label->setMarkedText( label->setMarkedText(
TextWithEntities(i ? one : many).append(QString::number(i + 1)), TextWithEntities(i ? many : one).append(QString::number(i + 1)),
context); context);
rpl::combine( rpl::combine(
labels->widthValue(), labels->widthValue(),

View file

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

View file

@ -114,6 +114,7 @@ public:
base::flat_map<not_null<UserData*>, Restricted> lastRestricted; base::flat_map<not_null<UserData*>, Restricted> lastRestricted;
base::flat_set<not_null<PeerData*>> markupSenders; base::flat_set<not_null<PeerData*>> markupSenders;
base::flat_set<not_null<UserData*>> bots; base::flat_set<not_null<UserData*>> bots;
rpl::event_stream<bool> unrestrictedByBoostsChanges;
// For admin badges, full admins list with ranks. // For admin badges, full admins list with ranks.
base::flat_map<UserId, QString> admins; base::flat_map<UserId, QString> admins;
@ -440,6 +441,7 @@ public:
[[nodiscard]] int boostsApplied() const; [[nodiscard]] int boostsApplied() const;
[[nodiscard]] int boostsUnrestrict() const; [[nodiscard]] int boostsUnrestrict() const;
[[nodiscard]] bool unrestrictedByBoosts() const; [[nodiscard]] bool unrestrictedByBoosts() const;
[[nodiscard]] rpl::producer<bool> unrestrictedByBoostsValue() const;
void setBoostsUnrestrict(int applied, int unrestrict); void setBoostsUnrestrict(int applied, int unrestrict);
void setInvitePeek(const QString &hash, TimeId expires); void setInvitePeek(const QString &hash, TimeId expires);

View file

@ -1122,7 +1122,8 @@ Data::RestrictionCheckResult PeerData::amRestricted(
: ChatRestrictions(0)); : ChatRestrictions(0));
return (channel->amCreator() || allowByAdminRights(right, channel)) return (channel->amCreator() || allowByAdminRights(right, channel))
? Result::Allowed() ? Result::Allowed()
: (defaultRestrictions & right) : ((defaultRestrictions & right)
&& !channel->unrestrictedByBoosts())
? Result::WithEveryone() ? Result::WithEveryone()
: (channel->restrictions() & right) : (channel->restrictions() & right)
? Result::Explicit() ? Result::Explicit()

View file

@ -267,11 +267,13 @@ inline auto DefaultRestrictionValue(
AdminRightValue( AdminRightValue(
channel, channel,
ChatAdminRight::PostMessages), ChatAdminRight::PostMessages),
channel->unrestrictedByBoostsValue(),
RestrictionsValue(channel, rights), RestrictionsValue(channel, rights),
DefaultRestrictionsValue(channel, rights), DefaultRestrictionsValue(channel, rights),
[=]( [=](
ChannelDataFlags flags, ChannelDataFlags flags,
bool postMessagesRight, bool postMessagesRight,
bool unrestrictedByBoosts,
ChatRestrictions sendRestriction, ChatRestrictions sendRestriction,
ChatRestrictions defaultSendRestriction) { ChatRestrictions defaultSendRestriction) {
const auto notAmInFlags = Flag::Left | Flag::Forbidden; const auto notAmInFlags = Flag::Left | Flag::Forbidden;
@ -281,7 +283,7 @@ inline auto DefaultRestrictionValue(
|| ((flags & Flag::HasLink) || ((flags & Flag::HasLink)
&& !(flags & Flag::JoinToWrite)); && !(flags & Flag::JoinToWrite));
const auto restricted = sendRestriction const auto restricted = sendRestriction
| defaultSendRestriction; | (defaultSendRestriction && !unrestrictedByBoosts);
return allowed return allowed
&& !forumRestriction && !forumRestriction
&& (postMessagesRight && (postMessagesRight