mirror of https://github.com/procxx/kepka.git
				
				
				
			Edit who can add users to supergroup.
Add a couple of radiobuttons to EditChannelBox for that. Also a 'change info' admin now can edit 'signatures' in a channel.
This commit is contained in:
		
							parent
							
								
									9de95cee23
								
							
						
					
					
						commit
						758cf0388e
					
				| 
						 | 
					@ -1101,6 +1101,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
				
			||||||
"lng_edit_contact_title" = "Edit contact name";
 | 
					"lng_edit_contact_title" = "Edit contact name";
 | 
				
			||||||
"lng_edit_channel_title" = "Edit channel";
 | 
					"lng_edit_channel_title" = "Edit channel";
 | 
				
			||||||
"lng_edit_sign_messages" = "Sign messages";
 | 
					"lng_edit_sign_messages" = "Sign messages";
 | 
				
			||||||
 | 
					"lng_edit_group_who_invites" = "Who can add members";
 | 
				
			||||||
 | 
					"lng_edit_group_invites_everybody" = "All members";
 | 
				
			||||||
 | 
					"lng_edit_group_invites_only_admins" = "Only admins";
 | 
				
			||||||
"lng_edit_group" = "Edit group";
 | 
					"lng_edit_group" = "Edit group";
 | 
				
			||||||
"lng_edit_self_title" = "Edit your name";
 | 
					"lng_edit_self_title" = "Edit your name";
 | 
				
			||||||
"lng_confirm_contact_data" = "New Contact";
 | 
					"lng_confirm_contact_data" = "New Contact";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -911,11 +911,14 @@ void EditNameTitleBox::onSaveChatDone(const MTPUpdates &updates) {
 | 
				
			||||||
	closeBox();
 | 
						closeBox();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EditChannelBox::EditChannelBox(QWidget*, ChannelData *channel)
 | 
					EditChannelBox::EditChannelBox(QWidget*, gsl::not_null<ChannelData*> channel)
 | 
				
			||||||
: _channel(channel)
 | 
					: _channel(channel)
 | 
				
			||||||
, _title(this, st::defaultInputField, langFactory(_channel->isMegagroup() ? lng_dlg_new_group_name : lng_dlg_new_channel_name), _channel->name)
 | 
					, _title(this, st::defaultInputField, langFactory(_channel->isMegagroup() ? lng_dlg_new_group_name : lng_dlg_new_channel_name), _channel->name)
 | 
				
			||||||
, _description(this, st::newGroupDescription, langFactory(lng_create_group_description), _channel->about())
 | 
					, _description(this, st::newGroupDescription, langFactory(lng_create_group_description), _channel->about())
 | 
				
			||||||
, _sign(this, lang(lng_edit_sign_messages), channel->addsSignature(), st::defaultBoxCheckbox)
 | 
					, _sign(this, lang(lng_edit_sign_messages), channel->addsSignature(), st::defaultBoxCheckbox)
 | 
				
			||||||
 | 
					, _inviteGroup(std::make_shared<Ui::RadioenumGroup<Invites>>(channel->anyoneCanAddMembers() ? Invites::Everybody : Invites::OnlyAdmins))
 | 
				
			||||||
 | 
					, _inviteEverybody(this, _inviteGroup, Invites::Everybody, lang(lng_edit_group_invites_everybody))
 | 
				
			||||||
 | 
					, _inviteOnlyAdmins(this, _inviteGroup, Invites::OnlyAdmins, lang(lng_edit_group_invites_only_admins))
 | 
				
			||||||
, _publicLink(this, lang(channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link), st::boxLinkButton) {
 | 
					, _publicLink(this, lang(channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link), st::boxLinkButton) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -970,7 +973,11 @@ void EditChannelBox::onDescriptionResized() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool EditChannelBox::canEditSignatures() const {
 | 
					bool EditChannelBox::canEditSignatures() const {
 | 
				
			||||||
	return _channel->amCreator() && !_channel->isMegagroup();
 | 
						return _channel->canEditInformation() && !_channel->isMegagroup();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool EditChannelBox::canEditInvites() const {
 | 
				
			||||||
 | 
						return _channel->canEditInformation() && _channel->isMegagroup();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditChannelBox::updateMaxHeight() {
 | 
					void EditChannelBox::updateMaxHeight() {
 | 
				
			||||||
| 
						 | 
					@ -979,6 +986,10 @@ void EditChannelBox::updateMaxHeight() {
 | 
				
			||||||
	if (canEditSignatures()) {
 | 
						if (canEditSignatures()) {
 | 
				
			||||||
		newHeight += st::newGroupPublicLinkPadding.top() + _sign->heightNoMargins() + st::newGroupPublicLinkPadding.bottom();
 | 
							newHeight += st::newGroupPublicLinkPadding.top() + _sign->heightNoMargins() + st::newGroupPublicLinkPadding.bottom();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (canEditInvites()) {
 | 
				
			||||||
 | 
							newHeight += st::boxTitleHeight + _inviteEverybody->heightNoMargins();
 | 
				
			||||||
 | 
							newHeight += st::boxLittleSkip + _inviteOnlyAdmins->heightNoMargins();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (_channel->canEditUsername()) {
 | 
						if (_channel->canEditUsername()) {
 | 
				
			||||||
		newHeight += st::newGroupPublicLinkPadding.top() + _publicLink->height() + st::newGroupPublicLinkPadding.bottom();
 | 
							newHeight += st::newGroupPublicLinkPadding.top() + _publicLink->height() + st::newGroupPublicLinkPadding.bottom();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -997,15 +1008,31 @@ void EditChannelBox::resizeEvent(QResizeEvent *e) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_sign->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
						_sign->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_inviteEverybody->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::boxTitleHeight);
 | 
				
			||||||
 | 
						_inviteOnlyAdmins->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _inviteEverybody->bottomNoMargins() + st::boxLittleSkip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (canEditSignatures()) {
 | 
						if (canEditSignatures()) {
 | 
				
			||||||
		_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _sign->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
							_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _sign->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
				
			||||||
 | 
						} else if (canEditInvites()) {
 | 
				
			||||||
 | 
							_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _inviteOnlyAdmins->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
							_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void EditChannelBox::paintEvent(QPaintEvent *e) {
 | 
				
			||||||
 | 
						BoxContent::paintEvent(e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (canEditInvites()) {
 | 
				
			||||||
 | 
							Painter p(this);
 | 
				
			||||||
 | 
							p.setPen(st::boxTitleFg);
 | 
				
			||||||
 | 
							p.setFont(st::autoDownloadTitleFont);
 | 
				
			||||||
 | 
							p.drawTextLeft(st::boxTitlePosition.x(), _description->y() + _description->height() + st::boxTitlePosition.y(), width(), lang(lng_edit_group_who_invites));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditChannelBox::onSave() {
 | 
					void EditChannelBox::onSave() {
 | 
				
			||||||
	if (_saveTitleRequestId || _saveDescriptionRequestId || _saveSignRequestId) return;
 | 
						if (_saveTitleRequestId || _saveDescriptionRequestId || _saveSignRequestId || _saveInvitesRequestId) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QString title = prepareText(_title->getLastText()), description = prepareText(_description->getLastText(), true);
 | 
						QString title = prepareText(_title->getLastText()), description = prepareText(_description->getLastText(), true);
 | 
				
			||||||
	if (title.isEmpty()) {
 | 
						if (title.isEmpty()) {
 | 
				
			||||||
| 
						 | 
					@ -1036,12 +1063,20 @@ void EditChannelBox::saveDescription() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditChannelBox::saveSign() {
 | 
					void EditChannelBox::saveSign() {
 | 
				
			||||||
	if (!canEditSignatures() || _channel->addsSignature() == _sign->checked()) {
 | 
						if (!canEditSignatures() || _channel->addsSignature() == _sign->checked()) {
 | 
				
			||||||
		closeBox();
 | 
							saveInvites();
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		_saveSignRequestId = MTP::send(MTPchannels_ToggleSignatures(_channel->inputChannel, MTP_bool(_sign->checked())), rpcDone(&EditChannelBox::onSaveSignDone), rpcFail(&EditChannelBox::onSaveFail));
 | 
							_saveSignRequestId = MTP::send(MTPchannels_ToggleSignatures(_channel->inputChannel, MTP_bool(_sign->checked())), rpcDone(&EditChannelBox::onSaveSignDone), rpcFail(&EditChannelBox::onSaveFail));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void EditChannelBox::saveInvites() {
 | 
				
			||||||
 | 
						if (!canEditInvites() || _channel->anyoneCanAddMembers() == (_inviteGroup->value() == Invites::Everybody)) {
 | 
				
			||||||
 | 
							closeBox();
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							_saveInvitesRequestId = MTP::send(MTPchannels_ToggleInvites(_channel->inputChannel, MTP_bool(_inviteGroup->value() == Invites::Everybody)), rpcDone(&EditChannelBox::onSaveInvitesDone), rpcFail(&EditChannelBox::onSaveFail));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) {
 | 
					bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) {
 | 
				
			||||||
	if (MTP::isDefaultHandledError(error)) return false;
 | 
						if (MTP::isDefaultHandledError(error)) return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1074,6 +1109,12 @@ bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if (req == _saveSignRequestId) {
 | 
						} else if (req == _saveSignRequestId) {
 | 
				
			||||||
		_saveSignRequestId = 0;
 | 
							_saveSignRequestId = 0;
 | 
				
			||||||
 | 
							if (err == qstr("CHAT_NOT_MODIFIED")) {
 | 
				
			||||||
 | 
								saveInvites();
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else if (req == _saveInvitesRequestId) {
 | 
				
			||||||
 | 
							_saveInvitesRequestId = 0;
 | 
				
			||||||
		if (err == qstr("CHAT_NOT_MODIFIED")) {
 | 
							if (err == qstr("CHAT_NOT_MODIFIED")) {
 | 
				
			||||||
			closeBox();
 | 
								closeBox();
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
| 
						 | 
					@ -1082,11 +1123,9 @@ bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) {
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditChannelBox::onSaveTitleDone(const MTPUpdates &updates) {
 | 
					void EditChannelBox::onSaveTitleDone(const MTPUpdates &result) {
 | 
				
			||||||
	_saveTitleRequestId = 0;
 | 
						_saveTitleRequestId = 0;
 | 
				
			||||||
	if (App::main()) {
 | 
						AuthSession::Current().api().applyUpdates(result);
 | 
				
			||||||
		App::main()->sentUpdatesReceived(updates);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	saveDescription();
 | 
						saveDescription();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1100,11 +1139,15 @@ void EditChannelBox::onSaveDescriptionDone(const MTPBool &result) {
 | 
				
			||||||
	saveSign();
 | 
						saveSign();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditChannelBox::onSaveSignDone(const MTPUpdates &updates) {
 | 
					void EditChannelBox::onSaveSignDone(const MTPUpdates &result) {
 | 
				
			||||||
	_saveSignRequestId = 0;
 | 
						_saveSignRequestId = 0;
 | 
				
			||||||
	if (App::main()) {
 | 
						AuthSession::Current().api().applyUpdates(result);
 | 
				
			||||||
		App::main()->sentUpdatesReceived(updates);
 | 
						saveInvites();
 | 
				
			||||||
	}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void EditChannelBox::onSaveInvitesDone(const MTPUpdates &result) {
 | 
				
			||||||
 | 
						_saveSignRequestId = 0;
 | 
				
			||||||
 | 
						AuthSession::Current().api().applyUpdates(result);
 | 
				
			||||||
	closeBox();
 | 
						closeBox();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,7 +234,7 @@ class EditChannelBox : public BoxContent, public RPCSender {
 | 
				
			||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	EditChannelBox(QWidget*, ChannelData *channel);
 | 
						EditChannelBox(QWidget*, gsl::not_null<ChannelData*> channel);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
	void prepare() override;
 | 
						void prepare() override;
 | 
				
			||||||
| 
						 | 
					@ -242,6 +242,7 @@ protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void keyPressEvent(QKeyEvent *e) override;
 | 
						void keyPressEvent(QKeyEvent *e) override;
 | 
				
			||||||
	void resizeEvent(QResizeEvent *e) override;
 | 
						void resizeEvent(QResizeEvent *e) override;
 | 
				
			||||||
 | 
						void paintEvent(QPaintEvent *e) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
	void peerUpdated(PeerData *peer);
 | 
						void peerUpdated(PeerData *peer);
 | 
				
			||||||
| 
						 | 
					@ -256,26 +257,38 @@ private slots:
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	void updateMaxHeight();
 | 
						void updateMaxHeight();
 | 
				
			||||||
	bool canEditSignatures() const;
 | 
						bool canEditSignatures() const;
 | 
				
			||||||
 | 
						bool canEditInvites() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void onSaveTitleDone(const MTPUpdates &updates);
 | 
						void onSaveTitleDone(const MTPUpdates &result);
 | 
				
			||||||
	void onSaveDescriptionDone(const MTPBool &result);
 | 
						void onSaveDescriptionDone(const MTPBool &result);
 | 
				
			||||||
	void onSaveSignDone(const MTPUpdates &updates);
 | 
						void onSaveSignDone(const MTPUpdates &result);
 | 
				
			||||||
	bool onSaveFail(const RPCError &e, mtpRequestId req);
 | 
						void onSaveInvitesDone(const MTPUpdates &result);
 | 
				
			||||||
 | 
						bool onSaveFail(const RPCError &error, mtpRequestId req);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void saveDescription();
 | 
						void saveDescription();
 | 
				
			||||||
	void saveSign();
 | 
						void saveSign();
 | 
				
			||||||
 | 
						void saveInvites();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ChannelData *_channel;
 | 
						gsl::not_null<ChannelData*> _channel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	object_ptr<Ui::InputField> _title;
 | 
						object_ptr<Ui::InputField> _title;
 | 
				
			||||||
	object_ptr<Ui::InputArea> _description;
 | 
						object_ptr<Ui::InputArea> _description;
 | 
				
			||||||
	object_ptr<Ui::Checkbox> _sign;
 | 
						object_ptr<Ui::Checkbox> _sign;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						enum class Invites {
 | 
				
			||||||
 | 
							Everybody,
 | 
				
			||||||
 | 
							OnlyAdmins,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						std::shared_ptr<Ui::RadioenumGroup<Invites>> _inviteGroup;
 | 
				
			||||||
 | 
						object_ptr<Ui::Radioenum<Invites>> _inviteEverybody;
 | 
				
			||||||
 | 
						object_ptr<Ui::Radioenum<Invites>> _inviteOnlyAdmins;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	object_ptr<Ui::LinkButton> _publicLink;
 | 
						object_ptr<Ui::LinkButton> _publicLink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mtpRequestId _saveTitleRequestId = 0;
 | 
						mtpRequestId _saveTitleRequestId = 0;
 | 
				
			||||||
	mtpRequestId _saveDescriptionRequestId = 0;
 | 
						mtpRequestId _saveDescriptionRequestId = 0;
 | 
				
			||||||
	mtpRequestId _saveSignRequestId = 0;
 | 
						mtpRequestId _saveSignRequestId = 0;
 | 
				
			||||||
 | 
						mtpRequestId _saveInvitesRequestId = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QString _sentTitle, _sentDescription;
 | 
						QString _sentTitle, _sentDescription;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -459,7 +459,7 @@ newGroupNamePosition: point(27px, 5px);
 | 
				
			||||||
newGroupDescriptionPadding: margins(0px, 13px, 0px, 4px);
 | 
					newGroupDescriptionPadding: margins(0px, 13px, 0px, 4px);
 | 
				
			||||||
newGroupDescription: InputField(defaultInputField) {
 | 
					newGroupDescription: InputField(defaultInputField) {
 | 
				
			||||||
	textMargins: margins(1px, 26px, 1px, 4px);
 | 
						textMargins: margins(1px, 26px, 1px, 4px);
 | 
				
			||||||
	heightMax: 135px;
 | 
						heightMax: 116px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
setupChannelLink: InputField(defaultInputField) {
 | 
					setupChannelLink: InputField(defaultInputField) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue