diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 950debc82..351fe5256 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -443,7 +443,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_auto_night_disable" = "Disable"; "lng_suggest_hide_new_title" = "Hide new chats?"; -"lng_suggest_hide_new_about" = "You are receiving lots of new chats from users who are not in your ContactList. Do you want to have such chats **automatically muted** and **archived**?"; +"lng_suggest_hide_new_about" = "You are receiving lots of new chats from users who are not in your Contact List.\n\nDo you want to have such chats **automatically muted** and **archived**?"; "lng_suggest_hide_new_to_settings" = "Go to Settings"; "lng_settings_spellchecker" = "Spell checker"; diff --git a/Telegram/SourceFiles/api/api_global_privacy.cpp b/Telegram/SourceFiles/api/api_global_privacy.cpp index 88fee6de5..5d07ab79a 100644 --- a/Telegram/SourceFiles/api/api_global_privacy.cpp +++ b/Telegram/SourceFiles/api/api_global_privacy.cpp @@ -19,7 +19,10 @@ GlobalPrivacy::GlobalPrivacy(not_null api) , _api(&api->instance()) { } -void GlobalPrivacy::reload() { +void GlobalPrivacy::reload(Fn callback) { + if (callback) { + _callbacks.push_back(std::move(callback)); + } if (_requestId) { return; } @@ -27,8 +30,14 @@ void GlobalPrivacy::reload() { )).done([=](const MTPGlobalPrivacySettings &result) { _requestId = 0; apply(result); + for (const auto &callback : base::take(_callbacks)) { + callback(); + } }).fail([=](const RPCError &error) { _requestId = 0; + for (const auto &callback : base::take(_callbacks)) { + callback(); + } }).send(); _session->account().appConfig().value( @@ -36,7 +45,7 @@ void GlobalPrivacy::reload() { _showArchiveAndMute = _session->account().appConfig().get( u"autoarchive_setting_available"_q, false); - }, _session->lifetime()); + }, _session->lifetime()); } bool GlobalPrivacy::archiveAndMuteCurrent() const { diff --git a/Telegram/SourceFiles/api/api_global_privacy.h b/Telegram/SourceFiles/api/api_global_privacy.h index e35f76cb6..a1a693499 100644 --- a/Telegram/SourceFiles/api/api_global_privacy.h +++ b/Telegram/SourceFiles/api/api_global_privacy.h @@ -21,7 +21,7 @@ class GlobalPrivacy final { public: explicit GlobalPrivacy(not_null api); - void reload(); + void reload(Fn callback = nullptr); void update(bool archiveAndMute); [[nodiscard]] bool archiveAndMuteCurrent() const; @@ -38,6 +38,7 @@ private: mtpRequestId _requestId = 0; rpl::variable _archiveAndMute = false; rpl::variable _showArchiveAndMute = false; + std::vector> _callbacks; }; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index b961d2a9d..2f40803c9 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -31,6 +31,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/core_settings.h" #include "base/unixtime.h" +#include "ui/layers/generic_box.h" +#include "ui/text/text_utilities.h" +#include "ui/delayed_activation.h" #include "boxes/calendar_box.h" #include "boxes/sticker_set_box.h" // requestAttachedStickerSets. #include "boxes/confirm_box.h" // requestAttachedStickerSets. @@ -42,11 +45,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session_settings.h" #include "apiwrap.h" #include "api/api_chat_invite.h" +#include "api/api_global_privacy.h" #include "support/support_helper.h" #include "facades.h" #include "styles/style_window.h" #include "styles/style_dialogs.h" -#include "ui/delayed_activation.h" +#include "styles/style_layers.h" // st::boxLabel namespace Window { namespace { @@ -167,9 +171,43 @@ SessionController::SessionController( }); }, lifetime()); + session->api().globalPrivacy().suggestArchiveAndMute( + ) | rpl::take(1) | rpl::start_with_next([=] { + session->api().globalPrivacy().reload(crl::guard(this, [=] { + if (!session->api().globalPrivacy().archiveAndMuteCurrent()) { + suggestArchiveAndMute(); + } + })); + }, _lifetime); + session->addWindow(this); } +void SessionController::suggestArchiveAndMute() { + const auto weak = base::make_weak(this); + _window->show(Box([=](not_null box) { + box->setTitle(tr::lng_suggest_hide_new_title()); + box->addRow(object_ptr( + box, + tr::lng_suggest_hide_new_about(Ui::Text::RichLangValue), + st::boxLabel)); + box->addButton(tr::lng_suggest_hide_new_to_settings(), [=] { + showSettings(Settings::Type::PrivacySecurity); + }); + box->setCloseByOutsideClick(false); + box->boxClosing( + ) | rpl::start_with_next([=] { + crl::on_main(weak, [=] { + auto &privacy = session().api().globalPrivacy(); + privacy.dismissArchiveAndMuteSuggestion(); + }); + }, box->lifetime()); + box->addButton(tr::lng_cancel(), [=] { + box->closeBox(); + }); + })); +} + not_null<::MainWindow*> SessionController::widget() const { return _window->widget(); } diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 63c4d47ab..48718bd33 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -308,6 +308,7 @@ private: void initSupportMode(); void refreshFiltersMenu(); void checkOpenedFilter(); + void suggestArchiveAndMute(); int minimalThreeColumnWidth() const; int countDialogsWidthFromRatio(int bodyWidth) const;