feat: implement recentStickersCount

This commit is contained in:
ZavaruKitsu 2023-06-09 15:04:25 +03:00
parent a5bd116b40
commit 89036a4c94
7 changed files with 60 additions and 2 deletions

View file

@ -3881,6 +3881,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"ayu_GhostModeShortcut" = "Enter with Ghost";
"ayu_SettingsWatermark" = "AyuGram developed and maintained by Radolyn Labs.";
"ayu_SettingsCustomizationHint" = "After making changes to the \"Customization\" section, you must restart the application.";
"ayu_SettingsRecentStickersCount" = "Recent stickers count";
"ayu_SettingsShowID" = "Show peer ID";
"ayu_SettingsShowID_Hide" = "Hide";
"ayu_SettingsShowMessageSeconds" = "Show message seconds";

View file

@ -128,6 +128,10 @@ namespace AyuSettings {
editedMarkReactive = editedMark;
}
void AyuGramSettings::set_recentStickersCount(int val) {
recentStickersCount = val;
}
void AyuGramSettings::set_showGhostToggleInDrawer(bool val) {
showGhostToggleInDrawer = val;
}

View file

@ -33,6 +33,7 @@ namespace AyuSettings {
// ~ Customization
deletedMark = "🧹";
editedMark = tr::lng_edited(tr::now);
recentStickersCount = 20;
showGhostToggleInDrawer = true;
/*
@ -69,6 +70,8 @@ namespace AyuSettings {
QS_FIELD(QString, editedMark)
QS_FIELD(int, recentStickersCount)
QS_FIELD(bool, showGhostToggleInDrawer)
QS_FIELD(int, showPeerId)
@ -92,6 +95,7 @@ namespace AyuSettings {
void set_deletedMark(QString val);
void set_editedMark(QString val);
void set_recentStickersCount(int val);
void set_showGhostToggleInDrawer(bool val);
void set_showPeerId(int val);
void set_showMessageSeconds(bool val);

View file

@ -11,7 +11,6 @@
#include "ui/widgets/buttons.h"
#include "ui/widgets/checkbox.h"
#include "boxes/connection_box.h"
#include "ui/boxes/confirm_box.h"
#include "platform/platform_specific.h"
#include "window/window_session_controller.h"
#include "lang/lang_instance.h"
@ -22,6 +21,7 @@
#include "styles/style_settings.h"
#include "apiwrap.h"
#include "api/api_blocked_peers.h"
#include "ui/widgets/continuous_sliders.h"
namespace Settings {
@ -207,6 +207,8 @@ namespace Settings {
Ui::show(std::move(box));
});
SetupRecentStickersLimitSlider(container);
SetupShowPeerId(container, controller);
AddButton(
@ -274,6 +276,46 @@ namespace Settings {
});
}
void Ayu::SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout *> container) {
auto settings = &AyuSettings::getInstance();
container->add(
CreateButton(
container,
tr::ayu_SettingsRecentStickersCount(),
st::settingsButtonNoIcon)
);
auto recentStickersLimitSlider = MakeSliderWithLabel(
container,
st::settingsScale,
st::settingsScaleLabel,
st::normalFont->spacew * 2,
st::settingsScaleLabel.style.font->width("300%"));
container->add(
std::move(recentStickersLimitSlider.widget),
st::settingsScalePadding);
const auto slider = recentStickersLimitSlider.slider;
const auto label = recentStickersLimitSlider.label;
const auto updateLabel = [=](int amount) {
label->setText(QString::number(amount));
};
updateLabel(settings->recentStickersCount);
slider->setPseudoDiscrete(
40 + 1, // thx tg
[=](int amount) { return amount; },
settings->recentStickersCount,
[=](int amount) { updateLabel(amount); },
[=](int amount) {
updateLabel(amount);
settings->set_recentStickersCount(amount);
AyuSettings::save();
});
}
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller) {
AddSkip(container);
SetupGhostEssentials(container);

View file

@ -22,7 +22,9 @@ namespace Settings {
void SetupSpyEssentials(not_null<Ui::VerticalLayout *> container);
void SetupQoLToggles(not_null<Ui::VerticalLayout *> container);
void SetupCustomization(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller);
void SetupShowPeerId(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller);
void SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout *> container);
void SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> null);
void setupContent(not_null<Window::SessionController *> controller);

View file

@ -54,6 +54,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication>
#include "ayu/ayu_settings.h"
namespace ChatHelpers {
namespace {
@ -2089,8 +2091,10 @@ auto StickersListWidget::collectRecentStickers() -> std::vector<Sticker> {
result.reserve(cloudCount + recent.size() + customCount);
_custom.reserve(cloudCount + recent.size() + customCount);
auto settings = &AyuSettings::getInstance();
auto add = [&](not_null<DocumentData*> document, bool custom) {
if (result.size() >= kRecentDisplayLimit) {
if (result.size() >= settings->recentStickersCount) {
return;
}
const auto i = ranges::find(result, document, &Sticker::document);

View file

@ -1,6 +1,7 @@
{
"SettingsWatermark": "AyuGram developed and maintained by Radolyn Labs.",
"SettingsCustomizationHint": "After making changes to the \"Customization\" section, you must restart the application.",
"SettingsRecentStickersCount": "Recent stickers count",
"SettingsShowID": "Show peer ID",
"SettingsShowID_Hide": "Hide",
"SettingsShowMessageSeconds": "Show message seconds",