mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Return old allowed reactions edit for channels.
This commit is contained in:
parent
7e7562fdad
commit
e0513f7b7c
2 changed files with 77 additions and 29 deletions
|
@ -1200,15 +1200,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_manage_peer_requests" = "Member Requests";
|
"lng_manage_peer_requests" = "Member Requests";
|
||||||
"lng_manage_peer_requests_channel" = "Subscriber Requests";
|
"lng_manage_peer_requests_channel" = "Subscriber Requests";
|
||||||
|
|
||||||
|
"lng_manage_peer_reactions_enable" = "Enable Reactions";
|
||||||
|
"lng_manage_peer_reactions_about_channel" = "Allow subscribers to react to channel posts.";
|
||||||
"lng_manage_peer_reactions_all" = "All reactions";
|
"lng_manage_peer_reactions_all" = "All reactions";
|
||||||
"lng_manage_peer_reactions_all_about" = "Members of the group can use any emoji as reactions to messages.";
|
"lng_manage_peer_reactions_all_about" = "Members of the group can use any emoji as reactions to messages.";
|
||||||
"lng_manage_peer_reactions_all_about_channel" = "Subscribers of this channel can use any emoji as reactions to messages.";
|
|
||||||
"lng_manage_peer_reactions_some" = "Some reactions";
|
"lng_manage_peer_reactions_some" = "Some reactions";
|
||||||
"lng_manage_peer_reactions_some_about" = "You can select emoji that will allow members of your group to react to messages.";
|
"lng_manage_peer_reactions_some_about" = "You can select emoji that will allow members of your group to react to messages.";
|
||||||
"lng_manage_peer_reactions_some_about_channel" = "You can select emoji that will allow subscribers of this channel to react to messages.";
|
|
||||||
"lng_manage_peer_reactions_none" = "No reactions";
|
"lng_manage_peer_reactions_none" = "No reactions";
|
||||||
"lng_manage_peer_reactions_none_about" = "Members of the group can't add any reactions to messages.";
|
"lng_manage_peer_reactions_none_about" = "Members of the group can't add any reactions to messages.";
|
||||||
"lng_manage_peer_reactions_none_about_channel" = "Subscribers of this channel can't add any reactions to messages.";
|
|
||||||
"lng_manage_peer_reactions_some_title" = "Only allow these reactions";
|
"lng_manage_peer_reactions_some_title" = "Only allow these reactions";
|
||||||
"lng_manage_peer_reactions_available" = "Available reactions";
|
"lng_manage_peer_reactions_available" = "Available reactions";
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,9 @@ void EditAllowedReactionsBox(
|
||||||
};
|
};
|
||||||
struct State {
|
struct State {
|
||||||
base::flat_map<ReactionId, not_null<Ui::SettingsButton*>> toggles;
|
base::flat_map<ReactionId, not_null<Ui::SettingsButton*>> toggles;
|
||||||
rpl::variable<Option> option;
|
rpl::variable<Option> option; // For groups.
|
||||||
|
rpl::variable<bool> anyToggled; // For channels.
|
||||||
|
rpl::event_stream<bool> forceToggleAll; // For channels.
|
||||||
};
|
};
|
||||||
const auto state = box->lifetime().make_state<State>(State{
|
const auto state = box->lifetime().make_state<State>(State{
|
||||||
.option = (allowed.type != AllowedReactionsType::Some
|
.option = (allowed.type != AllowedReactionsType::Some
|
||||||
|
@ -53,17 +55,12 @@ void EditAllowedReactionsBox(
|
||||||
: allowed.some.empty()
|
: allowed.some.empty()
|
||||||
? Option::None
|
? Option::None
|
||||||
: Option::Some),
|
: Option::Some),
|
||||||
|
.anyToggled = (allowed.type != Data::AllowedReactionsType::Some),
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto collect = [=] {
|
const auto collect = [=] {
|
||||||
auto result = AllowedReactions{
|
auto result = AllowedReactions();
|
||||||
.type = (state->option.current() != Option::All
|
if (!isGroup || state->option.current() == Option::Some) {
|
||||||
? AllowedReactionsType::Some
|
|
||||||
: isGroup
|
|
||||||
? AllowedReactionsType::All
|
|
||||||
: AllowedReactionsType::Default),
|
|
||||||
};
|
|
||||||
if (state->option.current() == Option::Some) {
|
|
||||||
result.some.reserve(state->toggles.size());
|
result.some.reserve(state->toggles.size());
|
||||||
for (const auto &[id, button] : state->toggles) {
|
for (const auto &[id, button] : state->toggles) {
|
||||||
if (button->toggled()) {
|
if (button->toggled()) {
|
||||||
|
@ -71,17 +68,54 @@ void EditAllowedReactionsBox(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result.type = isGroup
|
||||||
|
? (state->option.current() != Option::All
|
||||||
|
? AllowedReactionsType::Some
|
||||||
|
: AllowedReactionsType::All)
|
||||||
|
: (result.some.size() == state->toggles.size())
|
||||||
|
? AllowedReactionsType::Default
|
||||||
|
: AllowedReactionsType::Some;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto container = box->verticalLayout();
|
const auto container = box->verticalLayout();
|
||||||
|
|
||||||
|
const auto enabled = isGroup ? nullptr : Settings::AddButton(
|
||||||
|
container,
|
||||||
|
tr::lng_manage_peer_reactions_enable(),
|
||||||
|
st::manageGroupButton.button
|
||||||
|
).get();
|
||||||
|
if (enabled && !list.empty()) {
|
||||||
|
AddReactionAnimatedIcon(
|
||||||
|
enabled,
|
||||||
|
enabled->sizeValue(
|
||||||
|
) | rpl::map([=](const QSize &size) {
|
||||||
|
return QPoint(
|
||||||
|
st::manageGroupButton.iconPosition.x(),
|
||||||
|
(size.height() - iconHeight) / 2);
|
||||||
|
}),
|
||||||
|
iconHeight,
|
||||||
|
list.front(),
|
||||||
|
rpl::never<>(),
|
||||||
|
rpl::never<>(),
|
||||||
|
&enabled->lifetime());
|
||||||
|
}
|
||||||
|
if (enabled) {
|
||||||
|
enabled->toggleOn(state->anyToggled.value());
|
||||||
|
enabled->toggledChanges(
|
||||||
|
) | rpl::filter([=](bool value) {
|
||||||
|
return (value != state->anyToggled.current());
|
||||||
|
}) | rpl::start_to_stream(state->forceToggleAll, enabled->lifetime());
|
||||||
|
}
|
||||||
const auto group = std::make_shared<Ui::RadioenumGroup<Option>>(
|
const auto group = std::make_shared<Ui::RadioenumGroup<Option>>(
|
||||||
state->option.current());
|
state->option.current());
|
||||||
group->setChangedCallback([=](Option value) {
|
group->setChangedCallback([=](Option value) {
|
||||||
state->option = value;
|
state->option = value;
|
||||||
});
|
});
|
||||||
const auto addOption = [&](Option option, const QString &text) {
|
const auto addOption = [&](Option option, const QString &text) {
|
||||||
|
if (!isGroup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
container->add(
|
container->add(
|
||||||
object_ptr<Ui::Radioenum<Option>>(
|
object_ptr<Ui::Radioenum<Option>>(
|
||||||
container,
|
container,
|
||||||
|
@ -95,37 +129,39 @@ void EditAllowedReactionsBox(
|
||||||
addOption(Option::Some, tr::lng_manage_peer_reactions_some(tr::now));
|
addOption(Option::Some, tr::lng_manage_peer_reactions_some(tr::now));
|
||||||
addOption(Option::None, tr::lng_manage_peer_reactions_none(tr::now));
|
addOption(Option::None, tr::lng_manage_peer_reactions_none(tr::now));
|
||||||
|
|
||||||
const auto about = [isGroup](Option option) {
|
const auto about = [](Option option) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case Option::All: return isGroup
|
case Option::All: return tr::lng_manage_peer_reactions_all_about();
|
||||||
? tr::lng_manage_peer_reactions_all_about()
|
case Option::Some: return tr::lng_manage_peer_reactions_some_about();
|
||||||
: tr::lng_manage_peer_reactions_all_about_channel();
|
case Option::None: return tr::lng_manage_peer_reactions_none_about();
|
||||||
case Option::Some: return isGroup
|
|
||||||
? tr::lng_manage_peer_reactions_some_about()
|
|
||||||
: tr::lng_manage_peer_reactions_some_about_channel();
|
|
||||||
case Option::None: return isGroup
|
|
||||||
? tr::lng_manage_peer_reactions_none_about()
|
|
||||||
: tr::lng_manage_peer_reactions_none_about_channel();
|
|
||||||
}
|
}
|
||||||
Unexpected("Option value in EditAllowedReactionsBox.");
|
Unexpected("Option value in EditAllowedReactionsBox.");
|
||||||
};
|
};
|
||||||
Settings::AddSkip(container);
|
Settings::AddSkip(container);
|
||||||
Settings::AddDividerText(
|
Settings::AddDividerText(
|
||||||
container,
|
container,
|
||||||
state->option.value() | rpl::map(about) | rpl::flatten_latest());
|
(isGroup
|
||||||
|
? (state->option.value()
|
||||||
|
| rpl::map(about)
|
||||||
|
| rpl::flatten_latest())
|
||||||
|
: tr::lng_manage_peer_reactions_about_channel()));
|
||||||
|
|
||||||
const auto wrap = container->add(
|
const auto wrap = enabled ? nullptr : container->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
container,
|
container,
|
||||||
object_ptr<Ui::VerticalLayout>(container)));
|
object_ptr<Ui::VerticalLayout>(container)));
|
||||||
wrap->toggleOn(state->option.value() | rpl::map(_1 == Option::Some));
|
if (wrap) {
|
||||||
wrap->finishAnimating();
|
wrap->toggleOn(state->option.value() | rpl::map(_1 == Option::Some));
|
||||||
const auto reactions = wrap->entity();
|
wrap->finishAnimating();
|
||||||
|
}
|
||||||
|
const auto reactions = wrap ? wrap->entity() : container.get();
|
||||||
|
|
||||||
Settings::AddSkip(reactions);
|
Settings::AddSkip(reactions);
|
||||||
Settings::AddSubsectionTitle(
|
Settings::AddSubsectionTitle(
|
||||||
reactions,
|
reactions,
|
||||||
tr::lng_manage_peer_reactions_some_title());
|
(enabled
|
||||||
|
? tr::lng_manage_peer_reactions_available()
|
||||||
|
: tr::lng_manage_peer_reactions_some_title()));
|
||||||
|
|
||||||
const auto active = [&](const ReactionId &id) {
|
const auto active = [&](const ReactionId &id) {
|
||||||
return (allowed.type != AllowedReactionsType::Some)
|
return (allowed.type != AllowedReactionsType::Some)
|
||||||
|
@ -153,7 +189,20 @@ void EditAllowedReactionsBox(
|
||||||
rpl::never<>(),
|
rpl::never<>(),
|
||||||
&button->lifetime());
|
&button->lifetime());
|
||||||
state->toggles.emplace(entry.id, button);
|
state->toggles.emplace(entry.id, button);
|
||||||
button->toggleOn(rpl::single(active(entry.id)));
|
button->toggleOn(rpl::single(active(entry.id)) | rpl::then(enabled
|
||||||
|
? (state->forceToggleAll.events() | rpl::type_erased())
|
||||||
|
: rpl::never<bool>()
|
||||||
|
));
|
||||||
|
if (enabled) {
|
||||||
|
button->toggledChanges(
|
||||||
|
) | rpl::start_with_next([=](bool toggled) {
|
||||||
|
if (toggled) {
|
||||||
|
state->anyToggled = true;
|
||||||
|
} else if (collect().some.empty()) {
|
||||||
|
state->anyToggled = false;
|
||||||
|
}
|
||||||
|
}, button->lifetime());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
for (const auto &entry : list) {
|
for (const auto &entry : list) {
|
||||||
add(entry);
|
add(entry);
|
||||||
|
|
Loading…
Add table
Reference in a new issue