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

Method amRestricted

Telegram/SourceFiles/data/data_peer.cpp:1803–1858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1801}
1802
1803Data::RestrictionCheckResult PeerData::amRestricted(
1804 ChatRestriction right) const {
1805 using Result = Data::RestrictionCheckResult;
1806 const auto allowByAdminRights = [](auto right, auto chat) -> bool {
1807 if (right == ChatRestriction::AddParticipants) {
1808 return chat->adminRights() & ChatAdminRight::InviteByLinkOrAdd;
1809 } else if (right == ChatRestriction::ChangeInfo) {
1810 return chat->adminRights() & ChatAdminRight::ChangeInfo;
1811 } else if (right == ChatRestriction::CreateTopics) {
1812 return chat->adminRights() & ChatAdminRight::ManageTopics;
1813 } else if (right == ChatRestriction::PinMessages) {
1814 return chat->adminRights() & ChatAdminRight::PinMessages;
1815 } else {
1816 return chat->hasAdminRights();
1817 }
1818 };
1819 if (const auto user = asUser()) {
1820 if (user->requiresPremiumToWrite() && !user->session().premium()) {
1821 return Result::Explicit();
1822 }
1823 return (right == ChatRestriction::SendVoiceMessages
1824 || right == ChatRestriction::SendVideoMessages)
1825 ? ((user->flags() & UserDataFlag::VoiceMessagesForbidden)
1826 ? Result::Explicit()
1827 : Result::Allowed())
1828 : (right == ChatRestriction::PinMessages)
1829 ? ((user->flags() & UserDataFlag::CanPinMessages)
1830 ? Result::Allowed()
1831 : Result::Explicit())
1832 : Result::Allowed();
1833 } else if (const auto channel = asChannel()) {
1834 if (channel->monoforumDisabled()) {
1835 return Result::WithEveryone();
1836 }
1837 const auto defaultRestrictions = channel->defaultRestrictions()
1838 | (channel->isPublic()
1839 ? (ChatRestriction::PinMessages
1840 | ChatRestriction::ChangeInfo)
1841 : ChatRestrictions(0));
1842 return (channel->amCreator() || allowByAdminRights(right, channel))
1843 ? Result::Allowed()
1844 : ((defaultRestrictions & right)
1845 && !channel->unrestrictedByBoosts())
1846 ? Result::WithEveryone()
1847 : (channel->restrictions() & right)
1848 ? Result::Explicit()
1849 : Result::Allowed();
1850 } else if (const auto chat = asChat()) {
1851 return (chat->amCreator() || allowByAdminRights(right, chat))
1852 ? Result::Allowed()
1853 : (chat->defaultRestrictions() & right)
1854 ? Result::WithEveryone()
1855 : Result::Allowed();
1856 }
1857 return Result::Allowed();
1858}
1859
1860bool PeerData::amAnonymous() const {

Callers 10

rowContextMenuMethod · 0.80
computeTypeMethod · 0.80
TagInfoBoxFunction · 0.80
canPinMessagesMethod · 0.80
canCreateTopicsMethod · 0.80
CanSendAnyOfFunction · 0.80
RestrictionErrorFunction · 0.80
HistoryItemMethod · 0.80
canReactMethod · 0.80
checkPreviewMethod · 0.80

Calls 13

monoforumDisabledMethod · 0.80
isPublicMethod · 0.80
unrestrictedByBoostsMethod · 0.80
AllowedFunction · 0.50
adminRightsMethod · 0.45
hasAdminRightsMethod · 0.45
premiumMethod · 0.45
sessionMethod · 0.45
flagsMethod · 0.45
defaultRestrictionsMethod · 0.45
amCreatorMethod · 0.45

Tested by

no test coverage detected