mirror of https://github.com/procxx/kepka.git
				
				
				
			Refactored code. Removed unused code.
- Deleted manage_peer_box from sources.
This commit is contained in:
		
							parent
							
								
									c86257568f
								
							
						
					
					
						commit
						8887272577
					
				| 
						 | 
					@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "boxes/confirm_box.h"
 | 
					#include "boxes/confirm_box.h"
 | 
				
			||||||
#include "boxes/peer_list_controllers.h"
 | 
					#include "boxes/peer_list_controllers.h"
 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					#include "boxes/peers/edit_participants_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_group_type_box.h"
 | 
					#include "boxes/peers/edit_peer_type_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_history_visibility_box.h"
 | 
					#include "boxes/peers/edit_peer_history_visibility_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_permissions_box.h"
 | 
					#include "boxes/peers/edit_peer_permissions_box.h"
 | 
				
			||||||
#include "boxes/stickers_box.h"
 | 
					#include "boxes/stickers_box.h"
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "window/window_controller.h"
 | 
					#include "window/window_controller.h"
 | 
				
			||||||
#include <rpl/flatten_latest.h>
 | 
					#include <rpl/flatten_latest.h>
 | 
				
			||||||
#include <rpl/range.h>
 | 
					#include <rpl/range.h>
 | 
				
			||||||
 | 
					#include "info/profile/info_profile_icon.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,27 +74,13 @@ void AddSkip(not_null<Ui::VerticalLayout*> container) {
 | 
				
			||||||
	container->add(object_ptr<BoxContentDivider>(container));
 | 
						container->add(object_ptr<BoxContentDivider>(container));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Info::Profile::Button *AddButton(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
					 | 
				
			||||||
		Fn<void()> callback,
 | 
					 | 
				
			||||||
		const style::icon &icon) {
 | 
					 | 
				
			||||||
	return ManagePeerBox::CreateButton(
 | 
					 | 
				
			||||||
		parent,
 | 
					 | 
				
			||||||
		std::move(text),
 | 
					 | 
				
			||||||
		rpl::single(QString()),
 | 
					 | 
				
			||||||
		std::move(callback),
 | 
					 | 
				
			||||||
		st::manageGroupButton,
 | 
					 | 
				
			||||||
		&icon);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AddButtonWithCount(
 | 
					void AddButtonWithCount(
 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
							not_null<Ui::VerticalLayout*> parent,
 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
							rpl::producer<QString> &&text,
 | 
				
			||||||
		rpl::producer<QString> &&count,
 | 
							rpl::producer<QString> &&count,
 | 
				
			||||||
		Fn<void()> callback,
 | 
							Fn<void()> callback,
 | 
				
			||||||
		const style::icon &icon) {
 | 
							const style::icon &icon) {
 | 
				
			||||||
	ManagePeerBox::CreateButton(
 | 
						EditPeerInfoBox::CreateButton(
 | 
				
			||||||
		parent,
 | 
							parent,
 | 
				
			||||||
		std::move(text),
 | 
							std::move(text),
 | 
				
			||||||
		std::move(count),
 | 
							std::move(count),
 | 
				
			||||||
| 
						 | 
					@ -107,7 +94,7 @@ Info::Profile::Button *AddButtonWithText(
 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
							rpl::producer<QString> &&text,
 | 
				
			||||||
		rpl::producer<QString> &&label,
 | 
							rpl::producer<QString> &&label,
 | 
				
			||||||
		Fn<void()> callback) {
 | 
							Fn<void()> callback) {
 | 
				
			||||||
	return ManagePeerBox::CreateButton(
 | 
						return EditPeerInfoBox::CreateButton(
 | 
				
			||||||
		parent,
 | 
							parent,
 | 
				
			||||||
		std::move(text),
 | 
							std::move(text),
 | 
				
			||||||
		std::move(label),
 | 
							std::move(label),
 | 
				
			||||||
| 
						 | 
					@ -160,91 +147,79 @@ void ShowEditPermissions(not_null<PeerData*> peer) {
 | 
				
			||||||
	}, box->lifetime());
 | 
						}, box->lifetime());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FillManageChatBox(
 | 
					void FillManageSection(
 | 
				
			||||||
		not_null<Window::Navigation*> navigation,
 | 
							not_null<Window::Navigation*> navigation,
 | 
				
			||||||
		not_null<ChatData*> chat,
 | 
							not_null<PeerData*> peer,
 | 
				
			||||||
		not_null<Ui::VerticalLayout*> content) {
 | 
							not_null<Ui::VerticalLayout*> content) {
 | 
				
			||||||
 | 
						const auto chat = peer->asChat();
 | 
				
			||||||
 | 
						const auto channel = peer->asChannel();
 | 
				
			||||||
 | 
						const auto isChannel = (!chat);
 | 
				
			||||||
 | 
						if (!chat && !channel) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (chat->canEditPermissions()) {
 | 
						const auto canEditPermissions = [=] {
 | 
				
			||||||
 | 
							return isChannel
 | 
				
			||||||
 | 
								? channel->canEditPermissions()
 | 
				
			||||||
 | 
								: chat->canEditPermissions();
 | 
				
			||||||
 | 
						}();
 | 
				
			||||||
 | 
						const auto canViewAdmins = [=] {
 | 
				
			||||||
 | 
							return isChannel
 | 
				
			||||||
 | 
								? channel->canViewAdmins()
 | 
				
			||||||
 | 
								: chat->amIn();
 | 
				
			||||||
 | 
						}();
 | 
				
			||||||
 | 
						const auto canViewMembers = [=] {
 | 
				
			||||||
 | 
							return isChannel
 | 
				
			||||||
 | 
								? channel->canViewMembers()
 | 
				
			||||||
 | 
								: chat->amIn();
 | 
				
			||||||
 | 
						}();
 | 
				
			||||||
 | 
						const auto canViewKicked = [=] {
 | 
				
			||||||
 | 
							return isChannel
 | 
				
			||||||
 | 
								? (!channel->isMegagroup())
 | 
				
			||||||
 | 
								: false;
 | 
				
			||||||
 | 
						}();
 | 
				
			||||||
 | 
						const auto hasRecentActions = [=] {
 | 
				
			||||||
 | 
							return isChannel
 | 
				
			||||||
 | 
								? (channel->hasAdminRights() || channel->amCreator())
 | 
				
			||||||
 | 
								: false;
 | 
				
			||||||
 | 
						}();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (canEditPermissions) {
 | 
				
			||||||
		AddButtonWithCount(
 | 
							AddButtonWithCount(
 | 
				
			||||||
			content,
 | 
								content,
 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_permissions),
 | 
								Lang::Viewer(lng_manage_peer_permissions),
 | 
				
			||||||
			Info::Profile::RestrictionsCountValue(chat)
 | 
								Info::Profile::RestrictionsCountValue(peer)
 | 
				
			||||||
				| ToPositiveNumberStringRestrictions(),
 | 
									| ToPositiveNumberStringRestrictions(),
 | 
				
			||||||
			[=] { ShowEditPermissions(chat); },
 | 
								[=] { ShowEditPermissions(peer); },
 | 
				
			||||||
			st::infoIconPermissions);
 | 
								st::infoIconPermissions);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (chat->amIn()) {
 | 
						if (canViewAdmins) {
 | 
				
			||||||
		AddButtonWithCount(
 | 
							AddButtonWithCount(
 | 
				
			||||||
			content,
 | 
								content,
 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_administrators),
 | 
								Lang::Viewer(lng_manage_peer_administrators),
 | 
				
			||||||
			Info::Profile::AdminsCountValue(chat)
 | 
								Info::Profile::AdminsCountValue(peer)
 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
									| ToPositiveNumberString(),
 | 
				
			||||||
			[=] {
 | 
								[=] {
 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
									ParticipantsBoxController::Start(
 | 
				
			||||||
					navigation,
 | 
										navigation,
 | 
				
			||||||
					chat,
 | 
										peer,
 | 
				
			||||||
					ParticipantsBoxController::Role::Admins);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconAdministrators);
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_members),
 | 
					 | 
				
			||||||
			Info::Profile::MembersCountValue(chat)
 | 
					 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					chat,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Members);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconMembers);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void FillManageChannelBox(
 | 
					 | 
				
			||||||
		not_null<Window::Navigation*> navigation,
 | 
					 | 
				
			||||||
		not_null<ChannelData*> channel,
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> content) {
 | 
					 | 
				
			||||||
	auto isGroup = channel->isMegagroup();
 | 
					 | 
				
			||||||
	if (channel->canEditPermissions()) {
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_permissions),
 | 
					 | 
				
			||||||
			Info::Profile::RestrictionsCountValue(channel)
 | 
					 | 
				
			||||||
				| ToPositiveNumberStringRestrictions(),
 | 
					 | 
				
			||||||
			[=] { ShowEditPermissions(channel); },
 | 
					 | 
				
			||||||
			st::infoIconPermissions);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (channel->canViewAdmins()) {
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_administrators),
 | 
					 | 
				
			||||||
			Info::Profile::AdminsCountValue(channel)
 | 
					 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					channel,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Admins);
 | 
										ParticipantsBoxController::Role::Admins);
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			st::infoIconAdministrators);
 | 
								st::infoIconAdministrators);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (channel->canViewMembers()) {
 | 
						if (canViewMembers) {
 | 
				
			||||||
		AddButtonWithCount(
 | 
							AddButtonWithCount(
 | 
				
			||||||
			content,
 | 
								content,
 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_members),
 | 
								Lang::Viewer(lng_manage_peer_members),
 | 
				
			||||||
			Info::Profile::MembersCountValue(channel)
 | 
								Info::Profile::MembersCountValue(peer)
 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
									| ToPositiveNumberString(),
 | 
				
			||||||
			[=] {
 | 
								[=] {
 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
									ParticipantsBoxController::Start(
 | 
				
			||||||
					navigation,
 | 
										navigation,
 | 
				
			||||||
					channel,
 | 
										peer,
 | 
				
			||||||
					ParticipantsBoxController::Role::Members);
 | 
										ParticipantsBoxController::Role::Members);
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			st::infoIconMembers);
 | 
								st::infoIconMembers);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!channel->isMegagroup()) {
 | 
						if (canViewKicked) {
 | 
				
			||||||
		AddButtonWithCount(
 | 
							AddButtonWithCount(
 | 
				
			||||||
			content,
 | 
								content,
 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_removed_users),
 | 
								Lang::Viewer(lng_manage_peer_removed_users),
 | 
				
			||||||
| 
						 | 
					@ -253,15 +228,16 @@ void FillManageChannelBox(
 | 
				
			||||||
			[=] {
 | 
								[=] {
 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
									ParticipantsBoxController::Start(
 | 
				
			||||||
					navigation,
 | 
										navigation,
 | 
				
			||||||
					channel,
 | 
										peer,
 | 
				
			||||||
					ParticipantsBoxController::Role::Kicked);
 | 
										ParticipantsBoxController::Role::Kicked);
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			st::infoIconBlacklist);
 | 
								st::infoIconBlacklist);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (HasRecentActions(channel)) {
 | 
						if (hasRecentActions) {
 | 
				
			||||||
		AddButton(
 | 
							AddButtonWithCount(
 | 
				
			||||||
			content,
 | 
								content,
 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_recent_actions),
 | 
								Lang::Viewer(lng_manage_peer_recent_actions),
 | 
				
			||||||
 | 
								rpl::single(QString()), //Empty count.
 | 
				
			||||||
			[=] { ShowRecentActions(navigation, channel); },
 | 
								[=] { ShowRecentActions(navigation, channel); },
 | 
				
			||||||
			st::infoIconRecentActions);
 | 
								st::infoIconRecentActions);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -341,8 +317,6 @@ private:
 | 
				
			||||||
	void deleteWithConfirmation();
 | 
						void deleteWithConfirmation();
 | 
				
			||||||
	void deleteChannel();
 | 
						void deleteChannel();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void refreshHistoryVisibility(bool instant = false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	std::optional<Saving> validate() const;
 | 
						std::optional<Saving> validate() const;
 | 
				
			||||||
	bool validateUsername(Saving &to) const;
 | 
						bool validateUsername(Saving &to) const;
 | 
				
			||||||
	bool validateTitle(Saving &to) const;
 | 
						bool validateTitle(Saving &to) const;
 | 
				
			||||||
| 
						 | 
					@ -573,6 +547,15 @@ object_ptr<Ui::RpWidget> Controller::createPrivaciesButtons() {
 | 
				
			||||||
		return nullptr;
 | 
							return nullptr;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const auto refreshHistoryVisibility = [=](bool instant = false) {
 | 
				
			||||||
 | 
							if (!_controls.historyVisibilityWrap) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							_controls.historyVisibilityWrap->toggle(
 | 
				
			||||||
 | 
								_controls.privacySavedValue == Privacy::Private,
 | 
				
			||||||
 | 
								instant ? anim::type::instant : anim::type::normal);
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto channel = _peer->asChannel();
 | 
						const auto channel = _peer->asChannel();
 | 
				
			||||||
	auto isRealChannel = !(!channel || !channel->canEditSignatures() || channel->isMegagroup());
 | 
						auto isRealChannel = !(!channel || !channel->canEditSignatures() || channel->isMegagroup());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -597,7 +580,7 @@ object_ptr<Ui::RpWidget> Controller::createPrivaciesButtons() {
 | 
				
			||||||
		refreshHistoryVisibility();
 | 
							refreshHistoryVisibility();
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	const auto buttonCallback = [=]{ 
 | 
						const auto buttonCallback = [=]{ 
 | 
				
			||||||
		Ui::show(Box<EditPeerGroupTypeBox>(
 | 
							Ui::show(Box<EditPeerTypeBox>(
 | 
				
			||||||
			_peer,
 | 
								_peer,
 | 
				
			||||||
			boxCallback,
 | 
								boxCallback,
 | 
				
			||||||
			_controls.privacySavedValue,
 | 
								_controls.privacySavedValue,
 | 
				
			||||||
| 
						 | 
					@ -696,25 +679,12 @@ object_ptr<Ui::RpWidget> Controller::createManageGroupButtons() {
 | 
				
			||||||
		st::editPeerBottomButtonsLayoutMargins);
 | 
							st::editPeerBottomButtonsLayoutMargins);
 | 
				
			||||||
	auto container = result->entity();
 | 
						auto container = result->entity();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (const auto chat = _peer->asChat()) {
 | 
						FillManageSection(App::wnd()->controller(), _peer, container);
 | 
				
			||||||
		FillManageChatBox(App::wnd()->controller(), chat, container);
 | 
					 | 
				
			||||||
	} else if (const auto channel = _peer->asChannel()) {
 | 
					 | 
				
			||||||
		FillManageChannelBox(App::wnd()->controller(), channel, container);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// setDimensionsToContent(st::boxWidth, content);
 | 
						// setDimensionsToContent(st::boxWidth, content);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return std::move(result);
 | 
						return std::move(result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Controller::refreshHistoryVisibility(bool instant) {
 | 
					 | 
				
			||||||
	if (!_controls.historyVisibilityWrap) {
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	_controls.historyVisibilityWrap->toggle(
 | 
					 | 
				
			||||||
		_controls.privacySavedValue == Privacy::Private,
 | 
					 | 
				
			||||||
		instant ? anim::type::instant : anim::type::normal);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
 | 
					object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
 | 
				
			||||||
	Expects(_wrap != nullptr);
 | 
						Expects(_wrap != nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1160,3 +1130,65 @@ void EditPeerInfoBox::prepare() {
 | 
				
			||||||
		this,
 | 
							this,
 | 
				
			||||||
		std::move(content)));
 | 
							std::move(content)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Info::Profile::Button *EditPeerInfoBox::CreateButton(
 | 
				
			||||||
 | 
							not_null<Ui::VerticalLayout*> parent,
 | 
				
			||||||
 | 
							rpl::producer<QString> &&text,
 | 
				
			||||||
 | 
							rpl::producer<QString> &&count,
 | 
				
			||||||
 | 
							Fn<void()> callback,
 | 
				
			||||||
 | 
							const style::InfoProfileCountButton &st,
 | 
				
			||||||
 | 
							const style::icon *icon) {
 | 
				
			||||||
 | 
						const auto button = parent->add(
 | 
				
			||||||
 | 
							object_ptr<Info::Profile::Button>(
 | 
				
			||||||
 | 
								parent,
 | 
				
			||||||
 | 
								std::move(text),
 | 
				
			||||||
 | 
								st.button));
 | 
				
			||||||
 | 
						button->addClickHandler(callback);
 | 
				
			||||||
 | 
						if (icon) {
 | 
				
			||||||
 | 
							Ui::CreateChild<Info::Profile::FloatingIcon>(
 | 
				
			||||||
 | 
								button,
 | 
				
			||||||
 | 
								*icon,
 | 
				
			||||||
 | 
								st.iconPosition);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						const auto label = Ui::CreateChild<Ui::FlatLabel>(
 | 
				
			||||||
 | 
							button,
 | 
				
			||||||
 | 
							std::move(count),
 | 
				
			||||||
 | 
							st.label);
 | 
				
			||||||
 | 
						label->setAttribute(Qt::WA_TransparentForMouseEvents);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rpl::combine(
 | 
				
			||||||
 | 
							button->widthValue(),
 | 
				
			||||||
 | 
							label->widthValue()
 | 
				
			||||||
 | 
						) | rpl::start_with_next([=, &st](int outerWidth, int width) {
 | 
				
			||||||
 | 
							label->moveToRight(
 | 
				
			||||||
 | 
								st.labelPosition.x(),
 | 
				
			||||||
 | 
								st.labelPosition.y(),
 | 
				
			||||||
 | 
								outerWidth);
 | 
				
			||||||
 | 
						}, label->lifetime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return button;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool EditPeerInfoBox::Available(not_null<PeerData*> peer) {
 | 
				
			||||||
 | 
						if (const auto chat = peer->asChat()) {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
								|| chat->canEditInformation()
 | 
				
			||||||
 | 
								|| chat->canEditPermissions();
 | 
				
			||||||
 | 
						} else if (const auto channel = peer->asChannel()) {
 | 
				
			||||||
 | 
							// canViewMembers() is removed, because in supergroups you
 | 
				
			||||||
 | 
							// see them in profile and in channels only admins can see them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// canViewAdmins() is removed, because in supergroups it is
 | 
				
			||||||
 | 
							// always true and in channels it is equal to canViewBanned().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
								//|| channel->canViewMembers()
 | 
				
			||||||
 | 
								//|| channel->canViewAdmins()
 | 
				
			||||||
 | 
								|| channel->canViewBanned()
 | 
				
			||||||
 | 
								|| channel->canEditInformation()
 | 
				
			||||||
 | 
								|| channel->canEditPermissions()
 | 
				
			||||||
 | 
								|| HasRecentActions(channel);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <rpl/event_stream.h>
 | 
					#include <rpl/event_stream.h>
 | 
				
			||||||
#include "boxes/peers/manage_peer_box.h"
 | 
					#include "boxes/abstract_box.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace style {
 | 
				
			||||||
 | 
					struct InfoProfileCountButton;
 | 
				
			||||||
 | 
					} // namespace style
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui {
 | 
				
			||||||
 | 
					class VerticalLayout;
 | 
				
			||||||
 | 
					} // namespace Ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Info {
 | 
				
			||||||
 | 
					namespace Profile {
 | 
				
			||||||
 | 
					class Button;
 | 
				
			||||||
 | 
					} // namespace Profile
 | 
				
			||||||
 | 
					} // namespace Info
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EditPeerInfoBox : public BoxContent {
 | 
					class EditPeerInfoBox : public BoxContent {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
| 
						 | 
					@ -18,6 +32,16 @@ public:
 | 
				
			||||||
		_focusRequests.fire({});
 | 
							_focusRequests.fire({});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static bool Available(not_null<PeerData*> peer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static Info::Profile::Button *CreateButton(
 | 
				
			||||||
 | 
							not_null<Ui::VerticalLayout*> parent,
 | 
				
			||||||
 | 
							rpl::producer<QString> &&text,
 | 
				
			||||||
 | 
							rpl::producer<QString> &&count,
 | 
				
			||||||
 | 
							Fn<void()> callback,
 | 
				
			||||||
 | 
							const style::InfoProfileCountButton &st,
 | 
				
			||||||
 | 
							const style::icon *icon = nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
	void prepare() override;
 | 
						void prepare() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "info/profile/info_profile_icon.h"
 | 
					#include "info/profile/info_profile_icon.h"
 | 
				
			||||||
#include "info/profile/info_profile_values.h"
 | 
					#include "info/profile/info_profile_values.h"
 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					#include "boxes/peers/edit_participants_box.h"
 | 
				
			||||||
#include "boxes/peers/manage_peer_box.h"
 | 
					#include "boxes/peers/edit_peer_info_box.h"
 | 
				
			||||||
#include "window/window_controller.h"
 | 
					#include "window/window_controller.h"
 | 
				
			||||||
#include "mainwindow.h"
 | 
					#include "mainwindow.h"
 | 
				
			||||||
#include "styles/style_boxes.h"
 | 
					#include "styles/style_boxes.h"
 | 
				
			||||||
| 
						 | 
					@ -357,7 +357,7 @@ void EditPeerPermissionsBox::addBannedButtons(
 | 
				
			||||||
		{ 0, st::infoProfileSkip, 0, st::infoProfileSkip });
 | 
							{ 0, st::infoProfileSkip, 0, st::infoProfileSkip });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto navigation = App::wnd()->controller();
 | 
						const auto navigation = App::wnd()->controller();
 | 
				
			||||||
	ManagePeerBox::CreateButton(
 | 
						EditPeerInfoBox::CreateButton(
 | 
				
			||||||
		container,
 | 
							container,
 | 
				
			||||||
		Lang::Viewer(lng_manage_peer_exceptions),
 | 
							Lang::Viewer(lng_manage_peer_exceptions),
 | 
				
			||||||
		(channel
 | 
							(channel
 | 
				
			||||||
| 
						 | 
					@ -371,7 +371,7 @@ void EditPeerPermissionsBox::addBannedButtons(
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		st::peerPermissionsButton);
 | 
							st::peerPermissionsButton);
 | 
				
			||||||
	if (channel) {
 | 
						if (channel) {
 | 
				
			||||||
		ManagePeerBox::CreateButton(
 | 
							EditPeerInfoBox::CreateButton(
 | 
				
			||||||
			container,
 | 
								container,
 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_removed_users),
 | 
								Lang::Viewer(lng_manage_peer_removed_users),
 | 
				
			||||||
			Info::Profile::KickedCountValue(channel)
 | 
								Info::Profile::KickedCountValue(channel)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
 | 
				
			||||||
For license and copyright information please follow this link:
 | 
					For license and copyright information please follow this link:
 | 
				
			||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
#include "boxes/peers/edit_peer_group_type_box.h"
 | 
					#include "boxes/peers/edit_peer_type_box.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "apiwrap.h"
 | 
					#include "apiwrap.h"
 | 
				
			||||||
#include "apiwrap.h"
 | 
					#include "apiwrap.h"
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					#include "boxes/peers/edit_participants_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					#include "boxes/peers/edit_participants_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					#include "boxes/peers/edit_participants_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_group_type_box.h"
 | 
					#include "boxes/peers/edit_peer_type_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_history_visibility_box.h"
 | 
					#include "boxes/peers/edit_peer_history_visibility_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_info_box.h"
 | 
					#include "boxes/peers/edit_peer_info_box.h"
 | 
				
			||||||
#include "boxes/peers/edit_peer_permissions_box.h"
 | 
					#include "boxes/peers/edit_peer_permissions_box.h"
 | 
				
			||||||
| 
						 | 
					@ -754,7 +754,7 @@ void Controller::refreshCreateInviteLink() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace
 | 
					} // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EditPeerGroupTypeBox::EditPeerGroupTypeBox(
 | 
					EditPeerTypeBox::EditPeerTypeBox(
 | 
				
			||||||
		QWidget*,
 | 
							QWidget*,
 | 
				
			||||||
		not_null<PeerData*> p,
 | 
							not_null<PeerData*> p,
 | 
				
			||||||
		FnMut<void(Privacy, QString)> savedCallback,
 | 
							FnMut<void(Privacy, QString)> savedCallback,
 | 
				
			||||||
| 
						 | 
					@ -768,7 +768,7 @@ EditPeerGroupTypeBox::EditPeerGroupTypeBox(
 | 
				
			||||||
	allowSave = !usernameSaved->isEmpty() && usernameSaved.has_value();
 | 
						allowSave = !usernameSaved->isEmpty() && usernameSaved.has_value();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditPeerGroupTypeBox::prepare() {
 | 
					void EditPeerTypeBox::prepare() {
 | 
				
			||||||
	_peer->updateFull();
 | 
						_peer->updateFull();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setTitle(langFactory((peer->isChat() || peer->isMegagroup())
 | 
						setTitle(langFactory((peer->isChat() || peer->isMegagroup())
 | 
				
			||||||
| 
						 | 
					@ -794,7 +794,7 @@ void EditPeerGroupTypeBox::prepare() {
 | 
				
			||||||
	setupContent();
 | 
						setupContent();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EditPeerGroupTypeBox::setupContent() {
 | 
					void EditPeerTypeBox::setupContent() {
 | 
				
			||||||
	isGroup = (_peer->isChat() || _peer->isMegagroup());
 | 
						isGroup = (_peer->isChat() || _peer->isMegagroup());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
 | 
						const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
 | 
				
			||||||
| 
						 | 
					@ -35,10 +35,10 @@ enum class UsernameState {
 | 
				
			||||||
	NotAvailable,
 | 
						NotAvailable,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EditPeerGroupTypeBox : public BoxContent {
 | 
					class EditPeerTypeBox : public BoxContent {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	EditPeerGroupTypeBox(
 | 
						EditPeerTypeBox(
 | 
				
			||||||
		QWidget*,
 | 
							QWidget*,
 | 
				
			||||||
		not_null<PeerData*> p,
 | 
							not_null<PeerData*> p,
 | 
				
			||||||
		FnMut<void(Privacy, QString)> savedCallback,
 | 
							FnMut<void(Privacy, QString)> savedCallback,
 | 
				
			||||||
| 
						 | 
					@ -1,322 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
This file is part of Telegram Desktop,
 | 
					 | 
				
			||||||
the official desktop application for the Telegram messaging service.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
For license and copyright information please follow this link:
 | 
					 | 
				
			||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
#include "boxes/peers/manage_peer_box.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <rpl/combine.h>
 | 
					 | 
				
			||||||
#include "lang/lang_keys.h"
 | 
					 | 
				
			||||||
#include "boxes/peers/edit_peer_info_box.h"
 | 
					 | 
				
			||||||
#include "boxes/peers/edit_peer_permissions_box.h"
 | 
					 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					 | 
				
			||||||
#include "ui/wrap/vertical_layout.h"
 | 
					 | 
				
			||||||
#include "ui/widgets/labels.h"
 | 
					 | 
				
			||||||
#include "history/admin_log/history_admin_log_section.h"
 | 
					 | 
				
			||||||
#include "window/window_controller.h"
 | 
					 | 
				
			||||||
#include "info/profile/info_profile_button.h"
 | 
					 | 
				
			||||||
#include "info/profile/info_profile_icon.h"
 | 
					 | 
				
			||||||
#include "info/profile/info_profile_values.h"
 | 
					 | 
				
			||||||
#include "data/data_channel.h"
 | 
					 | 
				
			||||||
#include "data/data_chat.h"
 | 
					 | 
				
			||||||
#include "mainwindow.h"
 | 
					 | 
				
			||||||
#include "auth_session.h"
 | 
					 | 
				
			||||||
#include "apiwrap.h"
 | 
					 | 
				
			||||||
#include "styles/style_boxes.h"
 | 
					 | 
				
			||||||
#include "styles/style_info.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Fn<QString()> ManagePeerTitle(not_null<PeerData*> peer) {
 | 
					 | 
				
			||||||
	return langFactory((peer->isChat() || peer->isMegagroup())
 | 
					 | 
				
			||||||
		? lng_manage_group_title
 | 
					 | 
				
			||||||
		: lng_manage_channel_title);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
auto ToPositiveNumberString() {
 | 
					 | 
				
			||||||
	return rpl::map([](int count) {
 | 
					 | 
				
			||||||
		return count ? QString::number(count) : QString();
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Info::Profile::Button *AddButton(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
					 | 
				
			||||||
		Fn<void()> callback,
 | 
					 | 
				
			||||||
		const style::icon &icon) {
 | 
					 | 
				
			||||||
	return ManagePeerBox::CreateButton(
 | 
					 | 
				
			||||||
		parent,
 | 
					 | 
				
			||||||
		std::move(text),
 | 
					 | 
				
			||||||
		rpl::single(QString()),
 | 
					 | 
				
			||||||
		std::move(callback),
 | 
					 | 
				
			||||||
		st::managePeerButton,
 | 
					 | 
				
			||||||
		&icon);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AddButtonWithCount(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&count,
 | 
					 | 
				
			||||||
		Fn<void()> callback,
 | 
					 | 
				
			||||||
		const style::icon &icon) {
 | 
					 | 
				
			||||||
	ManagePeerBox::CreateButton(
 | 
					 | 
				
			||||||
		parent,
 | 
					 | 
				
			||||||
		std::move(text),
 | 
					 | 
				
			||||||
		std::move(count),
 | 
					 | 
				
			||||||
		std::move(callback),
 | 
					 | 
				
			||||||
		st::managePeerButton,
 | 
					 | 
				
			||||||
		&icon);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool HasRecentActions(not_null<ChannelData*> channel) {
 | 
					 | 
				
			||||||
	return channel->hasAdminRights() || channel->amCreator();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ShowRecentActions(
 | 
					 | 
				
			||||||
		not_null<Window::Navigation*> navigation,
 | 
					 | 
				
			||||||
		not_null<ChannelData*> channel) {
 | 
					 | 
				
			||||||
	navigation->showSection(AdminLog::SectionMemento(channel));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool HasEditInfoBox(not_null<PeerData*> peer) {
 | 
					 | 
				
			||||||
	if (const auto chat = peer->asChat()) {
 | 
					 | 
				
			||||||
		if (chat->canEditInformation()) {
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else if (const auto channel = peer->asChannel()) {
 | 
					 | 
				
			||||||
		if (channel->canEditInformation()) {
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		} else if (!channel->isPublic() && channel->canAddMembers()) {
 | 
					 | 
				
			||||||
			// Edit invite link.
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ShowEditPermissions(not_null<PeerData*> peer) {
 | 
					 | 
				
			||||||
	const auto box = Ui::show(
 | 
					 | 
				
			||||||
		Box<EditPeerPermissionsBox>(peer),
 | 
					 | 
				
			||||||
		LayerOption::KeepOther);
 | 
					 | 
				
			||||||
	box->saveEvents(
 | 
					 | 
				
			||||||
	) | rpl::start_with_next([=](MTPDchatBannedRights::Flags restrictions) {
 | 
					 | 
				
			||||||
		const auto callback = crl::guard(box, [=](bool success) {
 | 
					 | 
				
			||||||
			if (success) {
 | 
					 | 
				
			||||||
				box->closeBox();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
		peer->session().api().saveDefaultRestrictions(
 | 
					 | 
				
			||||||
			peer->migrateToOrMe(),
 | 
					 | 
				
			||||||
			MTP_chatBannedRights(MTP_flags(restrictions), MTP_int(0)),
 | 
					 | 
				
			||||||
			callback);
 | 
					 | 
				
			||||||
	}, box->lifetime());
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void FillManageChatBox(
 | 
					 | 
				
			||||||
		not_null<Window::Navigation*> navigation,
 | 
					 | 
				
			||||||
		not_null<ChatData*> chat,
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> content) {
 | 
					 | 
				
			||||||
	if (HasEditInfoBox(chat)) {
 | 
					 | 
				
			||||||
		AddButton(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_group_info),
 | 
					 | 
				
			||||||
			[=] { Ui::show(Box<EditPeerInfoBox>(chat)); },
 | 
					 | 
				
			||||||
			st::infoIconInformation);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (chat->canEditPermissions()) {
 | 
					 | 
				
			||||||
		AddButton(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_permissions),
 | 
					 | 
				
			||||||
			[=] { ShowEditPermissions(chat); },
 | 
					 | 
				
			||||||
			st::infoIconPermissions);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (chat->amIn()) {
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_administrators),
 | 
					 | 
				
			||||||
			Info::Profile::AdminsCountValue(chat)
 | 
					 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					chat,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Admins);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconAdministrators);
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_members),
 | 
					 | 
				
			||||||
			Info::Profile::MembersCountValue(chat)
 | 
					 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					chat,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Members);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconMembers);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void FillManageChannelBox(
 | 
					 | 
				
			||||||
		not_null<Window::Navigation*> navigation,
 | 
					 | 
				
			||||||
		not_null<ChannelData*> channel,
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> content) {
 | 
					 | 
				
			||||||
	auto isGroup = channel->isMegagroup();
 | 
					 | 
				
			||||||
	if (HasEditInfoBox(channel)) {
 | 
					 | 
				
			||||||
		AddButton(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(isGroup
 | 
					 | 
				
			||||||
				? lng_manage_group_info
 | 
					 | 
				
			||||||
				: lng_manage_channel_info),
 | 
					 | 
				
			||||||
			[=] { Ui::show(Box<EditPeerInfoBox>(channel)); },
 | 
					 | 
				
			||||||
			st::infoIconInformation);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (HasRecentActions(channel)) {
 | 
					 | 
				
			||||||
		AddButton(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_recent_actions),
 | 
					 | 
				
			||||||
			[=] { ShowRecentActions(navigation, channel); },
 | 
					 | 
				
			||||||
			st::infoIconRecentActions);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (channel->canEditPermissions()) {
 | 
					 | 
				
			||||||
		AddButton(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_permissions),
 | 
					 | 
				
			||||||
			[=] { ShowEditPermissions(channel); },
 | 
					 | 
				
			||||||
			st::infoIconPermissions);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (channel->canViewAdmins()) {
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_administrators),
 | 
					 | 
				
			||||||
			Info::Profile::AdminsCountValue(channel)
 | 
					 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					channel,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Admins);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconAdministrators);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (channel->canViewMembers()) {
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_members),
 | 
					 | 
				
			||||||
			Info::Profile::MembersCountValue(channel)
 | 
					 | 
				
			||||||
				| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					channel,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Members);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconMembers);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (!channel->isMegagroup()) {
 | 
					 | 
				
			||||||
		AddButtonWithCount(
 | 
					 | 
				
			||||||
			content,
 | 
					 | 
				
			||||||
			Lang::Viewer(lng_manage_peer_removed_users),
 | 
					 | 
				
			||||||
			Info::Profile::KickedCountValue(channel)
 | 
					 | 
				
			||||||
			| ToPositiveNumberString(),
 | 
					 | 
				
			||||||
			[=] {
 | 
					 | 
				
			||||||
				ParticipantsBoxController::Start(
 | 
					 | 
				
			||||||
					navigation,
 | 
					 | 
				
			||||||
					channel,
 | 
					 | 
				
			||||||
					ParticipantsBoxController::Role::Kicked);
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			st::infoIconBlacklist);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
} // namespace
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ManagePeerBox::ManagePeerBox(
 | 
					 | 
				
			||||||
	QWidget*,
 | 
					 | 
				
			||||||
	not_null<PeerData*> peer)
 | 
					 | 
				
			||||||
: _peer(peer) {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool ManagePeerBox::Available(not_null<PeerData*> peer) {
 | 
					 | 
				
			||||||
	if (const auto chat = peer->asChat()) {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
			|| chat->canEditInformation()
 | 
					 | 
				
			||||||
			|| chat->canEditPermissions();
 | 
					 | 
				
			||||||
	} else if (const auto channel = peer->asChannel()) {
 | 
					 | 
				
			||||||
		// canViewMembers() is removed, because in supergroups you
 | 
					 | 
				
			||||||
		// see them in profile and in channels only admins can see them.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// canViewAdmins() is removed, because in supergroups it is
 | 
					 | 
				
			||||||
		// always true and in channels it is equal to canViewBanned().
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
			//|| channel->canViewMembers()
 | 
					 | 
				
			||||||
			//|| channel->canViewAdmins()
 | 
					 | 
				
			||||||
			|| channel->canViewBanned()
 | 
					 | 
				
			||||||
			|| channel->canEditInformation()
 | 
					 | 
				
			||||||
			|| channel->canEditPermissions()
 | 
					 | 
				
			||||||
			|| HasRecentActions(channel);
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Info::Profile::Button *ManagePeerBox::CreateButton(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&count,
 | 
					 | 
				
			||||||
		Fn<void()> callback,
 | 
					 | 
				
			||||||
		const style::InfoProfileCountButton &st,
 | 
					 | 
				
			||||||
		const style::icon *icon) {
 | 
					 | 
				
			||||||
	const auto button = parent->add(
 | 
					 | 
				
			||||||
		object_ptr<Info::Profile::Button>(
 | 
					 | 
				
			||||||
			parent,
 | 
					 | 
				
			||||||
			std::move(text),
 | 
					 | 
				
			||||||
			st.button));
 | 
					 | 
				
			||||||
	button->addClickHandler(callback);
 | 
					 | 
				
			||||||
	if (icon) {
 | 
					 | 
				
			||||||
		Ui::CreateChild<Info::Profile::FloatingIcon>(
 | 
					 | 
				
			||||||
			button,
 | 
					 | 
				
			||||||
			*icon,
 | 
					 | 
				
			||||||
			st.iconPosition);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	const auto label = Ui::CreateChild<Ui::FlatLabel>(
 | 
					 | 
				
			||||||
		button,
 | 
					 | 
				
			||||||
		std::move(count),
 | 
					 | 
				
			||||||
		st.label);
 | 
					 | 
				
			||||||
	label->setAttribute(Qt::WA_TransparentForMouseEvents);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rpl::combine(
 | 
					 | 
				
			||||||
		button->widthValue(),
 | 
					 | 
				
			||||||
		label->widthValue()
 | 
					 | 
				
			||||||
	) | rpl::start_with_next([=, &st](int outerWidth, int width) {
 | 
					 | 
				
			||||||
		label->moveToRight(
 | 
					 | 
				
			||||||
			st.labelPosition.x(),
 | 
					 | 
				
			||||||
			st.labelPosition.y(),
 | 
					 | 
				
			||||||
			outerWidth);
 | 
					 | 
				
			||||||
	}, label->lifetime());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return button;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ManagePeerBox::prepare() {
 | 
					 | 
				
			||||||
	_peer->updateFull();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	setTitle(ManagePeerTitle(_peer));
 | 
					 | 
				
			||||||
	addButton(langFactory(lng_cancel), [=] { closeBox(); });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	setupContent();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ManagePeerBox::setupContent() {
 | 
					 | 
				
			||||||
	const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
 | 
					 | 
				
			||||||
	if (const auto chat = _peer->asChat()) {
 | 
					 | 
				
			||||||
		FillManageChatBox(App::wnd()->controller(), chat, content);
 | 
					 | 
				
			||||||
	} else if (const auto channel = _peer->asChannel()) {
 | 
					 | 
				
			||||||
		FillManageChannelBox(App::wnd()->controller(), channel, content);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	setDimensionsToContent(st::boxWidth, content);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,48 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
This file is part of Telegram Desktop,
 | 
					 | 
				
			||||||
the official desktop application for the Telegram messaging service.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
For license and copyright information please follow this link:
 | 
					 | 
				
			||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
#pragma once
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "boxes/abstract_box.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace style {
 | 
					 | 
				
			||||||
struct InfoProfileCountButton;
 | 
					 | 
				
			||||||
} // namespace style
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace Ui {
 | 
					 | 
				
			||||||
class VerticalLayout;
 | 
					 | 
				
			||||||
} // namespace Ui
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace Info {
 | 
					 | 
				
			||||||
namespace Profile {
 | 
					 | 
				
			||||||
class Button;
 | 
					 | 
				
			||||||
} // namespace Profile
 | 
					 | 
				
			||||||
} // namespace Info
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ManagePeerBox : public BoxContent {
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
	ManagePeerBox(QWidget*, not_null<PeerData*> peer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	static bool Available(not_null<PeerData*> peer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	static Info::Profile::Button *CreateButton(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&text,
 | 
					 | 
				
			||||||
		rpl::producer<QString> &&count,
 | 
					 | 
				
			||||||
		Fn<void()> callback,
 | 
					 | 
				
			||||||
		const style::InfoProfileCountButton &st,
 | 
					 | 
				
			||||||
		const style::icon *icon = nullptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
protected:
 | 
					 | 
				
			||||||
	void prepare() override;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
	void setupContent();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	not_null<PeerData*> _peer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "boxes/report_box.h"
 | 
					#include "boxes/report_box.h"
 | 
				
			||||||
#include "boxes/create_poll_box.h"
 | 
					#include "boxes/create_poll_box.h"
 | 
				
			||||||
#include "boxes/peers/add_participants_box.h"
 | 
					#include "boxes/peers/add_participants_box.h"
 | 
				
			||||||
#include "boxes/peers/manage_peer_box.h"
 | 
					 | 
				
			||||||
#include "ui/toast/toast.h"
 | 
					#include "ui/toast/toast.h"
 | 
				
			||||||
#include "auth_session.h"
 | 
					#include "auth_session.h"
 | 
				
			||||||
#include "apiwrap.h"
 | 
					#include "apiwrap.h"
 | 
				
			||||||
| 
						 | 
					@ -37,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "data/data_drafts.h"
 | 
					#include "data/data_drafts.h"
 | 
				
			||||||
#include "data/data_user.h"
 | 
					#include "data/data_user.h"
 | 
				
			||||||
#include "dialogs/dialogs_key.h"
 | 
					#include "dialogs/dialogs_key.h"
 | 
				
			||||||
 | 
					#include "boxes/peers/edit_peer_info_box.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Window {
 | 
					namespace Window {
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
| 
						 | 
					@ -354,7 +354,7 @@ void Filler::addUserActions(not_null<UserData*> user) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Filler::addChatActions(not_null<ChatData*> chat) {
 | 
					void Filler::addChatActions(not_null<ChatData*> chat) {
 | 
				
			||||||
	if (_source != PeerMenuSource::ChatsList) {
 | 
						if (_source != PeerMenuSource::ChatsList) {
 | 
				
			||||||
		if (ManagePeerBox::Available(chat)) {
 | 
							if (EditPeerInfoBox::Available(chat)) {
 | 
				
			||||||
			const auto text = lang(lng_manage_group_title);
 | 
								const auto text = lang(lng_manage_group_title);
 | 
				
			||||||
			_addAction(text, [=] {
 | 
								_addAction(text, [=] {
 | 
				
			||||||
				App::wnd()->controller()->showEditPeerBox(chat);
 | 
									App::wnd()->controller()->showEditPeerBox(chat);
 | 
				
			||||||
| 
						 | 
					@ -396,7 +396,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (_source != PeerMenuSource::ChatsList) {
 | 
						if (_source != PeerMenuSource::ChatsList) {
 | 
				
			||||||
		if (ManagePeerBox::Available(channel)) {
 | 
							if (EditPeerInfoBox::Available(channel)) {
 | 
				
			||||||
			const auto text = lang(isGroup
 | 
								const auto text = lang(isGroup
 | 
				
			||||||
				? lng_manage_group_title
 | 
									? lng_manage_group_title
 | 
				
			||||||
				: lng_manage_channel_title);
 | 
									: lng_manage_channel_title);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,14 +6,12 @@
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_participants_box.h
 | 
					<(src_loc)/boxes/peers/edit_participants_box.h
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_info_box.cpp
 | 
					<(src_loc)/boxes/peers/edit_peer_info_box.cpp
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_info_box.h
 | 
					<(src_loc)/boxes/peers/edit_peer_info_box.h
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_group_type_box.cpp
 | 
					<(src_loc)/boxes/peers/edit_peer_type_box.cpp
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_group_type_box.h
 | 
					<(src_loc)/boxes/peers/edit_peer_type_box.h
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_history_visibility_box.cpp
 | 
					<(src_loc)/boxes/peers/edit_peer_history_visibility_box.cpp
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_history_visibility_box.h
 | 
					<(src_loc)/boxes/peers/edit_peer_history_visibility_box.h
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_permissions_box.cpp
 | 
					<(src_loc)/boxes/peers/edit_peer_permissions_box.cpp
 | 
				
			||||||
<(src_loc)/boxes/peers/edit_peer_permissions_box.h
 | 
					<(src_loc)/boxes/peers/edit_peer_permissions_box.h
 | 
				
			||||||
<(src_loc)/boxes/peers/manage_peer_box.cpp
 | 
					 | 
				
			||||||
<(src_loc)/boxes/peers/manage_peer_box.h
 | 
					 | 
				
			||||||
<(src_loc)/boxes/about_box.cpp
 | 
					<(src_loc)/boxes/about_box.cpp
 | 
				
			||||||
<(src_loc)/boxes/about_box.h
 | 
					<(src_loc)/boxes/about_box.h
 | 
				
			||||||
<(src_loc)/boxes/abstract_box.cpp
 | 
					<(src_loc)/boxes/abstract_box.cpp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue