diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index edf2f2737..90c6a3ed1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -207,16 +207,36 @@ ChatRestrictions DisabledByAdminRights(not_null peer) { : Flag::ChangeInfo); } +not_null AddDefaultCheckbox( + not_null container, + const QString &text, + bool toggled, + bool locked) { + auto toggle = std::make_unique( + st::rightsToggle, + toggled); + toggle->setLocked(locked); + return container->add( + object_ptr( + container, + text, + st::rightsCheckbox, + std::move(toggle)), + st::rightsToggleMargin); +}; + template < typename Flags, typename DisabledMessagePairs, - typename FlagLabelPairs> + typename FlagLabelPairs, + typename CheckboxFactory> [[nodiscard]] EditFlagsControl CreateEditFlags( not_null container, rpl::producer header, Flags checked, const DisabledMessagePairs &disabledMessagePairs, - const FlagLabelPairs &flagLabelPairs) { + const FlagLabelPairs &flagLabelPairs, + CheckboxFactory checkboxFactory) { const auto checkboxes = container->lifetime( ).make_state>>(); @@ -255,17 +275,11 @@ template < ? std::make_optional(lockedIt->second) : std::nullopt; const auto toggled = ((checked & flags) != 0); - auto toggle = std::make_unique( - st::rightsToggle, - toggled); - toggle->setLocked(locked.has_value()); - const auto control = container->add( - object_ptr( - container, - text, - st::rightsCheckbox, - std::move(toggle)), - st::rightsToggleMargin); + const auto control = checkboxFactory( + container, + text, + toggled, + locked.has_value()); control->checkedChanges( ) | rpl::start_with_next([=](bool checked) { if (locked.has_value()) { @@ -740,7 +754,8 @@ EditFlagsControl CreateEditRestrictions( header, NegateRestrictions(restrictions), disabledMessages, - RestrictionLabels(options)); + RestrictionLabels(options), + AddDefaultCheckbox); result.widget = std::move(widget); result.value = [original = std::move(result.value)]{ return NegateRestrictions(original()); @@ -764,7 +779,8 @@ EditFlagsControl CreateEditAdminRights( header, rights, disabledMessages, - AdminRightLabels(options)); + AdminRightLabels(options), + AddDefaultCheckbox); result.widget = std::move(widget); return result; }