"Fossies" - the Fresh Open Source Software Archive 
Member "tdesktop-2.6.1/Telegram/SourceFiles/api/api_global_privacy.cpp" (24 Feb 2021, 2733 Bytes) of package /linux/misc/tdesktop-2.6.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "api_global_privacy.cpp" see the
Fossies "Dox" file reference documentation.
1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #include "api/api_global_privacy.h"
9
10 #include "apiwrap.h"
11 #include "main/main_session.h"
12 #include "main/main_account.h"
13 #include "main/main_app_config.h"
14
15 namespace Api {
16
17 GlobalPrivacy::GlobalPrivacy(not_null<ApiWrap*> api)
18 : _session(&api->session())
19 , _api(&api->instance()) {
20 }
21
22 void GlobalPrivacy::reload(Fn<void()> callback) {
23 if (callback) {
24 _callbacks.push_back(std::move(callback));
25 }
26 if (_requestId) {
27 return;
28 }
29 _requestId = _api.request(MTPaccount_GetGlobalPrivacySettings(
30 )).done([=](const MTPGlobalPrivacySettings &result) {
31 _requestId = 0;
32 apply(result);
33 for (const auto &callback : base::take(_callbacks)) {
34 callback();
35 }
36 }).fail([=](const RPCError &error) {
37 _requestId = 0;
38 for (const auto &callback : base::take(_callbacks)) {
39 callback();
40 }
41 }).send();
42
43 _session->account().appConfig().value(
44 ) | rpl::start_with_next([=] {
45 _showArchiveAndMute = _session->account().appConfig().get<bool>(
46 u"autoarchive_setting_available"_q,
47 false);
48 }, _session->lifetime());
49 }
50
51 bool GlobalPrivacy::archiveAndMuteCurrent() const {
52 return _archiveAndMute.current();
53 }
54
55 rpl::producer<bool> GlobalPrivacy::archiveAndMute() const {
56 return _archiveAndMute.value();
57 }
58
59 rpl::producer<bool> GlobalPrivacy::showArchiveAndMute() const {
60 using namespace rpl::mappers;
61
62 return rpl::combine(
63 archiveAndMute(),
64 _showArchiveAndMute.value(),
65 _1 || _2);
66 }
67
68 rpl::producer<> GlobalPrivacy::suggestArchiveAndMute() const {
69 return _session->account().appConfig().suggestionRequested(
70 u"AUTOARCHIVE_POPULAR"_q);
71 }
72
73 void GlobalPrivacy::dismissArchiveAndMuteSuggestion() {
74 _session->account().appConfig().dismissSuggestion(
75 u"AUTOARCHIVE_POPULAR"_q);
76 }
77
78 void GlobalPrivacy::update(bool archiveAndMute) {
79 using Flag = MTPDglobalPrivacySettings::Flag;
80
81 _api.request(_requestId).cancel();
82 _requestId = _api.request(MTPaccount_SetGlobalPrivacySettings(
83 MTP_globalPrivacySettings(
84 MTP_flags(Flag::f_archive_and_mute_new_noncontact_peers),
85 MTP_bool(archiveAndMute))
86 )).done([=](const MTPGlobalPrivacySettings &result) {
87 _requestId = 0;
88 apply(result);
89 }).fail([=](const RPCError &error) {
90 _requestId = 0;
91 }).send();
92 _archiveAndMute = archiveAndMute;
93 }
94
95 void GlobalPrivacy::apply(const MTPGlobalPrivacySettings &data) {
96 data.match([&](const MTPDglobalPrivacySettings &data) {
97 _archiveAndMute = data.varchive_and_mute_new_noncontact_peers()
98 ? mtpIsTrue(*data.varchive_and_mute_new_noncontact_peers())
99 : false;
100 });
101 }
102
103 } // namespace Api