diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 1e6ef8012..ac99babc9 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -327,11 +327,12 @@ void EditRestrictedBox::prepare() { const auto prepareRights = (_oldRights.c_chatBannedRights().vflags.v ? _oldRights : Defaults(peer())); - const auto prepareFlags = prepareRights.c_chatBannedRights().vflags.v + const auto prepareFlags = FixDependentRestrictions( + prepareRights.c_chatBannedRights().vflags.v | defaultRestrictions | ((channel && channel->isPublic()) ? (Flag::f_change_info | Flag::f_pin_messages) - : Flags(0)); + : Flags(0))); const auto disabledMessages = [&] { auto result = std::map(); if (!canSave()) { @@ -339,10 +340,11 @@ void EditRestrictedBox::prepare() { ~Flags(0), lang(lng_rights_about_restriction_cant_edit)); } else { - const auto disabled = defaultRestrictions + const auto disabled = FixDependentRestrictions( + defaultRestrictions | ((channel && channel->isPublic()) ? (Flag::f_change_info | Flag::f_pin_messages) - : Flags(0)); + : Flags(0))); result.emplace( disabled, lang(lng_rights_restriction_for_all)); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index adfcd3b21..e27b885fa 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -71,7 +71,8 @@ void ApplyDependencies( return result; }; - while (true) { + const auto maxFixesCount = int(checkboxes.size()); + for (auto i = 0; i != maxFixesCount; ++i) { if (!applySomeDependency()) { break; } @@ -142,10 +143,10 @@ auto Dependencies(ChatRestrictions) { Flag::f_send_stickers, Flag::f_send_inline }, // stickers -> send_media - { Flag::f_send_stickers, Flag::f_send_media }, + { Flag::f_send_stickers, Flag::f_send_messages }, // embed_links -> send_media - { Flag::f_embed_links, Flag::f_send_media }, + { Flag::f_embed_links, Flag::f_send_messages }, // send_media -> send_messages { Flag::f_send_media, Flag::f_send_messages }, @@ -220,14 +221,14 @@ ChatAdminRights DisabledByDefaultRestrictions(not_null peer) { using Flag = ChatAdminRight; using Restriction = ChatRestriction; - const auto restrictions = [&] { + const auto restrictions = FixDependentRestrictions([&] { if (const auto chat = peer->asChat()) { return chat->defaultRestrictions(); } else if (const auto channel = peer->asChannel()) { return channel->defaultRestrictions(); } Unexpected("User in DisabledByDefaultRestrictions."); - }(); + }()); return Flag(0) | ((restrictions & Restriction::f_pin_messages) ? Flag(0) @@ -246,6 +247,32 @@ ChatAdminRights DisabledByDefaultRestrictions(not_null peer) { : Flag::f_change_info); } +ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions) { + const auto &dependencies = Dependencies(restrictions); + + // Fix iOS bug of saving send_inline like embed_links. + // We copy send_stickers to send_inline. + if (restrictions & ChatRestriction::f_send_stickers) { + restrictions |= ChatRestriction::f_send_inline; + } else { + restrictions &= ~ChatRestriction::f_send_inline; + } + + // Apply the strictest. + const auto fixOne = [&] { + for (const auto [first, second] : dependencies) { + if ((restrictions & second) && !(restrictions & first)) { + restrictions |= first; + return true; + } + } + return false; + }; + while (fixOne()) { + } + return restrictions; +} + EditPeerPermissionsBox::EditPeerPermissionsBox( QWidget*, not_null peer) @@ -268,7 +295,7 @@ void EditPeerPermissionsBox::prepare() { using Flags = ChatRestrictions; const auto disabledByAdminRights = DisabledByAdminRights(_peer); - const auto restrictions = [&] { + const auto restrictions = FixDependentRestrictions([&] { if (const auto chat = _peer->asChat()) { return chat->defaultRestrictions() | disabledByAdminRights; @@ -280,7 +307,7 @@ void EditPeerPermissionsBox::prepare() { | disabledByAdminRights; } Unexpected("User in EditPeerPermissionsBox."); - }(); + }()); const auto disabledMessages = [&] { auto result = std::map(); result.emplace( diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h index cd6998f83..e7e07023c 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h @@ -57,3 +57,4 @@ EditFlagsControl CreateEditAdminRights( bool anyoneCanAddMembers); ChatAdminRights DisabledByDefaultRestrictions(not_null peer); +ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions);