Fix permissions dependencies.
This commit is contained in:
parent
ae6c152988
commit
5ec80238a0
|
@ -327,11 +327,12 @@ void EditRestrictedBox::prepare() {
|
||||||
const auto prepareRights = (_oldRights.c_chatBannedRights().vflags.v
|
const auto prepareRights = (_oldRights.c_chatBannedRights().vflags.v
|
||||||
? _oldRights
|
? _oldRights
|
||||||
: Defaults(peer()));
|
: Defaults(peer()));
|
||||||
const auto prepareFlags = prepareRights.c_chatBannedRights().vflags.v
|
const auto prepareFlags = FixDependentRestrictions(
|
||||||
|
prepareRights.c_chatBannedRights().vflags.v
|
||||||
| defaultRestrictions
|
| defaultRestrictions
|
||||||
| ((channel && channel->isPublic())
|
| ((channel && channel->isPublic())
|
||||||
? (Flag::f_change_info | Flag::f_pin_messages)
|
? (Flag::f_change_info | Flag::f_pin_messages)
|
||||||
: Flags(0));
|
: Flags(0)));
|
||||||
const auto disabledMessages = [&] {
|
const auto disabledMessages = [&] {
|
||||||
auto result = std::map<Flags, QString>();
|
auto result = std::map<Flags, QString>();
|
||||||
if (!canSave()) {
|
if (!canSave()) {
|
||||||
|
@ -339,10 +340,11 @@ void EditRestrictedBox::prepare() {
|
||||||
~Flags(0),
|
~Flags(0),
|
||||||
lang(lng_rights_about_restriction_cant_edit));
|
lang(lng_rights_about_restriction_cant_edit));
|
||||||
} else {
|
} else {
|
||||||
const auto disabled = defaultRestrictions
|
const auto disabled = FixDependentRestrictions(
|
||||||
|
defaultRestrictions
|
||||||
| ((channel && channel->isPublic())
|
| ((channel && channel->isPublic())
|
||||||
? (Flag::f_change_info | Flag::f_pin_messages)
|
? (Flag::f_change_info | Flag::f_pin_messages)
|
||||||
: Flags(0));
|
: Flags(0)));
|
||||||
result.emplace(
|
result.emplace(
|
||||||
disabled,
|
disabled,
|
||||||
lang(lng_rights_restriction_for_all));
|
lang(lng_rights_restriction_for_all));
|
||||||
|
|
|
@ -71,7 +71,8 @@ void ApplyDependencies(
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true) {
|
const auto maxFixesCount = int(checkboxes.size());
|
||||||
|
for (auto i = 0; i != maxFixesCount; ++i) {
|
||||||
if (!applySomeDependency()) {
|
if (!applySomeDependency()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -142,10 +143,10 @@ auto Dependencies(ChatRestrictions)
|
||||||
{ Flag::f_send_stickers, Flag::f_send_inline },
|
{ Flag::f_send_stickers, Flag::f_send_inline },
|
||||||
|
|
||||||
// stickers -> send_media
|
// stickers -> send_media
|
||||||
{ Flag::f_send_stickers, Flag::f_send_media },
|
{ Flag::f_send_stickers, Flag::f_send_messages },
|
||||||
|
|
||||||
// embed_links -> send_media
|
// embed_links -> send_media
|
||||||
{ Flag::f_embed_links, Flag::f_send_media },
|
{ Flag::f_embed_links, Flag::f_send_messages },
|
||||||
|
|
||||||
// send_media -> send_messages
|
// send_media -> send_messages
|
||||||
{ Flag::f_send_media, Flag::f_send_messages },
|
{ Flag::f_send_media, Flag::f_send_messages },
|
||||||
|
@ -220,14 +221,14 @@ ChatAdminRights DisabledByDefaultRestrictions(not_null<PeerData*> peer) {
|
||||||
using Flag = ChatAdminRight;
|
using Flag = ChatAdminRight;
|
||||||
using Restriction = ChatRestriction;
|
using Restriction = ChatRestriction;
|
||||||
|
|
||||||
const auto restrictions = [&] {
|
const auto restrictions = FixDependentRestrictions([&] {
|
||||||
if (const auto chat = peer->asChat()) {
|
if (const auto chat = peer->asChat()) {
|
||||||
return chat->defaultRestrictions();
|
return chat->defaultRestrictions();
|
||||||
} else if (const auto channel = peer->asChannel()) {
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
return channel->defaultRestrictions();
|
return channel->defaultRestrictions();
|
||||||
}
|
}
|
||||||
Unexpected("User in DisabledByDefaultRestrictions.");
|
Unexpected("User in DisabledByDefaultRestrictions.");
|
||||||
}();
|
}());
|
||||||
return Flag(0)
|
return Flag(0)
|
||||||
| ((restrictions & Restriction::f_pin_messages)
|
| ((restrictions & Restriction::f_pin_messages)
|
||||||
? Flag(0)
|
? Flag(0)
|
||||||
|
@ -246,6 +247,32 @@ ChatAdminRights DisabledByDefaultRestrictions(not_null<PeerData*> peer) {
|
||||||
: Flag::f_change_info);
|
: Flag::f_change_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions) {
|
||||||
|
const auto &dependencies = Dependencies(restrictions);
|
||||||
|
|
||||||
|
// Fix iOS bug of saving send_inline like embed_links.
|
||||||
|
// We copy send_stickers to send_inline.
|
||||||
|
if (restrictions & ChatRestriction::f_send_stickers) {
|
||||||
|
restrictions |= ChatRestriction::f_send_inline;
|
||||||
|
} else {
|
||||||
|
restrictions &= ~ChatRestriction::f_send_inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the strictest.
|
||||||
|
const auto fixOne = [&] {
|
||||||
|
for (const auto [first, second] : dependencies) {
|
||||||
|
if ((restrictions & second) && !(restrictions & first)) {
|
||||||
|
restrictions |= first;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
while (fixOne()) {
|
||||||
|
}
|
||||||
|
return restrictions;
|
||||||
|
}
|
||||||
|
|
||||||
EditPeerPermissionsBox::EditPeerPermissionsBox(
|
EditPeerPermissionsBox::EditPeerPermissionsBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
not_null<PeerData*> peer)
|
not_null<PeerData*> peer)
|
||||||
|
@ -268,7 +295,7 @@ void EditPeerPermissionsBox::prepare() {
|
||||||
using Flags = ChatRestrictions;
|
using Flags = ChatRestrictions;
|
||||||
|
|
||||||
const auto disabledByAdminRights = DisabledByAdminRights(_peer);
|
const auto disabledByAdminRights = DisabledByAdminRights(_peer);
|
||||||
const auto restrictions = [&] {
|
const auto restrictions = FixDependentRestrictions([&] {
|
||||||
if (const auto chat = _peer->asChat()) {
|
if (const auto chat = _peer->asChat()) {
|
||||||
return chat->defaultRestrictions()
|
return chat->defaultRestrictions()
|
||||||
| disabledByAdminRights;
|
| disabledByAdminRights;
|
||||||
|
@ -280,7 +307,7 @@ void EditPeerPermissionsBox::prepare() {
|
||||||
| disabledByAdminRights;
|
| disabledByAdminRights;
|
||||||
}
|
}
|
||||||
Unexpected("User in EditPeerPermissionsBox.");
|
Unexpected("User in EditPeerPermissionsBox.");
|
||||||
}();
|
}());
|
||||||
const auto disabledMessages = [&] {
|
const auto disabledMessages = [&] {
|
||||||
auto result = std::map<Flags, QString>();
|
auto result = std::map<Flags, QString>();
|
||||||
result.emplace(
|
result.emplace(
|
||||||
|
|
|
@ -57,3 +57,4 @@ EditFlagsControl<MTPDchatAdminRights::Flags> CreateEditAdminRights(
|
||||||
bool anyoneCanAddMembers);
|
bool anyoneCanAddMembers);
|
||||||
|
|
||||||
ChatAdminRights DisabledByDefaultRestrictions(not_null<PeerData*> peer);
|
ChatAdminRights DisabledByDefaultRestrictions(not_null<PeerData*> peer);
|
||||||
|
ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions);
|
||||||
|
|
Loading…
Reference in New Issue