diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 118f73698..c510c39cb 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -53,6 +53,15 @@ "ktg_settings_ffmpeg_multithread": "Multithread video decoding", "ktg_settings_ffmpeg_multithread_about": "When enabled, CPU and RAM consumption is higher, video decodes faster. When disabled, CPU and RAM consumption is lower, video decodes slower. The more CPU cores you have, the more RAM consumption you have when this option is enabled. You can set exact number of threads in the JSON configuration file.", "ktg_settings_adaptive_bubbles": "Adaptive bubbles", + "ktg_settings_recent_stickers_limit": { + "zero": "Recent stickers: show {count} stickers", + "one": "Recent stickers: show {count} sticker", + "two": "Recent stickers: show {count} stickers", + "few": "Recent stickers: show {count} stickers", + "many": "Recent stickers: show {count} stickers", + "other": "Recent stickers: show {count} stickers" + }, + "ktg_settings_recent_stickers_limit_none": "Recent stickers: hide all", "ktg_settings_filters": "Folders", "ktg_settings_messages": "Messages", "ktg_settings_chat_id": "Chat ID in profile", diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index e44b8aaef..e95f5d755 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "chat_helpers/stickers_list_widget.h" +#include "kotato/kotato_settings.h" #include "core/application.h" #include "data/data_document.h" #include "data/data_document_media.h" @@ -59,7 +60,6 @@ namespace ChatHelpers { namespace { constexpr auto kSearchRequestDelay = 400; -constexpr auto kRecentDisplayLimit = 20; constexpr auto kPreloadOfficialPages = 4; constexpr auto kOfficialLoadLimit = 40; constexpr auto kMinRepaintDelay = crl::time(33); @@ -271,6 +271,12 @@ StickersListWidget::StickersListWidget( ) | rpl::start_with_next([=] { refreshStickers(); }, lifetime()); + + ::Kotato::JsonSettings::Events( + "recent_stickers_limit" + ) | rpl::start_with_next([=] { + refreshStickers(); + }, lifetime()); } rpl::producer StickersListWidget::chosen() const { @@ -1822,6 +1828,10 @@ void StickersListWidget::removeRecentSticker(int section, int index) { } } } + Api::ToggleRecentSticker( + document, + Data::FileOriginStickerSet(Data::Stickers::RecentSetId, 0), + false); if (refresh) { refreshRecentStickers(); updateSelected(); @@ -2132,7 +2142,7 @@ auto StickersListWidget::collectRecentStickers() -> std::vector { _custom.reserve(cloudCount + recent.size() + customCount); auto add = [&](not_null document, bool custom) { - if (result.size() >= kRecentDisplayLimit) { + if (result.size() >= ::Kotato::JsonSettings::GetInt("recent_stickers_limit")) { return; } const auto i = ranges::find(result, document, &Sticker::document); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index aff2cf287..320b9cbd9 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -429,6 +429,8 @@ private: rpl::event_stream<> _scrollUpdated; rpl::event_stream _choosingUpdated; + rpl::lifetime _lifetime; + }; [[nodiscard]] object_ptr MakeConfirmRemoveSetBox( diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index 7645d3c7d..834d7e0b0 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -289,6 +289,10 @@ const std::map> DefinitionMap { .type = SettingType::IntSetting, .defaultValue = 0, .limitHandler = IntLimitMin(0) }}, + { "recent_stickers_limit", { + .type = SettingType::IntSetting, + .defaultValue = 20, + .limitHandler = IntLimit(0, 200, 20), }}, }; using OldOptionKey = QString; diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index 18bbd0507..8b58585c8 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -88,6 +88,38 @@ void SetupKotatoChats( Ui::AddSkip(container); Ui::AddSubsectionTitle(container, rktr("ktg_settings_chats")); + const auto recentStickersLimitLabel = container->add( + object_ptr( + container, + st::ktgSettingsSliderLabel), + st::groupCallDelayLabelMargin); + const auto recentStickersLimitSlider = container->add( + object_ptr( + container, + st::defaultContinuousSlider), + st::localStorageLimitMargin); + const auto updateRecentStickersLimitLabel = [=](int value) { + if (value == 0) { + recentStickersLimitLabel->setText( + ktr("ktg_settings_recent_stickers_limit_none")); + } else { + recentStickersLimitLabel->setText( + ktr("ktg_settings_recent_stickers_limit", value, { "count", QString::number(value) })); + } + }; + const auto updateRecentStickersLimitHeight = [=](int value) { + updateRecentStickersLimitLabel(value); + ::Kotato::JsonSettings::Set("recent_stickers_limit", value); + ::Kotato::JsonSettings::Write(); + }; + recentStickersLimitSlider->resize(st::defaultContinuousSlider.seekSize); + recentStickersLimitSlider->setPseudoDiscrete( + 201, + [](int val) { return val; }, + ::Kotato::JsonSettings::GetInt("recent_stickers_limit"), + updateRecentStickersLimitHeight); + updateRecentStickersLimitLabel(::Kotato::JsonSettings::GetInt("recent_stickers_limit")); + SettingsMenuJsonSwitch(ktg_settings_disable_up_edit, disable_up_edit); SettingsMenuJsonSwitch(ktg_settings_always_show_scheduled, always_show_scheduled);