2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Prepare legacy group restrictions checking.

This commit is contained in:
John Preston
2019-01-05 14:50:04 +04:00
parent 441989a8e1
commit 61419b57c8
25 changed files with 415 additions and 403 deletions

View File

@@ -546,3 +546,28 @@ bool PeerData::canWrite() const {
? asUser()->canWrite()
: false;
}
bool PeerData::amRestricted(ChatRestriction right) const {
const auto allowByAdminRights = [](auto right, auto chat) -> bool {
if (right == ChatRestriction::f_invite_users) {
return chat->adminRights() & ChatAdminRight::f_invite_users;
} else if (right == ChatRestriction::f_change_info) {
return chat->adminRights() & ChatAdminRight::f_change_info;
} else if (right == ChatRestriction::f_pin_messages) {
return chat->adminRights() & ChatAdminRight::f_pin_messages;
} else {
return chat->hasAdminRights();
}
};
if (const auto channel = asChannel()) {
return !channel->amCreator()
&& !allowByAdminRights(right, channel)
&& ((channel->restrictions() & right)
|| (channel->defaultRestrictions() & right));
} else if (const auto chat = asChat()) {
return !chat->amCreator()
&& !allowByAdminRights(right, chat)
&& (chat->defaultRestrictions() & right);
}
return false;
}