Hide Add Users checkbox if megagroup is democracy.

Also unite invite_users and invite_link flags.
This commit is contained in:
John Preston 2017-06-14 13:58:54 +03:00
parent adcecaa195
commit 04e587b999
3 changed files with 14 additions and 8 deletions

View File

@ -1264,8 +1264,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
"lng_rights_channel_delete" = "Delete messages of others";
"lng_rights_group_info" = "Change group info";
"lng_rights_group_ban" = "Ban users";
"lng_rights_group_invite_link" = "Invite users via link";
"lng_rights_group_invite" = "Add users";
//"lng_rights_group_invite_link" = "Invite users via link";
"lng_rights_group_pin" = "Pin messages";
"lng_rights_group_delete" = "Delete messages";
"lng_rights_add_admins" = "Add new admins";

View File

@ -185,25 +185,24 @@ void EditAdminBox::prepare() {
addControl(object_ptr<Ui::FlatLabel>(this, lang(lng_rights_edit_admin_header), Ui::FlatLabel::InitType::Simple, st::boxLabel));
auto addCheckbox = [this](Flag flag, const QString &text) {
auto addCheckbox = [this](Flags flags, const QString &text) {
if (!channel()->amCreator()) {
if (!(channel()->adminRights().vflags.v & flag)) {
if (!(channel()->adminRights().vflags.v & flags)) {
return; // Don't add options that we don't have ourselves.
}
}
auto checked = (_rights.c_channelAdminRights().vflags.v & flag) != 0;
auto checked = (_rights.c_channelAdminRights().vflags.v & flags) != 0;
auto control = addControl(object_ptr<Ui::Checkbox>(this, text, checked, st::defaultBoxCheckbox));
connect(control, &Ui::Checkbox::changed, this, [this, control] {
applyDependencies(control);
}, Qt::QueuedConnection);
_checkboxes.emplace(flag, control);
_checkboxes.emplace(flags, control);
};
if (channel()->isMegagroup()) {
addCheckbox(Flag::f_change_info, lang(lng_rights_group_info));
addCheckbox(Flag::f_delete_messages, lang(lng_rights_group_delete));
addCheckbox(Flag::f_ban_users, lang(lng_rights_group_ban));
addCheckbox(Flag::f_invite_users, lang(lng_rights_group_invite));
// addCheckbox(Flag::f_invite_link, lang(lng_rights_group_invite_link));
addCheckbox(Flag::f_invite_users | Flag::f_invite_link, lang(channel()->anyoneCanAddMembers() ? lng_rights_group_invite_link : lng_rights_group_invite));
addCheckbox(Flag::f_pin_messages, lang(lng_rights_group_pin));
addCheckbox(Flag::f_add_admins, lang(lng_rights_add_admins));
} else {
@ -234,6 +233,10 @@ void EditAdminBox::prepare() {
newFlags &= ~checkbox.first;
}
}
if (!channel()->amCreator()) {
// Leave only rights that we have so we could save them.
newFlags &= channel()->adminRights().vflags.v;
}
_saveCallback(MTP_channelAdminRights(MTP_flags(newFlags)));
});
addButton(langFactory(lng_cancel), [this] { closeBox(); });

View File

@ -864,8 +864,11 @@ public:
bool canDeleteMessages() const {
return adminRights().is_delete_messages() || amCreator();
}
bool anyoneCanAddMembers() const {
return (flags & MTPDchannel::Flag::f_democracy);
}
bool canAddMembers() const {
return adminRights().is_invite_users() || amCreator() || (amIn() && (flags & MTPDchannel::Flag::f_democracy));
return adminRights().is_invite_users() || amCreator() || (anyoneCanAddMembers() && amIn() && !hasRestrictedRights());
}
bool canAddAdmins() const {
return adminRights().is_add_admins() || amCreator();