mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add archive and mute settings editing.
This commit is contained in:
parent
060fe6a928
commit
3aea9cb3ca
10 changed files with 243 additions and 6 deletions
|
@ -195,6 +195,8 @@ PRIVATE
|
||||||
api/api_common.h
|
api/api_common.h
|
||||||
api/api_editing.cpp
|
api/api_editing.cpp
|
||||||
api/api_editing.h
|
api/api_editing.h
|
||||||
|
api/api_global_privacy.cpp
|
||||||
|
api/api_global_privacy.h
|
||||||
api/api_hash.cpp
|
api/api_hash.cpp
|
||||||
api/api_hash.h
|
api/api_hash.h
|
||||||
api/api_media.cpp
|
api/api_media.cpp
|
||||||
|
|
|
@ -424,6 +424,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_settings_passcode_title" = "Local passcode";
|
"lng_settings_passcode_title" = "Local passcode";
|
||||||
"lng_settings_password_title" = "Two-step verification";
|
"lng_settings_password_title" = "Two-step verification";
|
||||||
"lng_settings_sessions_title" = "Active sessions";
|
"lng_settings_sessions_title" = "Active sessions";
|
||||||
|
"lng_settings_new_unknown" = "New chats from unknown users";
|
||||||
|
"lng_settings_auto_archive" = "Archive and Mute";
|
||||||
|
"lng_settings_auto_archive_about" = "Automatically archive and mute new chats, groups and channels from non-contacts.";
|
||||||
"lng_settings_destroy_title" = "Delete my account";
|
"lng_settings_destroy_title" = "Delete my account";
|
||||||
"lng_settings_network_proxy" = "Network and proxy";
|
"lng_settings_network_proxy" = "Network and proxy";
|
||||||
"lng_settings_version_info" = "Version and updates";
|
"lng_settings_version_info" = "Version and updates";
|
||||||
|
|
94
Telegram/SourceFiles/api/api_global_privacy.cpp
Normal file
94
Telegram/SourceFiles/api/api_global_privacy.cpp
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#include "api/api_global_privacy.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "main/main_account.h"
|
||||||
|
#include "main/main_app_config.h"
|
||||||
|
|
||||||
|
namespace Api {
|
||||||
|
|
||||||
|
GlobalPrivacy::GlobalPrivacy(not_null<ApiWrap*> api)
|
||||||
|
: _session(&api->session())
|
||||||
|
, _api(&api->instance()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalPrivacy::reload() {
|
||||||
|
if (_requestId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_requestId = _api.request(MTPaccount_GetGlobalPrivacySettings(
|
||||||
|
)).done([=](const MTPGlobalPrivacySettings &result) {
|
||||||
|
_requestId = 0;
|
||||||
|
apply(result);
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
_requestId = 0;
|
||||||
|
}).send();
|
||||||
|
|
||||||
|
_session->account().appConfig().value(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_showArchiveAndMute = _session->account().appConfig().get<bool>(
|
||||||
|
u"autoarchive_setting_available"_q,
|
||||||
|
false);
|
||||||
|
}, _session->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GlobalPrivacy::archiveAndMuteCurrent() const {
|
||||||
|
return _archiveAndMute.current();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> GlobalPrivacy::archiveAndMute() const {
|
||||||
|
return _archiveAndMute.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> GlobalPrivacy::showArchiveAndMute() const {
|
||||||
|
using namespace rpl::mappers;
|
||||||
|
|
||||||
|
return rpl::combine(
|
||||||
|
archiveAndMute(),
|
||||||
|
_showArchiveAndMute.value(),
|
||||||
|
_1 || _2);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> GlobalPrivacy::suggestArchiveAndMute() const {
|
||||||
|
return _session->account().appConfig().suggestionRequested(
|
||||||
|
u"AUTOARCHIVE_POPULAR"_q);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalPrivacy::dismissArchiveAndMuteSuggestion() {
|
||||||
|
_session->account().appConfig().dismissSuggestion(
|
||||||
|
u"AUTOARCHIVE_POPULAR"_q);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalPrivacy::update(bool archiveAndMute) {
|
||||||
|
using Flag = MTPDglobalPrivacySettings::Flag;
|
||||||
|
|
||||||
|
_api.request(_requestId).cancel();
|
||||||
|
_requestId = _api.request(MTPaccount_SetGlobalPrivacySettings(
|
||||||
|
MTP_globalPrivacySettings(
|
||||||
|
MTP_flags(Flag::f_archive_and_mute_new_noncontact_peers),
|
||||||
|
MTP_bool(archiveAndMute))
|
||||||
|
)).done([=](const MTPGlobalPrivacySettings &result) {
|
||||||
|
_requestId = 0;
|
||||||
|
apply(result);
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
_requestId = 0;
|
||||||
|
}).send();
|
||||||
|
_archiveAndMute = archiveAndMute;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalPrivacy::apply(const MTPGlobalPrivacySettings &data) {
|
||||||
|
data.match([&](const MTPDglobalPrivacySettings &data) {
|
||||||
|
_archiveAndMute = data.varchive_and_mute_new_noncontact_peers()
|
||||||
|
? mtpIsTrue(*data.varchive_and_mute_new_noncontact_peers())
|
||||||
|
: false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Api
|
44
Telegram/SourceFiles/api/api_global_privacy.h
Normal file
44
Telegram/SourceFiles/api/api_global_privacy.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mtproto/sender.h"
|
||||||
|
|
||||||
|
class ApiWrap;
|
||||||
|
|
||||||
|
namespace Main {
|
||||||
|
class Session;
|
||||||
|
} // namespace Main
|
||||||
|
|
||||||
|
namespace Api {
|
||||||
|
|
||||||
|
class GlobalPrivacy final {
|
||||||
|
public:
|
||||||
|
explicit GlobalPrivacy(not_null<ApiWrap*> api);
|
||||||
|
|
||||||
|
void reload();
|
||||||
|
void update(bool archiveAndMute);
|
||||||
|
|
||||||
|
[[nodiscard]] bool archiveAndMuteCurrent() const;
|
||||||
|
[[nodiscard]] rpl::producer<bool> archiveAndMute() const;
|
||||||
|
[[nodiscard]] rpl::producer<bool> showArchiveAndMute() const;
|
||||||
|
[[nodiscard]] rpl::producer<> suggestArchiveAndMute() const;
|
||||||
|
void dismissArchiveAndMuteSuggestion();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void apply(const MTPGlobalPrivacySettings &data);
|
||||||
|
|
||||||
|
const not_null<Main::Session*> _session;
|
||||||
|
MTP::Sender _api;
|
||||||
|
mtpRequestId _requestId = 0;
|
||||||
|
rpl::variable<bool> _archiveAndMute = false;
|
||||||
|
rpl::variable<bool> _showArchiveAndMute = false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Api
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_text_entities.h"
|
#include "api/api_text_entities.h"
|
||||||
#include "api/api_self_destruct.h"
|
#include "api/api_self_destruct.h"
|
||||||
#include "api/api_sensitive_content.h"
|
#include "api/api_sensitive_content.h"
|
||||||
|
#include "api/api_global_privacy.h"
|
||||||
#include "api/api_updates.h"
|
#include "api/api_updates.h"
|
||||||
#include "data/stickers/data_stickers.h"
|
#include "data/stickers/data_stickers.h"
|
||||||
#include "data/data_drafts.h"
|
#include "data/data_drafts.h"
|
||||||
|
@ -186,7 +187,8 @@ ApiWrap::ApiWrap(not_null<Main::Session*> session)
|
||||||
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
||||||
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
|
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
|
||||||
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
|
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
|
||||||
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this)) {
|
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this))
|
||||||
|
, _globalPrivacy(std::make_unique<Api::GlobalPrivacy>(this)) {
|
||||||
crl::on_main(session, [=] {
|
crl::on_main(session, [=] {
|
||||||
// You can't use _session->lifetime() in the constructor,
|
// You can't use _session->lifetime() in the constructor,
|
||||||
// only queued, because it is not constructed yet.
|
// only queued, because it is not constructed yet.
|
||||||
|
@ -5241,6 +5243,10 @@ Api::SensitiveContent &ApiWrap::sensitiveContent() {
|
||||||
return *_sensitiveContent;
|
return *_sensitiveContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Api::GlobalPrivacy &ApiWrap::globalPrivacy() {
|
||||||
|
return *_globalPrivacy;
|
||||||
|
}
|
||||||
|
|
||||||
void ApiWrap::createPoll(
|
void ApiWrap::createPoll(
|
||||||
const PollData &data,
|
const PollData &data,
|
||||||
const SendAction &action,
|
const SendAction &action,
|
||||||
|
|
|
@ -50,6 +50,12 @@ struct CloudPasswordState;
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
|
||||||
|
class Updates;
|
||||||
|
class SelfDestruct;
|
||||||
|
class SensitiveContent;
|
||||||
|
class GlobalPrivacy;
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
inline QString ToString(const QString &value) {
|
inline QString ToString(const QString &value) {
|
||||||
|
@ -66,8 +72,6 @@ inline QString ToString(uint64 value) {
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|
||||||
class Updates;
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename ...Types,
|
typename ...Types,
|
||||||
typename = std::enable_if_t<(sizeof...(Types) > 0)>>
|
typename = std::enable_if_t<(sizeof...(Types) > 0)>>
|
||||||
|
@ -86,9 +90,6 @@ QString RequestKey(Types &&...values) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelfDestruct;
|
|
||||||
class SensitiveContent;
|
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
||||||
class ApiWrap : public MTP::Sender, private base::Subscriber {
|
class ApiWrap : public MTP::Sender, private base::Subscriber {
|
||||||
|
@ -460,6 +461,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] Api::SelfDestruct &selfDestruct();
|
[[nodiscard]] Api::SelfDestruct &selfDestruct();
|
||||||
[[nodiscard]] Api::SensitiveContent &sensitiveContent();
|
[[nodiscard]] Api::SensitiveContent &sensitiveContent();
|
||||||
|
[[nodiscard]] Api::GlobalPrivacy &globalPrivacy();
|
||||||
|
|
||||||
void createPoll(
|
void createPoll(
|
||||||
const PollData &data,
|
const PollData &data,
|
||||||
|
@ -821,6 +823,7 @@ private:
|
||||||
|
|
||||||
const std::unique_ptr<Api::SelfDestruct> _selfDestruct;
|
const std::unique_ptr<Api::SelfDestruct> _selfDestruct;
|
||||||
const std::unique_ptr<Api::SensitiveContent> _sensitiveContent;
|
const std::unique_ptr<Api::SensitiveContent> _sensitiveContent;
|
||||||
|
const std::unique_ptr<Api::GlobalPrivacy> _globalPrivacy;
|
||||||
|
|
||||||
base::flat_map<FullMsgId, mtpRequestId> _pollVotesRequestIds;
|
base::flat_map<FullMsgId, mtpRequestId> _pollVotesRequestIds;
|
||||||
base::flat_map<FullMsgId, mtpRequestId> _pollCloseRequestIds;
|
base::flat_map<FullMsgId, mtpRequestId> _pollCloseRequestIds;
|
||||||
|
|
|
@ -67,6 +67,10 @@ rpl::producer<> AppConfig::refreshed() const {
|
||||||
return _refreshed.events();
|
return _refreshed.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> AppConfig::value() const {
|
||||||
|
return _refreshed.events_starting_with({});
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Extractor>
|
template <typename Extractor>
|
||||||
auto AppConfig::getValue(const QString &key, Extractor &&extractor) const {
|
auto AppConfig::getValue(const QString &key, Extractor &&extractor) const {
|
||||||
const auto i = _data.find(key);
|
const auto i = _data.find(key);
|
||||||
|
@ -126,4 +130,29 @@ std::vector<QString> AppConfig::getStringArray(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AppConfig::suggestionCurrent(const QString &key) const {
|
||||||
|
return !_dismissedSuggestions.contains(key)
|
||||||
|
&& ranges::contains(
|
||||||
|
get<std::vector<QString>>(
|
||||||
|
u"pending_suggestions"_q,
|
||||||
|
std::vector<QString>()),
|
||||||
|
key);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> AppConfig::suggestionRequested(const QString &key) const {
|
||||||
|
return value(
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
return suggestionCurrent(key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppConfig::dismissSuggestion(const QString &key) {
|
||||||
|
if (!_dismissedSuggestions.emplace(key).second) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_api->request(MTPhelp_DismissSuggestion(
|
||||||
|
MTP_string(key)
|
||||||
|
)).send();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
|
@ -31,6 +31,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<> refreshed() const;
|
[[nodiscard]] rpl::producer<> refreshed() const;
|
||||||
|
[[nodiscard]] rpl::producer<> value() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool suggestionCurrent(const QString &key) const;
|
||||||
|
[[nodiscard]] rpl::producer<> suggestionRequested(
|
||||||
|
const QString &key) const;
|
||||||
|
void dismissSuggestion(const QString &key);
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
|
@ -60,6 +66,7 @@ private:
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
base::flat_map<QString, MTPJSONValue> _data;
|
base::flat_map<QString, MTPJSONValue> _data;
|
||||||
rpl::event_stream<> _refreshed;
|
rpl::event_stream<> _refreshed;
|
||||||
|
base::flat_set<QString> _dismissedSuggestions;
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_account.h"
|
#include "main/main_account.h"
|
||||||
#include "main/main_app_config.h"
|
#include "main/main_app_config.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_sensitive_content.h"
|
||||||
|
#include "api/api_global_privacy.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
|
@ -373,6 +375,8 @@ void Main::setupContent(not_null<Window::SessionController*> controller) {
|
||||||
// If we load this in advance it won't jump when we open its' section.
|
// If we load this in advance it won't jump when we open its' section.
|
||||||
controller->session().api().reloadPasswordState();
|
controller->session().api().reloadPasswordState();
|
||||||
controller->session().api().reloadContactSignupSilent();
|
controller->session().api().reloadContactSignupSilent();
|
||||||
|
controller->session().api().sensitiveContent().reload();
|
||||||
|
controller->session().api().globalPrivacy().reload();
|
||||||
controller->session().data().cloudThemes().refresh();
|
controller->session().data().cloudThemes().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "api/api_self_destruct.h"
|
#include "api/api_self_destruct.h"
|
||||||
#include "api/api_sensitive_content.h"
|
#include "api/api_sensitive_content.h"
|
||||||
|
#include "api/api_global_privacy.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
#include "settings/settings_privacy_controllers.h"
|
#include "settings/settings_privacy_controllers.h"
|
||||||
#include "boxes/peer_list_box.h"
|
#include "boxes/peer_list_box.h"
|
||||||
|
@ -186,6 +187,49 @@ void SetupPrivacy(
|
||||||
AddDividerText(container, tr::lng_settings_group_privacy_about());
|
AddDividerText(container, tr::lng_settings_group_privacy_about());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetupArchiveAndMute(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<Ui::VerticalLayout*> container) {
|
||||||
|
using namespace rpl::mappers;
|
||||||
|
|
||||||
|
const auto wrap = container->add(
|
||||||
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
container,
|
||||||
|
object_ptr<Ui::VerticalLayout>(container)));
|
||||||
|
const auto inner = wrap->entity();
|
||||||
|
|
||||||
|
AddSkip(inner);
|
||||||
|
AddSubsectionTitle(inner, tr::lng_settings_new_unknown());
|
||||||
|
|
||||||
|
const auto session = &controller->session();
|
||||||
|
|
||||||
|
const auto privacy = &session->api().globalPrivacy();
|
||||||
|
privacy->reload();
|
||||||
|
AddButton(
|
||||||
|
inner,
|
||||||
|
tr::lng_settings_auto_archive(),
|
||||||
|
st::settingsButton
|
||||||
|
)->toggleOn(
|
||||||
|
privacy->archiveAndMute()
|
||||||
|
)->toggledChanges(
|
||||||
|
) | rpl::filter([=](bool toggled) {
|
||||||
|
return toggled != privacy->archiveAndMuteCurrent();
|
||||||
|
}) | rpl::start_with_next([=](bool toggled) {
|
||||||
|
privacy->update(toggled);
|
||||||
|
}, container->lifetime());
|
||||||
|
|
||||||
|
AddSkip(inner);
|
||||||
|
AddDividerText(inner, tr::lng_settings_auto_archive_about());
|
||||||
|
|
||||||
|
using namespace rpl::mappers;
|
||||||
|
wrap->toggleOn(rpl::single(
|
||||||
|
false
|
||||||
|
) | rpl::then(
|
||||||
|
session->api().globalPrivacy().showArchiveAndMute(
|
||||||
|
) | rpl::filter(_1) | rpl::take(1)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
not_null<Ui::SlideWrap<Ui::PlainShadow>*> AddSeparator(
|
not_null<Ui::SlideWrap<Ui::PlainShadow>*> AddSeparator(
|
||||||
not_null<Ui::VerticalLayout*> container) {
|
not_null<Ui::VerticalLayout*> container) {
|
||||||
return container->add(
|
return container->add(
|
||||||
|
@ -647,6 +691,7 @@ void PrivacySecurity::setupContent(
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||||
|
|
||||||
SetupPrivacy(controller, content);
|
SetupPrivacy(controller, content);
|
||||||
|
SetupArchiveAndMute(controller, content);
|
||||||
SetupSessionsList(controller, content);
|
SetupSessionsList(controller, content);
|
||||||
SetupLocalPasscode(controller, content);
|
SetupLocalPasscode(controller, content);
|
||||||
SetupCloudPassword(controller, content);
|
SetupCloudPassword(controller, content);
|
||||||
|
|
Loading…
Add table
Reference in a new issue