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

Function RulesToTL

Telegram/SourceFiles/api/api_user_privacy.cpp:28–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using TLRules = MTPVector<MTPPrivacyRule>;
27
28TLInputRules RulesToTL(const UserPrivacy::Rule &rule) {
29 using Exceptions = UserPrivacy::Exceptions;
30 const auto collectInputUsers = [](const Exceptions &exceptions) {
31 const auto &peers = exceptions.peers;
32 auto result = QVector<MTPInputUser>();
33 result.reserve(peers.size());
34 for (const auto &peer : peers) {
35 if (const auto user = peer->asUser()) {
36 result.push_back(user->inputUser());
37 }
38 }
39 return result;
40 };
41 const auto collectInputChats = [](const Exceptions &exceptions) {
42 const auto &peers = exceptions.peers;
43 auto result = QVector<MTPlong>();
44 result.reserve(peers.size());
45 for (const auto &peer : peers) {
46 if (!peer->isUser()) {
47 result.push_back(peerToBareMTPInt(peer->id));
48 }
49 }
50 return result;
51 };
52
53 using Option = UserPrivacy::Option;
54 auto result = QVector<MTPInputPrivacyRule>();
55 result.reserve(kMaxRules);
56 if (!rule.ignoreAlways) {
57 const auto users = collectInputUsers(rule.always);
58 const auto chats = collectInputChats(rule.always);
59 if (!users.empty()) {
60 result.push_back(
61 MTP_inputPrivacyValueAllowUsers(
62 MTP_vector<MTPInputUser>(users)));
63 }
64 if (!chats.empty()) {
65 result.push_back(
66 MTP_inputPrivacyValueAllowChatParticipants(
67 MTP_vector<MTPlong>(chats)));
68 }
69 if (rule.always.premiums && (rule.option != Option::Everyone)) {
70 result.push_back(MTP_inputPrivacyValueAllowPremium());
71 }
72 if (rule.always.miniapps && (rule.option != Option::Everyone)) {
73 result.push_back(MTP_inputPrivacyValueAllowBots());
74 }
75 }
76 if (!rule.ignoreNever) {
77 const auto users = collectInputUsers(rule.never);
78 const auto chats = collectInputChats(rule.never);
79 if (!users.empty()) {
80 result.push_back(
81 MTP_inputPrivacyValueDisallowUsers(
82 MTP_vector<MTPInputUser>(users)));
83 }
84 if (!chats.empty()) {
85 result.push_back(

Callers 1

saveMethod · 0.85

Calls 6

peerToBareMTPIntFunction · 0.85
asUserMethod · 0.80
inputUserMethod · 0.80
sizeMethod · 0.45
isUserMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected