mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to change reactions limit in channels.
This commit is contained in:
parent
225c0e0af3
commit
df16e7c00b
3 changed files with 144 additions and 17 deletions
|
@ -1495,6 +1495,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"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_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";
|
||||||
|
"lng_manage_peer_reactions_available_ph" = "Add reactions...";
|
||||||
"lng_manage_peer_reactions_own" = "You can also {link} emoji packs and use them as reactions.";
|
"lng_manage_peer_reactions_own" = "You can also {link} emoji packs and use them as reactions.";
|
||||||
"lng_manage_peer_reactions_own_link" = "create your own";
|
"lng_manage_peer_reactions_own_link" = "create your own";
|
||||||
"lng_manage_peer_reactions_level#one" = "Your channel needs to reach level **{count}** to use **{same_count}** custom reaction.";
|
"lng_manage_peer_reactions_level#one" = "Your channel needs to reach level **{count}** to use **{same_count}** custom reaction.";
|
||||||
|
@ -1503,6 +1504,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_manage_peer_reactions_boost_link" = "here";
|
"lng_manage_peer_reactions_boost_link" = "here";
|
||||||
"lng_manage_peer_reactions_limit" = "Channels can't have more custom reactions.";
|
"lng_manage_peer_reactions_limit" = "Channels can't have more custom reactions.";
|
||||||
|
|
||||||
|
"lng_manage_peer_reactions_max_title" = "Maximum number of reactions";
|
||||||
|
"lng_manage_peer_reactions_max_slider#one" = "{count} reaction per post";
|
||||||
|
"lng_manage_peer_reactions_max_slider#other" = "{count} reactions per post";
|
||||||
|
"lng_manage_peer_reactions_max_about" = "Limit the number of different reactions that can be added to a post, including already published ones.";
|
||||||
|
|
||||||
"lng_manage_peer_antispam" = "Aggressive Anti-Spam";
|
"lng_manage_peer_antispam" = "Aggressive Anti-Spam";
|
||||||
"lng_manage_peer_antispam_about" = "Telegram will filter more spam but may occasionally affect ordinary messages. You can report False Positives in Recent Actions.";
|
"lng_manage_peer_antispam_about" = "Telegram will filter more spam but may occasionally affect ordinary messages. You can report False Positives in Recent Actions.";
|
||||||
"lng_manage_peer_antispam_not_enough#one" = "Aggressive filtering can be enabled only in groups with more than **{count} member**.";
|
"lng_manage_peer_antispam_not_enough#one" = "Aggressive filtering can be enabled only in groups with more than **{count} member**.";
|
||||||
|
|
|
@ -7,30 +7,33 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/peers/edit_peer_reactions.h"
|
#include "boxes/peers/edit_peer_reactions.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
#include "base/event_filter.h"
|
#include "base/event_filter.h"
|
||||||
#include "chat_helpers/tabbed_panel.h"
|
#include "chat_helpers/tabbed_panel.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
#include "data/data_chat.h"
|
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
#include "data/data_chat.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_peer_values.h" // UniqueReactionsLimit.
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_user.h"
|
||||||
#include "history/view/reactions/history_view_reactions_selector.h"
|
#include "history/view/reactions/history_view_reactions_selector.h"
|
||||||
#include "main/main_session.h"
|
|
||||||
#include "apiwrap.h"
|
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
#include "ui/boxes/boost_box.h"
|
#include "ui/boxes/boost_box.h"
|
||||||
#include "ui/widgets/fields/input_field.h"
|
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
|
||||||
#include "ui/wrap/slide_wrap.h"
|
|
||||||
#include "ui/vertical_list.h"
|
#include "ui/vertical_list.h"
|
||||||
|
#include "ui/widgets/checkbox.h"
|
||||||
|
#include "ui/widgets/continuous_sliders.h"
|
||||||
|
#include "ui/widgets/fields/input_field.h"
|
||||||
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "window/window_session_controller_link_info.h"
|
#include "window/window_session_controller_link_info.h"
|
||||||
#include "styles/style_chat_helpers.h"
|
#include "styles/style_chat_helpers.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
#include "styles/style_settings.h"
|
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
#include "styles/style_settings.h"
|
||||||
|
|
||||||
#include <QtWidgets/QTextEdit>
|
#include <QtWidgets/QTextEdit>
|
||||||
#include <QtGui/QTextBlock>
|
#include <QtGui/QTextBlock>
|
||||||
|
@ -705,12 +708,16 @@ void EditAllowedReactionsBox(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
changed(selected.empty() ? DefaultSelected() : std::move(selected), {});
|
changed(selected.empty() ? DefaultSelected() : std::move(selected), {});
|
||||||
|
Ui::AddSubsectionTitle(
|
||||||
|
reactions,
|
||||||
|
enabled
|
||||||
|
? tr::lng_manage_peer_reactions_available()
|
||||||
|
: tr::lng_manage_peer_reactions_some_title(),
|
||||||
|
st::manageGroupReactionsFieldPadding);
|
||||||
reactions->add(AddReactionsSelector(reactions, {
|
reactions->add(AddReactionsSelector(reactions, {
|
||||||
.outer = box->getDelegate()->outerContainer(),
|
.outer = box->getDelegate()->outerContainer(),
|
||||||
.controller = args.navigation->parentController(),
|
.controller = args.navigation->parentController(),
|
||||||
.title = (enabled
|
.title = tr::lng_manage_peer_reactions_available_ph(),
|
||||||
? tr::lng_manage_peer_reactions_available()
|
|
||||||
: tr::lng_manage_peer_reactions_some_title()),
|
|
||||||
.list = all,
|
.list = all,
|
||||||
.selected = state->selected,
|
.selected = state->selected,
|
||||||
.callback = changed,
|
.callback = changed,
|
||||||
|
@ -726,6 +733,7 @@ void EditAllowedReactionsBox(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const auto reactionsLimit = container->lifetime().make_state<int>(0);
|
||||||
if (!isGroup) {
|
if (!isGroup) {
|
||||||
AddReactionsText(
|
AddReactionsText(
|
||||||
container,
|
container,
|
||||||
|
@ -733,9 +741,109 @@ void EditAllowedReactionsBox(
|
||||||
args.allowedCustomReactions,
|
args.allowedCustomReactions,
|
||||||
state->customCount.value(),
|
state->customCount.value(),
|
||||||
args.askForBoosts);
|
args.askForBoosts);
|
||||||
|
|
||||||
|
const auto session = &args.navigation->parentController()->session();
|
||||||
|
|
||||||
|
const auto wrap = container->add(
|
||||||
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
container,
|
||||||
|
object_ptr<Ui::VerticalLayout>(container)));
|
||||||
|
const auto max = Data::UniqueReactionsLimit(session->user());
|
||||||
|
const auto inactiveColor = std::make_optional(st::windowSubTextFg->c);
|
||||||
|
const auto activeColor = std::make_optional(
|
||||||
|
st::windowActiveTextFg->c);
|
||||||
|
const auto inner = wrap->entity();
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
Ui::AddSubsectionTitle(
|
||||||
|
inner,
|
||||||
|
tr::lng_manage_peer_reactions_max_title(),
|
||||||
|
st::manageGroupReactionsMaxSubtitlePadding);
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
const auto line = inner->add(
|
||||||
|
object_ptr<Ui::RpWidget>(inner),
|
||||||
|
st::boxRowPadding);
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
const auto left = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
|
line,
|
||||||
|
QString::number(1),
|
||||||
|
st::defaultFlatLabel);
|
||||||
|
const auto center = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
|
line,
|
||||||
|
st::defaultFlatLabel);
|
||||||
|
const auto right = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
|
line,
|
||||||
|
QString::number(max),
|
||||||
|
st::defaultFlatLabel);
|
||||||
|
const auto slider = Ui::CreateChild<Ui::MediaSlider>(
|
||||||
|
line,
|
||||||
|
st::settingsScale);
|
||||||
|
rpl::combine(
|
||||||
|
line->sizeValue(),
|
||||||
|
left->sizeValue(),
|
||||||
|
center->sizeValue(),
|
||||||
|
right->sizeValue()
|
||||||
|
) | rpl::start_with_next([=](
|
||||||
|
const QSize &s,
|
||||||
|
const QSize &leftSize,
|
||||||
|
const QSize ¢erSize,
|
||||||
|
const QSize &rightSize) {
|
||||||
|
const auto sliderHeight = st::settingsScale.seekSize.height();
|
||||||
|
line->resize(
|
||||||
|
line->width(),
|
||||||
|
leftSize.height() + sliderHeight * 2);
|
||||||
|
{
|
||||||
|
const auto r = line->rect();
|
||||||
|
slider->setGeometry(
|
||||||
|
0,
|
||||||
|
r.height() - sliderHeight * 1.5,
|
||||||
|
r.width(),
|
||||||
|
sliderHeight);
|
||||||
|
}
|
||||||
|
left->moveToLeft(0, 0);
|
||||||
|
right->moveToRight(0, 0);
|
||||||
|
center->moveToLeft((s.width() - centerSize.width()) / 2, 0);
|
||||||
|
}, line->lifetime());
|
||||||
|
|
||||||
|
const auto updateLabels = [=](int limit) {
|
||||||
|
left->setTextColorOverride((limit <= 1)
|
||||||
|
? activeColor
|
||||||
|
: inactiveColor);
|
||||||
|
|
||||||
|
center->setText(tr::lng_manage_peer_reactions_max_slider(
|
||||||
|
tr::now,
|
||||||
|
lt_count,
|
||||||
|
limit));
|
||||||
|
center->setTextColorOverride(activeColor);
|
||||||
|
|
||||||
|
right->setTextColorOverride((limit >= max)
|
||||||
|
? activeColor
|
||||||
|
: inactiveColor);
|
||||||
|
|
||||||
|
(*reactionsLimit) = limit;
|
||||||
|
};
|
||||||
|
const auto current = args.allowed.maxCount
|
||||||
|
? std::clamp(1, args.allowed.maxCount, max)
|
||||||
|
: max / 2;
|
||||||
|
slider->setPseudoDiscrete(
|
||||||
|
max,
|
||||||
|
[=](int index) { return index + 1; },
|
||||||
|
current,
|
||||||
|
updateLabels,
|
||||||
|
updateLabels);
|
||||||
|
updateLabels(current);
|
||||||
|
|
||||||
|
wrap->toggleOn(rpl::single(
|
||||||
|
optionInitial != Option::None
|
||||||
|
) | rpl::then(
|
||||||
|
state->selectorState.value(
|
||||||
|
) | rpl::map(rpl::mappers::_1 == SelectorState::Active)));
|
||||||
|
|
||||||
|
Ui::AddDividerText(inner, tr::lng_manage_peer_reactions_max_about());
|
||||||
}
|
}
|
||||||
const auto collect = [=] {
|
const auto collect = [=] {
|
||||||
auto result = AllowedReactions();
|
auto result = AllowedReactions();
|
||||||
|
result.maxCount = (*reactionsLimit);
|
||||||
if (isGroup
|
if (isGroup
|
||||||
? (state->option.current() == Option::Some)
|
? (state->option.current() == Option::Some)
|
||||||
: (enabled->toggled())) {
|
: (enabled->toggled())) {
|
||||||
|
@ -783,6 +891,7 @@ void SaveAllowedReactions(
|
||||||
Data::ReactionToMTP
|
Data::ReactionToMTP
|
||||||
) | ranges::to<QVector<MTPReaction>>;
|
) | ranges::to<QVector<MTPReaction>>;
|
||||||
|
|
||||||
|
using Flag = MTPmessages_SetChatAvailableReactions::Flag;
|
||||||
using Type = Data::AllowedReactionsType;
|
using Type = Data::AllowedReactionsType;
|
||||||
const auto updated = (allowed.type != Type::Some)
|
const auto updated = (allowed.type != Type::Some)
|
||||||
? MTP_chatReactionsAll(MTP_flags((allowed.type == Type::Default)
|
? MTP_chatReactionsAll(MTP_flags((allowed.type == Type::Default)
|
||||||
|
@ -792,16 +901,18 @@ void SaveAllowedReactions(
|
||||||
? MTP_chatReactionsNone()
|
? MTP_chatReactionsNone()
|
||||||
: MTP_chatReactionsSome(MTP_vector<MTPReaction>(ids));
|
: MTP_chatReactionsSome(MTP_vector<MTPReaction>(ids));
|
||||||
peer->session().api().request(MTPmessages_SetChatAvailableReactions(
|
peer->session().api().request(MTPmessages_SetChatAvailableReactions(
|
||||||
MTP_flags(0),
|
allowed.maxCount ? MTP_flags(Flag::f_reactions_limit) : MTP_flags(0),
|
||||||
peer->input,
|
peer->input,
|
||||||
updated,
|
updated,
|
||||||
MTP_int(0) // reactions_limit
|
MTP_int(allowed.maxCount)
|
||||||
)).done([=](const MTPUpdates &result) {
|
)).done([=](const MTPUpdates &result) {
|
||||||
peer->session().api().applyUpdates(result);
|
peer->session().api().applyUpdates(result);
|
||||||
|
auto parsed = Data::Parse(updated);
|
||||||
|
parsed.maxCount = allowed.maxCount;
|
||||||
if (const auto chat = peer->asChat()) {
|
if (const auto chat = peer->asChat()) {
|
||||||
chat->setAllowedReactions(Data::Parse(updated));
|
chat->setAllowedReactions(parsed);
|
||||||
} else if (const auto channel = peer->asChannel()) {
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
channel->setAllowedReactions(Data::Parse(updated));
|
channel->setAllowedReactions(parsed);
|
||||||
} else {
|
} else {
|
||||||
Unexpected("Invalid peer type in SaveAllowedReactions.");
|
Unexpected("Invalid peer type in SaveAllowedReactions.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -647,12 +647,22 @@ manageGroupReactions: IconButton(defaultIconButton) {
|
||||||
iconOver: icon{{ "info/edit/stickers_add", historyComposeIconFgOver }};
|
iconOver: icon{{ "info/edit/stickers_add", historyComposeIconFgOver }};
|
||||||
}
|
}
|
||||||
manageGroupReactionsField: InputField(defaultInputField) {
|
manageGroupReactionsField: InputField(defaultInputField) {
|
||||||
textMargins: margins(1px, 38px, 24px, 8px);
|
textMargins: margins(1px, 12px, 24px, 8px);
|
||||||
placeholderShift: -32px;
|
placeholderFg: placeholderFg;
|
||||||
heightMin: 66px;
|
placeholderFgActive: placeholderFgActive;
|
||||||
|
placeholderFgError: placeholderFgActive;
|
||||||
|
placeholderMargins: margins(1px, 0px, 7px, 0px);
|
||||||
|
placeholderAlign: align(topleft);
|
||||||
|
placeholderScale: 0.;
|
||||||
|
placeholderFont: normalFont;
|
||||||
|
placeholderShift: -50px;
|
||||||
|
font: normalFont;
|
||||||
|
heightMin: 36px;
|
||||||
heightMax: 158px;
|
heightMax: 158px;
|
||||||
}
|
}
|
||||||
|
manageGroupReactionsFieldPadding: margins(0px, 0px, 0px, -9px);
|
||||||
manageGroupReactionsTextSkip: 16px;
|
manageGroupReactionsTextSkip: 16px;
|
||||||
|
manageGroupReactionsMaxSubtitlePadding: margins(0px, 0px, 0px, -3px);
|
||||||
|
|
||||||
infoEmptyFg: windowSubTextFg;
|
infoEmptyFg: windowSubTextFg;
|
||||||
infoEmptyPhoto: icon {{ "info/info_media_photo_empty", infoEmptyFg }};
|
infoEmptyPhoto: icon {{ "info/info_media_photo_empty", infoEmptyFg }};
|
||||||
|
|
Loading…
Add table
Reference in a new issue