Fixed respect of locked state in list of chat participant statuses.

This commit is contained in:
23rd 2023-01-30 04:57:04 +03:00 committed by John Preston
parent 7b7ff32c94
commit fda49a3bfa

View file

@ -181,7 +181,8 @@ not_null<Ui::SettingsButton*> SendMediaToggle(
rpl::producer<int> checkedValue, rpl::producer<int> checkedValue,
int total, int total,
not_null<Ui::SlideWrap<>*> wrap, not_null<Ui::SlideWrap<>*> wrap,
Fn<void(bool)> toggleMedia) { Fn<void(bool)> toggleMedia,
std::optional<QString> locked) {
const auto &stButton = st::rightsButton; const auto &stButton = st::rightsButton;
const auto button = container->add(object_ptr<Ui::SettingsButton>( const auto button = container->add(object_ptr<Ui::SettingsButton>(
container, container,
@ -219,6 +220,8 @@ not_null<Ui::SettingsButton*> SendMediaToggle(
using namespace rpl::mappers; using namespace rpl::mappers;
button->toggleOn(rpl::duplicate(checkedValue) | rpl::map(_1 > 0), true); button->toggleOn(rpl::duplicate(checkedValue) | rpl::map(_1 > 0), true);
toggleButton->toggleOn(button->toggledValue(), true); toggleButton->toggleOn(button->toggledValue(), true);
button->setToggleLocked(locked.has_value());
toggleButton->setToggleLocked(locked.has_value());
struct State final { struct State final {
Ui::Animations::Simple animation; Ui::Animations::Simple animation;
}; };
@ -278,14 +281,29 @@ not_null<Ui::SettingsButton*> SendMediaToggle(
st::slideWrapDuration); st::slideWrapDuration);
}, button->lifetime()); }, button->lifetime());
const auto handleLocked = [=] {
if (locked.has_value()) {
Ui::ShowMultilineToast({
.parentOverride = container,
.text = { *locked },
});
return true;
}
return false;
};
button->clicks( button->clicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
wrap->toggle(!wrap->toggled(), anim::type::normal); if (!handleLocked()) {
wrap->toggle(!wrap->toggled(), anim::type::normal);
}
}, button->lifetime()); }, button->lifetime());
toggleButton->clicks( toggleButton->clicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
toggleMedia(!button->toggled()); if (!handleLocked()) {
toggleMedia(!button->toggled());
}
}, toggleButton->lifetime()); }, toggleButton->lifetime());
return button; return button;
@ -340,13 +358,11 @@ not_null<Ui::SettingsButton*> AddInnerCheckbox(
not_null<Ui::SettingsButton*> AddDefaultCheckbox( not_null<Ui::SettingsButton*> AddDefaultCheckbox(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const QString &text, const QString &text,
bool toggled, bool toggled) {
bool locked) {
const auto button = Settings::AddButton( const auto button = Settings::AddButton(
container, container,
rpl::single(text), rpl::single(text),
st::rightsButton); st::rightsButton);
button->setToggleLocked(locked);
return button; return button;
}; };
@ -456,10 +472,11 @@ template <
flags, flags,
text, text,
toggled, toggled,
locked.has_value(), locked,
[=](bool v) { flagCheck->second.checkChanges.fire_copy(v); }); [=](bool v) { flagCheck->second.checkChanges.fire_copy(v); });
flagCheck->second.widget = Ui::MakeWeak(control); flagCheck->second.widget = Ui::MakeWeak(control);
control->toggleOn(flagCheck->second.checkChanges.events()); control->toggleOn(flagCheck->second.checkChanges.events());
control->setToggleLocked(locked.has_value());
control->toggledChanges( control->toggledChanges(
) | rpl::start_with_next([=](bool checked) { ) | rpl::start_with_next([=](bool checked) {
if (locked.has_value()) { if (locked.has_value()) {
@ -941,7 +958,7 @@ EditFlagsControl<ChatRestrictions, Ui::RpWidget> CreateEditRestrictions(
ChatRestrictions flags, ChatRestrictions flags,
const QString &text, const QString &text,
bool toggled, bool toggled,
bool locked, std::optional<QString> locked,
Fn<void(bool)> toggleCallback) { Fn<void(bool)> toggleCallback) {
const auto isMedia = ranges::any_of( const auto isMedia = ranges::any_of(
mediaRestrictions, mediaRestrictions,
@ -952,14 +969,19 @@ EditFlagsControl<ChatRestrictions, Ui::RpWidget> CreateEditRestrictions(
auto wrap = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( auto wrap = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container, container,
object_ptr<Ui::VerticalLayout>(container)); object_ptr<Ui::VerticalLayout>(container));
if (locked.has_value()) {
wrap->hide(anim::type::instant);
}
SendMediaToggle( SendMediaToggle(
container, container,
state->restrictions.events_starting_with( state->restrictions.events_starting_with(
0 ChatRestrictions(0)
) | rpl::map([=](ChatRestrictions r) -> int { ) | rpl::map([=](ChatRestrictions r) -> int {
return ranges::count_if( return (r == ChatRestrictions(0))
mediaRestrictions, ? 0
[&](auto f) { return !(r & f); }); : ranges::count_if(
mediaRestrictions,
[&](auto f) { return !(r & f); });
}), }),
mediaRestrictions.size(), mediaRestrictions.size(),
wrap.data(), wrap.data(),
@ -967,7 +989,8 @@ EditFlagsControl<ChatRestrictions, Ui::RpWidget> CreateEditRestrictions(
for (auto &callback : state->mediaToggleCallbacks) { for (auto &callback : state->mediaToggleCallbacks) {
callback(toggled); callback(toggled);
} }
}); },
locked);
state->inner = container->add(std::move(wrap)); state->inner = container->add(std::move(wrap));
} }
const auto checkbox = AddInnerCheckbox( const auto checkbox = AddInnerCheckbox(
@ -977,7 +1000,7 @@ EditFlagsControl<ChatRestrictions, Ui::RpWidget> CreateEditRestrictions(
state->restrictions.events() | rpl::to_empty); state->restrictions.events() | rpl::to_empty);
return checkbox; return checkbox;
} else { } else {
return AddDefaultCheckbox(container, text, toggled, locked); return AddDefaultCheckbox(container, text, toggled);
} }
}; };
auto result = CreateEditFlags( auto result = CreateEditFlags(
@ -1017,9 +1040,9 @@ EditFlagsControl<ChatAdminRights, Ui::RpWidget> CreateEditAdminRights(
ChatAdminRights flags, ChatAdminRights flags,
const QString &text, const QString &text,
bool toggled, bool toggled,
bool locked, std::optional<QString>,
auto callback) { auto&&) {
return AddDefaultCheckbox(container, text, toggled, locked); return AddDefaultCheckbox(container, text, toggled);
}; };
auto result = CreateEditFlags( auto result = CreateEditFlags(
widget.data(), widget.data(),