2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Recent stickers limit

This commit is contained in:
RadRussianRus
2020-02-23 04:53:24 +03:00
parent 4c54f4ef35
commit 55f39e1cbf
9 changed files with 83 additions and 4 deletions

View File

@@ -16,5 +16,6 @@
// "show_phone_in_drawer": true,
// "scales": [],
// "confirm_before_calls": false,
// "no_taskbar_flash": false
// "no_taskbar_flash": false,
// "recent_stickers_limit": 20
}

View File

@@ -2394,4 +2394,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"ktg_settings_disable_sound_from_tray" = "Disable sound";
"ktg_settings_enable_sound_from_tray" = "Enable sound";
"ktg_settings_recent_stickers_limit#one" = "Recent stickers: show {count} sticker";
"ktg_settings_recent_stickers_limit#other" = "Recent stickers: show {count} stickers";
"ktg_settings_recent_stickers_limit_none" = "Recent stickers: hide all";
// Keys finished

View File

@@ -90,5 +90,12 @@
"ktg_call_button": "Позвонить",
"ktg_settings_adaptive_bubbles": "Адаптивные пузырьки сообщений",
"ktg_settings_disable_sound_from_tray": "Отключить звук",
"ktg_settings_enable_sound_from_tray": "Включить звук"
"ktg_settings_enable_sound_from_tray": "Включить звук",
"ktg_settings_recent_stickers_limit": {
"one": "Недавние стикеры: показывать {count} стикер",
"few": "Недавние стикеры: показывать {count} стикера",
"many": "Недавние стикеры: показывать {count} стикеров",
"other": "Недавние стикеры: показывать {count} стикеров"
},
"ktg_settings_recent_stickers_limit_none": "Недавние стикеры: скрыть все"
}

View File

@@ -43,7 +43,6 @@ namespace {
constexpr auto kInlineItemsMaxPerRow = 5;
constexpr auto kSearchRequestDelay = 400;
constexpr auto kRecentDisplayLimit = 20;
bool SetInMyList(MTPDstickerSet::Flags flags) {
return (flags & MTPDstickerSet::Flag::f_installed_date)
@@ -857,6 +856,13 @@ StickersListWidget::StickersListWidget(
refreshStickers();
}
}));
RecentStickersLimitChanges(
) | rpl::start_with_next([=] {
crl::on_main(this, [=] {
refreshStickers();
});
}, _lifetime);
}
Main::Session &StickersListWidget::session() const {
@@ -2307,7 +2313,7 @@ auto StickersListWidget::collectRecentStickers() -> std::vector<Sticker> {
_custom.reserve(cloudCount + recent.size() + customCount);
auto add = [&](not_null<DocumentData*> document, bool custom) {
if (result.size() >= kRecentDisplayLimit) {
if (result.size() >= RecentStickersLimit()) {
return;
}
const auto i = ranges::find(result, document, &Sticker::document);

View File

@@ -350,6 +350,8 @@ private:
rpl::event_stream<> _scrollUpdated;
rpl::event_stream<> _checkForHide;
rpl::lifetime _lifetime;
};
} // namespace ChatHelpers

View File

@@ -275,6 +275,14 @@ bool Manager::readCustomFile() {
if (settingsNoTaskbarFlashing != settings.constEnd() && (*settingsNoTaskbarFlashing).isBool()) {
cSetNoTaskbarFlashing((*settingsNoTaskbarFlashing).toBool());
}
const auto settingsRecentStickersLimitIt = settings.constFind(qsl("recent_stickers_limit"));
if (settingsRecentStickersLimitIt != settings.constEnd()) {
const auto settingsRecentStickersLimit = (*settingsRecentStickersLimitIt).toInt();
if (settingsRecentStickersLimit >= 0 || settingsRecentStickersLimit <= 200) {
SetRecentStickersLimit(settingsRecentStickersLimit);
}
}
return true;
}
@@ -315,6 +323,7 @@ void Manager::writeDefaultFile() {
settings.insert(qsl("disable_up_edit"), cDisableUpEdit());
settings.insert(qsl("confirm_before_calls"), cConfirmBeforeCall());
settings.insert(qsl("no_taskbar_flash"), cNoTaskbarFlashing());
settings.insert(qsl("recent_stickers_limit"), RecentStickersLimit());
auto settingsScales = QJsonArray();
settings.insert(qsl("scales"), settingsScales);
@@ -376,6 +385,7 @@ void Manager::writeCurrentSettings() {
settings.insert(qsl("disable_up_edit"), cDisableUpEdit());
settings.insert(qsl("confirm_before_calls"), cConfirmBeforeCall());
settings.insert(qsl("no_taskbar_flash"), cNoTaskbarFlashing());
settings.insert(qsl("recent_stickers_limit"), RecentStickersLimit());
auto settingsScales = QJsonArray();
auto currentScales = cInterfaceScales();

View File

@@ -303,3 +303,16 @@ bool AddCustomReplace(QString from, QString to) {
bool gConfirmBeforeCall = false;
bool gNoTaskbarFlashing = false;
rpl::variable<int> gRecentStickersLimit = 20;
void SetRecentStickersLimit(int limit) {
if (limit >= 0 || limit <= 200) {
gRecentStickersLimit = limit;
}
}
int RecentStickersLimit() {
return gRecentStickersLimit.current();
}
rpl::producer<int> RecentStickersLimitChanges() {
return gRecentStickersLimit.changes();
}

View File

@@ -242,3 +242,7 @@ DeclareRefSetting(CustomReplacementsMap, CustomReplaces);
bool AddCustomReplace(QString from, QString to);
DeclareSetting(bool, ConfirmBeforeCall);
DeclareSetting(bool, NoTaskbarFlashing);
void SetRecentStickersLimit(int limit);
[[nodiscard]] int RecentStickersLimit();
[[nodiscard]] rpl::producer<int> RecentStickersLimitChanges();

View File

@@ -69,6 +69,38 @@ void SetupKotatoChats(not_null<Ui::VerticalLayout*> container) {
updateStickerHeight);
updateStickerHeightLabel(StickerHeight());
const auto recentStickersLimitLabel = container->add(
object_ptr<Ui::LabelSimple>(
container,
st::settingsAudioVolumeLabel),
st::settingsAudioVolumeLabelPadding);
const auto recentStickersLimitSlider = container->add(
object_ptr<Ui::MediaSlider>(
container,
st::settingsAudioVolumeSlider),
st::settingsAudioVolumeSliderPadding);
const auto updateRecentStickersLimitLabel = [=](int value) {
if (value == 0) {
recentStickersLimitLabel->setText(
tr::ktg_settings_recent_stickers_limit_none(tr::now));
} else {
recentStickersLimitLabel->setText(
tr::ktg_settings_recent_stickers_limit(tr::now, lt_count_decimal, value));
}
};
const auto updateRecentStickersLimitHeight = [=](int value) {
updateRecentStickersLimitLabel(value);
SetRecentStickersLimit(value);
KotatoSettings::Write();
};
recentStickersLimitSlider->resize(st::settingsAudioVolumeSlider.seekSize);
recentStickersLimitSlider->setPseudoDiscrete(
201,
[](int val) { return val; },
RecentStickersLimit(),
updateRecentStickersLimitHeight);
updateRecentStickersLimitLabel(RecentStickersLimit());
AddButton(
container,
tr::ktg_settings_adaptive_bubbles(),