From 41cb37b091fa46e53d2a6a5f5006db6f19dc5117 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 12 Sep 2020 17:10:56 +0300 Subject: [PATCH] Added labels update in privacy box by timer. --- .../settings/settings_privacy_security.cpp | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 88470d09b7..adac9798f8 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_global_privacy.h" #include "settings/settings_common.h" #include "settings/settings_privacy_controllers.h" +#include "base/timer_rpl.h" #include "boxes/peer_list_box.h" #include "boxes/edit_privacy_box.h" #include "boxes/passcode_box.h" @@ -48,6 +49,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { namespace { +constexpr auto kUpdateTimeout = 60 * crl::time(1000); + using Privacy = ApiWrap::Privacy; rpl::producer<> PasscodeChanges() { @@ -106,7 +109,6 @@ rpl::producer PrivacyString( } rpl::producer BlockedPeersCount(not_null<::Main::Session*> session) { - session->api().reloadBlockedPeers(); return session->api().blockedPeersSlice( ) | rpl::map([=](const ApiWrap::BlockedPeersSlice &data) { return data.total; @@ -115,7 +117,8 @@ rpl::producer BlockedPeersCount(not_null<::Main::Session*> session) { void SetupPrivacy( not_null controller, - not_null container) { + not_null container, + rpl::producer<> updateTrigger) { AddSkip(container, st::settingsPrivacySkip); AddSubsectionTitle(container, tr::lng_settings_privacy_title()); @@ -126,12 +129,12 @@ void SetupPrivacy( ) | rpl::map([](int count, const QString &none) { return count ? QString::number(count) : none; }); - AddButtonWithLabel( + const auto blockedPeers = AddButtonWithLabel( container, tr::lng_settings_blocked_users(), std::move(count), - st::settingsButton - )->addClickHandler([=] { + st::settingsButton); + blockedPeers->addClickHandler([=] { const auto initBox = [=](not_null box) { box->addButton(tr::lng_close(), [=] { box->closeBox(); @@ -144,6 +147,11 @@ void SetupPrivacy( std::make_unique(controller), initBox)); }); + std::move( + updateTrigger + ) | rpl::start_with_next([=] { + session->api().reloadBlockedPeers(); + }, blockedPeers->lifetime()); using Key = Privacy::Key; const auto add = [&]( @@ -484,7 +492,8 @@ void SetupCloudPassword( void SetupSensitiveContent( not_null controller, - not_null container) { + not_null container, + rpl::producer<> updateTrigger) { using namespace rpl::mappers; const auto wrap = container->add( @@ -498,7 +507,11 @@ void SetupSensitiveContent( const auto session = &controller->session(); - session->api().sensitiveContent().reload(); + std::move( + updateTrigger + ) | rpl::start_with_next([=] { + session->api().sensitiveContent().reload(); + }, container->lifetime()); AddButton( inner, tr::lng_settings_sensitive_disable_filtering(), @@ -520,13 +533,18 @@ void SetupSensitiveContent( void SetupSelfDestruction( not_null controller, - not_null container) { + not_null container, + rpl::producer<> updateTrigger) { AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_destroy_title()); const auto session = &controller->session(); - session->api().selfDestruct().reload(); + std::move( + updateTrigger + ) | rpl::start_with_next([=] { + session->api().selfDestruct().reload(); + }, container->lifetime()); const auto label = [&] { return session->api().selfDestruct().days( ) | rpl::map( @@ -550,13 +568,17 @@ void SetupSelfDestruction( void SetupSessionsList( not_null controller, - not_null container) { + not_null container, + rpl::producer<> updateTrigger) { AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_sessions_title()); - auto &authorizations = controller->session().api().authorizations(); - authorizations.reload(); - auto count = authorizations.totalChanges( + std::move( + updateTrigger + ) | rpl::start_with_next([=] { + controller->session().api().authorizations().reload(); + }, container->lifetime()); + auto count = controller->session().api().authorizations().totalChanges( ) | rpl::map([](int count) { return count ? QString::number(count) : QString(); }); @@ -696,17 +718,23 @@ void PrivacySecurity::setupContent( not_null controller) { const auto content = Ui::CreateChild(this); - SetupPrivacy(controller, content); + auto updateOnTick = rpl::single( + ) | rpl::then(base::timer_each(kUpdateTimeout)); + const auto trigger = [=] { + return rpl::duplicate(updateOnTick); + }; + + SetupPrivacy(controller, content, trigger()); SetupArchiveAndMute(controller, content); - SetupSessionsList(controller, content); + SetupSessionsList(controller, content, trigger()); SetupLocalPasscode(controller, content); SetupCloudPassword(controller, content); #if !defined OS_MAC_STORE && !defined OS_WIN_STORE - SetupSensitiveContent(controller, content); + SetupSensitiveContent(controller, content, trigger()); #else // !OS_MAC_STORE && !OS_WIN_STORE AddDivider(content); #endif // !OS_MAC_STORE && !OS_WIN_STORE - SetupSelfDestruction(controller, content); + SetupSelfDestruction(controller, content, trigger()); Ui::ResizeFitChild(this, content); }