Suggest enabling archive and mute in settings.

This commit is contained in:
John Preston 2020-07-06 18:08:28 +04:00
parent 152b49c65c
commit 5a1a8af222
5 changed files with 54 additions and 5 deletions

View file

@ -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";

View file

@ -19,7 +19,10 @@ GlobalPrivacy::GlobalPrivacy(not_null<ApiWrap*> api)
, _api(&api->instance()) {
}
void GlobalPrivacy::reload() {
void GlobalPrivacy::reload(Fn<void()> 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<bool>(
u"autoarchive_setting_available"_q,
false);
}, _session->lifetime());
}, _session->lifetime());
}
bool GlobalPrivacy::archiveAndMuteCurrent() const {

View file

@ -21,7 +21,7 @@ class GlobalPrivacy final {
public:
explicit GlobalPrivacy(not_null<ApiWrap*> api);
void reload();
void reload(Fn<void()> callback = nullptr);
void update(bool archiveAndMute);
[[nodiscard]] bool archiveAndMuteCurrent() const;
@ -38,6 +38,7 @@ private:
mtpRequestId _requestId = 0;
rpl::variable<bool> _archiveAndMute = false;
rpl::variable<bool> _showArchiveAndMute = false;
std::vector<Fn<void()>> _callbacks;
};

View file

@ -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<Ui::GenericBox*> box) {
box->setTitle(tr::lng_suggest_hide_new_title());
box->addRow(object_ptr<Ui::FlatLabel>(
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();
}

View file

@ -308,6 +308,7 @@ private:
void initSupportMode();
void refreshFiltersMenu();
void checkOpenedFilter();
void suggestArchiveAndMute();
int minimalThreeColumnWidth() const;
int countDialogsWidthFromRatio(int bodyWidth) const;