mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Allow disabling animations in folder emoji.
This commit is contained in:
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/filters/edit_filter_box.h"
|
||||
#include "boxes/premium_limits_box.h"
|
||||
#include "core/application.h" // primaryWindow
|
||||
#include "core/ui_integration.h"
|
||||
#include "data/data_chat_filters.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_session.h"
|
||||
@@ -22,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/text/text_utilities.h" // Ui::Text::Bold
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/menu/menu_action.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
@@ -169,15 +171,26 @@ void ChangeFilterById(
|
||||
)).done([=, chat = history->peer->name(), name = filter.title()] {
|
||||
const auto account = not_null(&history->session().account());
|
||||
if (const auto controller = Core::App().windowFor(account)) {
|
||||
controller->showToast((add
|
||||
? tr::lng_filters_toast_add
|
||||
: tr::lng_filters_toast_remove)(
|
||||
tr::now,
|
||||
lt_chat,
|
||||
Ui::Text::Bold(chat),
|
||||
lt_folder,
|
||||
Ui::Text::Wrapped(name, EntityType::Bold),
|
||||
Ui::Text::WithEntities));
|
||||
const auto isStatic = name.isStatic;
|
||||
const auto textContext = [=](not_null<QWidget*> widget) {
|
||||
return Core::MarkedTextContext{
|
||||
.session = &history->session(),
|
||||
.customEmojiRepaint = [=] { widget->update(); },
|
||||
.customEmojiLoopLimit = isStatic ? -1 : 0,
|
||||
};
|
||||
};
|
||||
controller->showToast({
|
||||
.text = (add
|
||||
? tr::lng_filters_toast_add
|
||||
: tr::lng_filters_toast_remove)(
|
||||
tr::now,
|
||||
lt_chat,
|
||||
Ui::Text::Bold(chat),
|
||||
lt_folder,
|
||||
Ui::Text::Wrapped(name.text, EntityType::Bold),
|
||||
Ui::Text::WithEntities),
|
||||
.textContext = textContext,
|
||||
});
|
||||
}
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
LOG(("API Error: failed to %1 a dialog to a folder. %2")
|
||||
@@ -279,7 +292,7 @@ void FillChooseFilterMenu(
|
||||
menu->st().menu,
|
||||
Ui::Menu::CreateAction(
|
||||
menu.get(), // todo filter emoji
|
||||
Ui::Text::FixAmpersandInAction(filter.title().text),
|
||||
Ui::Text::FixAmpersandInAction(filter.title().text.text),
|
||||
std::move(callback)),
|
||||
contains ? &st::mediaPlayerMenuCheck : nullptr,
|
||||
contains ? &st::mediaPlayerMenuCheck : nullptr);
|
||||
|
@@ -40,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/filter_icons.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/power_saving.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/fields/input_field.h"
|
||||
@@ -352,6 +353,8 @@ void EditFilterBox(
|
||||
rpl::variable<bool> hasLinks;
|
||||
rpl::variable<bool> chatlist;
|
||||
rpl::variable<bool> creating;
|
||||
rpl::variable<TextWithEntities> title;
|
||||
rpl::variable<bool> staticTitle;
|
||||
rpl::variable<int> colorIndex;
|
||||
};
|
||||
const auto owner = &window->session().data();
|
||||
@@ -359,6 +362,8 @@ void EditFilterBox(
|
||||
.rules = filter,
|
||||
.chatlist = filter.chatlist(),
|
||||
.creating = filter.title().empty(),
|
||||
.title = filter.titleText(),
|
||||
.staticTitle = filter.staticTitle(),
|
||||
});
|
||||
state->colorIndex = filter.colorIndex().value_or(kNoTag);
|
||||
state->links = owner->chatsFilters().chatlistLinks(filter.id()),
|
||||
@@ -404,7 +409,7 @@ void EditFilterBox(
|
||||
}, box->lifetime());
|
||||
|
||||
const auto content = box->verticalLayout();
|
||||
const auto current = filter.title();
|
||||
const auto current = state->title.current();
|
||||
const auto name = content->add(
|
||||
object_ptr<Ui::InputField>(
|
||||
box,
|
||||
@@ -422,6 +427,44 @@ void EditFilterBox(
|
||||
const auto nameEditing = box->lifetime().make_state<NameEditing>(
|
||||
NameEditing{ name });
|
||||
|
||||
const auto staticTitle = Ui::CreateChild<Ui::LinkButton>(
|
||||
name,
|
||||
QString());
|
||||
staticTitle->setClickedCallback([=] {
|
||||
state->staticTitle = !state->staticTitle.current();
|
||||
});
|
||||
state->staticTitle.value() | rpl::start_with_next([=](bool value) {
|
||||
staticTitle->setText(value
|
||||
? tr::lng_filters_enable_animations(tr::now)
|
||||
: tr::lng_filters_disable_animations(tr::now));
|
||||
const auto paused = [=] {
|
||||
using namespace Window;
|
||||
return window->isGifPausedAtLeastFor(GifPauseReason::Layer);
|
||||
};
|
||||
name->setCustomTextContext([=](Fn<void()> repaint) {
|
||||
return std::any(Core::MarkedTextContext{
|
||||
.session = session,
|
||||
.customEmojiRepaint = std::move(repaint),
|
||||
.customEmojiLoopLimit = value ? -1 : 0,
|
||||
});
|
||||
}, [paused] {
|
||||
return On(PowerSaving::kEmojiChat) || paused();
|
||||
}, [paused] {
|
||||
return On(PowerSaving::kChatSpoiler) || paused();
|
||||
});
|
||||
name->update();
|
||||
}, staticTitle->lifetime());
|
||||
|
||||
rpl::combine(
|
||||
staticTitle->widthValue(),
|
||||
name->widthValue()
|
||||
) | rpl::start_with_next([=](int inner, int outer) {
|
||||
staticTitle->moveToRight(
|
||||
st::windowFilterStaticTitlePosition.x(),
|
||||
st::windowFilterStaticTitlePosition.y(),
|
||||
outer);
|
||||
}, staticTitle->lifetime());
|
||||
|
||||
state->creating.value(
|
||||
) | rpl::filter(!_1) | rpl::start_with_next([=] {
|
||||
nameEditing->custom = true;
|
||||
@@ -432,7 +475,13 @@ void EditFilterBox(
|
||||
if (!nameEditing->settingDefault) {
|
||||
nameEditing->custom = true;
|
||||
}
|
||||
auto entered = name->getTextWithTags();
|
||||
state->title = TextWithEntities{
|
||||
std::move(entered.text),
|
||||
TextUtilities::ConvertTextTagsToEntities(entered.tags),
|
||||
};
|
||||
}, name->lifetime());
|
||||
|
||||
const auto updateDefaultTitle = [=](const Data::ChatFilter &filter) {
|
||||
if (nameEditing->custom) {
|
||||
return;
|
||||
@@ -444,13 +493,11 @@ void EditFilterBox(
|
||||
nameEditing->settingDefault = false;
|
||||
}
|
||||
};
|
||||
const auto nameWithEntities = [=](bool upper = false) {
|
||||
const auto entered = name->getTextWithTags();
|
||||
return TextWithEntities{
|
||||
(upper ? entered.text.toUpper() : entered.text),
|
||||
TextUtilities::ConvertTextTagsToEntities(entered.tags),
|
||||
};
|
||||
};
|
||||
|
||||
state->title.value(
|
||||
) | rpl::start_with_next([=](const TextWithEntities &value) {
|
||||
staticTitle->setVisible(!value.entities.isEmpty());
|
||||
}, staticTitle->lifetime());
|
||||
|
||||
const auto outer = box->getDelegate()->outerContainer();
|
||||
CreateIconSelector(
|
||||
@@ -595,10 +642,16 @@ void EditFilterBox(
|
||||
const auto palette = [](int i) {
|
||||
return Ui::EmptyUserpic::UserpicColor(i).color2;
|
||||
};
|
||||
name->changes() | rpl::start_with_next([=] {
|
||||
const auto upperTitle = [=] {
|
||||
auto value = state->title.current();
|
||||
value.text = value.text.toUpper();
|
||||
return value;
|
||||
};
|
||||
state->title.changes(
|
||||
) | rpl::start_with_next([=] {
|
||||
tag->context.color = palette(state->colorIndex.current())->c;
|
||||
tag->frame = Ui::ChatsFilterTag(
|
||||
nameWithEntities(true),
|
||||
upperTitle(),
|
||||
tag->context);
|
||||
preview->update();
|
||||
}, preview->lifetime());
|
||||
@@ -615,7 +668,7 @@ void EditFilterBox(
|
||||
if (progress == 1) {
|
||||
tag->context.color = color->c;
|
||||
tag->frame = Ui::ChatsFilterTag(
|
||||
nameWithEntities(true),
|
||||
upperTitle(),
|
||||
tag->context);
|
||||
if (i == kNoTag) {
|
||||
tag->alpha = 0.;
|
||||
@@ -641,7 +694,7 @@ void EditFilterBox(
|
||||
buttons[now]->setSelectedProgress(progress);
|
||||
tag->context.color = anim::color(c1, c2, progress);
|
||||
tag->frame = Ui::ChatsFilterTag(
|
||||
nameWithEntities(true),
|
||||
upperTitle(),
|
||||
tag->context);
|
||||
tag->alpha = anim::interpolateF(a1, a2, progress);
|
||||
preview->update();
|
||||
@@ -689,7 +742,9 @@ void EditFilterBox(
|
||||
}
|
||||
|
||||
const auto collect = [=]() -> std::optional<Data::ChatFilter> {
|
||||
const auto title = nameWithEntities();
|
||||
auto title = state->title.current();
|
||||
const auto staticTitle = !title.entities.isEmpty()
|
||||
&& state->staticTitle.current();
|
||||
const auto rules = data->current();
|
||||
if (title.empty()) {
|
||||
name->showError();
|
||||
@@ -708,7 +763,9 @@ void EditFilterBox(
|
||||
const auto colorIndex = (rawColorIndex >= kNoTag
|
||||
? std::nullopt
|
||||
: std::make_optional(rawColorIndex));
|
||||
return rules.withTitle(title).withColorIndex(colorIndex);
|
||||
return rules.withTitle(
|
||||
{ std::move(title), staticTitle }
|
||||
).withColorIndex(colorIndex);
|
||||
};
|
||||
|
||||
Ui::AddSubsectionTitle(
|
||||
|
@@ -151,7 +151,10 @@ ExceptionRow::ExceptionRow(
|
||||
if (!filters.empty()) {
|
||||
filters.append(u", "_q);
|
||||
}
|
||||
filters.append(filter.title());
|
||||
auto title = filter.title();
|
||||
filters.append(title.isStatic
|
||||
? Data::ForceCustomEmojiStatic(std::move(title.text))
|
||||
: std::move(title.text));
|
||||
}
|
||||
}
|
||||
if (!filters.empty()) {
|
||||
|
@@ -483,7 +483,7 @@ private:
|
||||
const not_null<Window::SessionController*> _window;
|
||||
InviteLinkData _data;
|
||||
|
||||
TextWithEntities _filterTitle;
|
||||
Data::ChatFilterTitle _filterTitle;
|
||||
base::flat_set<not_null<History*>> _filterChats;
|
||||
base::flat_map<not_null<PeerData*>, QString> _denied;
|
||||
rpl::variable<base::flat_set<not_null<PeerData*>>> _selected;
|
||||
@@ -536,10 +536,12 @@ void LinkController::addHeader(not_null<Ui::VerticalLayout*> container) {
|
||||
}, verticalLayout->lifetime());
|
||||
verticalLayout->add(std::move(icon.widget));
|
||||
|
||||
const auto isStatic = _filterTitle.isStatic;
|
||||
const auto makeContext = [=](Fn<void()> update) {
|
||||
return Core::MarkedTextContext{
|
||||
.session = &_window->session(),
|
||||
.customEmojiRepaint = update,
|
||||
.customEmojiLoopLimit = isStatic ? -1 : 0,
|
||||
};
|
||||
};
|
||||
verticalLayout->add(
|
||||
@@ -552,7 +554,7 @@ void LinkController::addHeader(not_null<Ui::VerticalLayout*> container) {
|
||||
: tr::lng_filters_link_share_about(
|
||||
lt_folder,
|
||||
rpl::single(Ui::Text::Wrapped(
|
||||
_filterTitle,
|
||||
_filterTitle.text,
|
||||
EntityType::Bold)),
|
||||
Ui::Text::WithEntities)),
|
||||
st::settingsFilterDividerLabel,
|
||||
|
Reference in New Issue
Block a user