From ea12c2f62ce730d9333f6db83d0aae1a775ff828 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 6 Feb 2024 17:32:25 +0400 Subject: [PATCH] Respect boosts restrictions lifting. --- Telegram/Resources/langs/lang.strings | 4 +-- .../boxes/peers/edit_peer_permissions_box.cpp | 2 +- Telegram/SourceFiles/data/data_channel.cpp | 31 +++++++++++++++---- Telegram/SourceFiles/data/data_channel.h | 2 ++ Telegram/SourceFiles/data/data_peer.cpp | 3 +- .../SourceFiles/data/data_peer_values.cpp | 4 ++- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7e7679f6d2..aa05e95416 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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_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_boost_apply#one" = "{from} boosted the group."; -"lng_action_boost_apply#other" = "{from} boosted the group {count} times."; +"lng_action_boost_apply#one" = "{from} boosted the group"; +"lng_action_boost_apply#other" = "{from} boosted the group {count} times"; "lng_similar_channels_title" = "Similar channels"; "lng_similar_channels_view_all" = "View all"; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 36204506e2..9b0747870e 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -889,7 +889,7 @@ void AddBoostsUnrestrictLabels( labels, st::boostsUnrestrictLabel); label->setMarkedText( - TextWithEntities(i ? one : many).append(QString::number(i + 1)), + TextWithEntities(i ? many : one).append(QString::number(i + 1)), context); rpl::combine( labels->widthValue(), diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 39cd1a1ca6..cf9048a5bc 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -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 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); } } } diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index cd12c8a9e0..b822edda5b 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -114,6 +114,7 @@ public: base::flat_map, Restricted> lastRestricted; base::flat_set> markupSenders; base::flat_set> bots; + rpl::event_stream unrestrictedByBoostsChanges; // For admin badges, full admins list with ranks. base::flat_map admins; @@ -440,6 +441,7 @@ public: [[nodiscard]] int boostsApplied() const; [[nodiscard]] int boostsUnrestrict() const; [[nodiscard]] bool unrestrictedByBoosts() const; + [[nodiscard]] rpl::producer unrestrictedByBoostsValue() const; void setBoostsUnrestrict(int applied, int unrestrict); void setInvitePeek(const QString &hash, TimeId expires); diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 1a0abf1345..78c2051a05 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -1122,7 +1122,8 @@ Data::RestrictionCheckResult PeerData::amRestricted( : ChatRestrictions(0)); return (channel->amCreator() || allowByAdminRights(right, channel)) ? Result::Allowed() - : (defaultRestrictions & right) + : ((defaultRestrictions & right) + && !channel->unrestrictedByBoosts()) ? Result::WithEveryone() : (channel->restrictions() & right) ? Result::Explicit() diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index 4a69ae3dbd..0d5393ac81 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -267,11 +267,13 @@ inline auto DefaultRestrictionValue( AdminRightValue( channel, ChatAdminRight::PostMessages), + channel->unrestrictedByBoostsValue(), RestrictionsValue(channel, rights), DefaultRestrictionsValue(channel, rights), [=]( ChannelDataFlags flags, bool postMessagesRight, + bool unrestrictedByBoosts, ChatRestrictions sendRestriction, ChatRestrictions defaultSendRestriction) { const auto notAmInFlags = Flag::Left | Flag::Forbidden; @@ -281,7 +283,7 @@ inline auto DefaultRestrictionValue( || ((flags & Flag::HasLink) && !(flags & Flag::JoinToWrite)); const auto restricted = sendRestriction - | defaultSendRestriction; + | (defaultSendRestriction && !unrestrictedByBoosts); return allowed && !forumRestriction && (postMessagesRight