From 2ef9724fa2fca1e71ebc58c673628f7bbd0de1e4 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Tue, 1 Aug 2023 15:47:39 +0000 Subject: [PATCH] feat: add hide "All chats" folder (thx 64Gram) --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/ayu/ayu_settings.cpp | 5 +++++ Telegram/SourceFiles/ayu/ayu_settings.h | 5 +++++ .../ayu/ui/settings/settings_ayu.cpp | 16 ++++++++++++++ .../SourceFiles/data/data_chat_filters.cpp | 21 +++++++++++++++++-- .../window/window_filters_menu.cpp | 14 +++++++++++-- 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ff41a5ef92..30a1a05fc0 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3980,6 +3980,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_CustomizationHeader" = "Customization"; "ayu_DeletedMarkText" = "Deleted mark"; "ayu_EditedMarkText" = "Edited mark"; +"ayu_HideAllChats" = "Hide \"All chats\" folder"; "ayu_ShowGhostToggleInDrawer" = "Show ghost mode toggle"; "ayu_ShowKllButtonInDrawer" = "Show kill app button"; "ayu_SettingsShowID" = "Show peer ID"; diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index c6251e2172..5e1878c9d2 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -248,6 +248,11 @@ namespace AyuSettings { showMessageSeconds = val; } + + void AyuGramSettings::set_hideAllChatsFolder(bool val) + { + hideAllChatsFolder = val; + } void AyuGramSettings::set_stickerConfirmation(bool val) { diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 39e9d7d936..403e734e03 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -51,6 +51,7 @@ namespace AyuSettings */ showPeerId = 2; + hideAllChatsFolder = false; showMessageSeconds = false; // ~ Confirmations @@ -76,6 +77,7 @@ namespace AyuSettings int recentStickersCount; bool showGhostToggleInDrawer; int showPeerId; + bool hideAllChatsFolder; bool showMessageSeconds; bool stickerConfirmation; bool gifConfirmation; @@ -120,6 +122,8 @@ namespace AyuSettings void set_showMessageSeconds(bool val); + void set_hideAllChatsFolder(bool val); + void set_stickerConfirmation(bool val); void set_gifConfirmation(bool val); @@ -147,6 +151,7 @@ namespace AyuSettings showGhostToggleInDrawer, showPeerId, showMessageSeconds, + hideAllChatsFolder, stickerConfirmation, gifConfirmation, voiceConfirmation diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 5284a08ec3..20dbb68cf1 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -296,6 +296,22 @@ namespace Settings SetupShowPeerId(container, controller); + AddButton( + container, + tr::ayu_HideAllChats(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->hideAllChatsFolder) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->hideAllChatsFolder); + }) | start_with_next([=](bool enabled) + { + settings->set_hideAllChatsFolder(enabled); + AyuSettings::save(); + }, container->lifetime()); + AddButton( container, tr::ayu_ShowGhostToggleInDrawer(), diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index 26c6b6287e..29c070d369 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -25,6 +25,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_app_config.h" #include "apiwrap.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace Data { namespace { @@ -389,10 +393,16 @@ void ChatFilters::load(bool force) { } void ChatFilters::received(const QVector &list) { + // AyuGram hideAllChatsFolder + const auto settings = &AyuSettings::getInstance(); + auto position = 0; auto changed = false; for (const auto &filter : list) { auto parsed = ChatFilter::FromTL(filter, _owner); + if (settings->hideAllChatsFolder && parsed.id() == 0 && list.size() > 1) { + continue; + } const auto b = begin(_list) + position, e = end(_list); const auto i = ranges::find(b, e, parsed.id(), &ChatFilter::id); if (i == e) { @@ -413,7 +423,7 @@ void ChatFilters::received(const QVector &list) { applyRemove(position); changed = true; } - if (!ranges::contains(begin(_list), end(_list), 0, &ChatFilter::id)) { + if (!settings->hideAllChatsFolder && !ranges::contains(begin(_list), end(_list), 0, &ChatFilter::id)) { _list.insert(begin(_list), ChatFilter()); } if (changed || !_loaded || _reloading) { @@ -424,9 +434,16 @@ void ChatFilters::received(const QVector &list) { } void ChatFilters::apply(const MTPUpdate &update) { + // AyuGram hideAllChatsFolder + const auto settings = &AyuSettings::getInstance(); + update.match([&](const MTPDupdateDialogFilter &data) { if (const auto filter = data.vfilter()) { - set(ChatFilter::FromTL(*filter, _owner)); + auto parsed = ChatFilter::FromTL(*filter, _owner); + if (settings->hideAllChatsFolder && parsed.id() == 0) { + return; + } + set(parsed); } else { remove(data.vid().v); } diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index c6c34a0d94..8c553824b1 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -37,6 +37,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_layers.h" // attentionBoxButton #include "styles/style_menu_icons.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace Window { namespace { @@ -197,6 +201,9 @@ void FiltersMenu::scrollToButton(not_null widget) { } void FiltersMenu::refresh() { + // AyuGram hideAllChatsFolder + const auto settings = &AyuSettings::getInstance(); + const auto filters = &_session->session().data().chatsFilters(); if (!filters->has() || _ignoreRefresh) { return; @@ -212,7 +219,7 @@ void FiltersMenu::refresh() { const auto maxLimit = (reorderAll ? 1 : 0) + Data::PremiumLimits(&_session->session()).dialogFiltersCurrent(); const auto premiumFrom = (reorderAll ? 0 : 1) + maxLimit; - if (!reorderAll) { + if (!reorderAll && !settings->hideAllChatsFolder) { _reorder->addPinnedInterval(0, 1); } _reorder->addPinnedInterval( @@ -542,9 +549,12 @@ void FiltersMenu::applyReorder( return; } + // AyuGram hideAllChatsFolder + const auto settings = &AyuSettings::getInstance(); + const auto filters = &_session->session().data().chatsFilters(); const auto &list = filters->list(); - if (!premium()) { + if (!settings->hideAllChatsFolder && !premium()) { if (list[0].id() != FilterId()) { filters->moveAllToFront(); }