From 2fb2fa966101d287656a486b3a96f514665d94b8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 Mar 2020 16:51:23 +0400 Subject: [PATCH] Handle last suggestion being added. --- .../SourceFiles/boxes/manage_filters_box.cpp | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/boxes/manage_filters_box.cpp b/Telegram/SourceFiles/boxes/manage_filters_box.cpp index 4373e171d6..b0726e85e0 100644 --- a/Telegram/SourceFiles/boxes/manage_filters_box.cpp +++ b/Telegram/SourceFiles/boxes/manage_filters_box.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" #include "ui/text/text_utilities.h" +#include "ui/wrap/slide_wrap.h" #include "settings/settings_common.h" #include "lang/lang_keys.h" #include "apiwrap.h" @@ -297,7 +298,7 @@ void ManageFiltersPrepare::showBoxWithSuggested() { void ManageFiltersPrepare::CreateBox( not_null box, not_null window, - const std::vector &suggested) { + const std::vector &suggestions) { struct FilterRow { not_null button; Data::ChatFilter filter; @@ -349,45 +350,58 @@ void ManageFiltersPrepare::CreateBox( tr::lng_filters_create() | Ui::Text::ToUpper(), st::settingsUpdate); Settings::AddSkip(content); - if (suggested.empty()) { - content->add( + const auto emptyAbout = content->add( + object_ptr>( + content, object_ptr( content, tr::lng_filters_about(), st::boxDividerLabel), - st::settingsDividerLabelPadding); - } else { - Settings::AddDividerText(content, tr::lng_filters_about()); - Settings::AddSkip(content); - Settings::AddSubsectionTitle(content, tr::lng_filters_recommended()); + st::settingsDividerLabelPadding) + )->setDuration(0); + const auto nonEmptyAbout = content->add( + object_ptr>( + content, + object_ptr(content)) + )->setDuration(0); + const auto aboutRows = nonEmptyAbout->entity(); + Settings::AddDividerText(aboutRows, tr::lng_filters_about()); + Settings::AddSkip(aboutRows); + Settings::AddSubsectionTitle(aboutRows, tr::lng_filters_recommended()); - for (const auto &suggestion : suggested) { - const auto filter = suggestion.filter; - const auto already = [&] { - for (const auto &entry : list) { - if (entry.flags() == filter.flags() - && entry.always() == filter.always() - && entry.never() == filter.never()) { - return true; - } + const auto suggested = box->lifetime().make_state>(); + for (const auto &suggestion : suggestions) { + const auto filter = suggestion.filter; + const auto already = [&] { + for (const auto &entry : list) { + if (entry.flags() == filter.flags() + && entry.always() == filter.always() + && entry.never() == filter.never()) { + return true; } - return false; - }(); - if (already) { - continue; } - const auto button = content->add(object_ptr( - content, - filter, - suggestion.description)); - button->addRequests( - ) | rpl::start_with_next([=] { - addFilter(filter); - delete button; - }, button->lifetime()); + return false; + }(); + if (already) { + continue; } + *suggested = suggested->current() + 1; + const auto button = aboutRows->add(object_ptr( + aboutRows, + filter, + suggestion.description)); + button->addRequests( + ) | rpl::start_with_next([=] { + addFilter(filter); + *suggested = suggested->current() - 1; + delete button; + }, button->lifetime()); } + using namespace rpl::mappers; + emptyAbout->toggleOn(suggested->value() | rpl::map(_1 == 0)); + nonEmptyAbout->toggleOn(suggested->value() | rpl::map(_1 > 0)); + const auto prepareGoodIdsForNewFilters = [=] { const auto &list = session->data().chatsFilters().list();