From 04e587b99925a9b52e85508dc6a992f528e799a7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 14 Jun 2017 13:58:54 +0300 Subject: [PATCH] Hide Add Users checkbox if megagroup is democracy. Also unite invite_users and invite_link flags. --- Telegram/Resources/langs/lang.strings | 2 +- .../SourceFiles/boxes/edit_participant_box.cpp | 15 +++++++++------ Telegram/SourceFiles/structs.h | 5 ++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 61fb3ea54..0734545d2 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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"; diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/edit_participant_box.cpp index 8975f9d2c..2fb11c8a5 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_participant_box.cpp @@ -185,25 +185,24 @@ void EditAdminBox::prepare() { addControl(object_ptr(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(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(); }); diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index f682d52c3..181ad7968 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -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();