MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / TLToRules

Function TLToRules

Telegram/SourceFiles/api/api_user_privacy.cpp:108–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108UserPrivacy::Rule TLToRules(const TLRules &rules, Data::Session &owner) {
109 // This is simplified version of privacy rules interpretation.
110 // But it should be fine for all the apps
111 // that use the same subset of features.
112 using Option = UserPrivacy::Option;
113 auto result = UserPrivacy::Rule();
114 auto optionSet = false;
115 const auto setOption = [&](Option option) {
116 if (optionSet) {
117 return;
118 }
119 optionSet = true;
120 result.option = option;
121 };
122 auto &always = result.always.peers;
123 auto &never = result.never.peers;
124 const auto feed = [&](const MTPPrivacyRule &rule) {
125 rule.match([&](const MTPDprivacyValueAllowAll &) {
126 setOption(Option::Everyone);
127 }, [&](const MTPDprivacyValueAllowContacts &) {
128 setOption(Option::Contacts);
129 }, [&](const MTPDprivacyValueAllowCloseFriends &) {
130 setOption(Option::CloseFriends);
131 }, [&](const MTPDprivacyValueAllowPremium &) {
132 result.always.premiums = true;
133 }, [&](const MTPDprivacyValueAllowBots &) {
134 result.always.miniapps = true;
135 }, [&](const MTPDprivacyValueDisallowBots &) {
136 result.never.miniapps = true;
137 }, [&](const MTPDprivacyValueAllowUsers &data) {
138 const auto &users = data.vusers().v;
139 always.reserve(always.size() + users.size());
140 for (const auto &userId : users) {
141 const auto user = owner.user(UserId(userId.v));
142 if (!base::contains(never, user)
143 && !base::contains(always, user)) {
144 always.emplace_back(user);
145 }
146 }
147 }, [&](const MTPDprivacyValueAllowChatParticipants &data) {
148 const auto &chats = data.vchats().v;
149 always.reserve(always.size() + chats.size());
150 for (const auto &chatId : chats) {
151 const auto chat = owner.chatLoaded(chatId);
152 const auto peer = chat
153 ? static_cast<PeerData*>(chat)
154 : owner.channelLoaded(chatId);
155 if (peer
156 && !base::contains(never, peer)
157 && !base::contains(always, peer)) {
158 always.emplace_back(peer);
159 }
160 }
161 }, [&](const MTPDprivacyValueDisallowContacts &) {
162 // Not supported
163 }, [&](const MTPDprivacyValueDisallowAll &) {
164 setOption(Option::Nobody);
165 }, [&](const MTPDprivacyValueDisallowUsers &data) {

Callers 1

pushPrivacyMethod · 0.85

Calls 6

RuleClass · 0.85
UserIdClass · 0.50
sizeMethod · 0.45
userMethod · 0.45
chatLoadedMethod · 0.45
channelLoadedMethod · 0.45

Tested by

no test coverage detected