| 1801 | } |
| 1802 | |
| 1803 | Data::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 | |
| 1860 | bool PeerData::amAnonymous() const { |
no test coverage detected