Begin of EditPeerBox redesigning.
- Moved buttons from ManageGroupBox to EditPeerBox. - Added counting of permissions.
This commit is contained in:
		
							parent
							
								
									3a5bad4b7a
								
							
						
					
					
						commit
						0f3ec47074
					
				
					 9 changed files with 442 additions and 16 deletions
				
			
		|  | @ -803,6 +803,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| "lng_manage_peer_exceptions" = "Exceptions"; | "lng_manage_peer_exceptions" = "Exceptions"; | ||||||
| "lng_manage_peer_removed_users" = "Removed users"; | "lng_manage_peer_removed_users" = "Removed users"; | ||||||
| "lng_manage_peer_permissions" = "Permissions"; | "lng_manage_peer_permissions" = "Permissions"; | ||||||
|  | 
 | ||||||
|  | "lng_manage_peer_group_type" = "Group type"; | ||||||
|  | "lng_manage_private_group_title" = "Private"; | ||||||
|  | 
 | ||||||
| "lng_manage_history_visibility_title" = "Chat history for new members"; | "lng_manage_history_visibility_title" = "Chat history for new members"; | ||||||
| "lng_manage_history_visibility_shown" = "Visible"; | "lng_manage_history_visibility_shown" = "Visible"; | ||||||
| "lng_manage_history_visibility_shown_about" = "New members will see messages that were sent before they joined."; | "lng_manage_history_visibility_shown_about" = "New members will see messages that were sent before they joined."; | ||||||
|  |  | ||||||
|  | @ -38,6 +38,237 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "styles/style_boxes.h" | #include "styles/style_boxes.h" | ||||||
| #include "styles/style_info.h" | #include "styles/style_info.h" | ||||||
| 
 | 
 | ||||||
|  | #include "ui/rp_widget.h" | ||||||
|  | #include "boxes/peers/edit_peer_permissions_box.h" | ||||||
|  | 
 | ||||||
|  | #include "info/profile/info_profile_button.h" | ||||||
|  | #include "info/profile/info_profile_icon.h" | ||||||
|  | #include "info/profile/info_profile_values.h" | ||||||
|  | 
 | ||||||
|  | #include "mainwindow.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(); | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | auto ToPositiveNumberStringRestrictions() { | ||||||
|  | 	return rpl::map([](int count) { | ||||||
|  | 		return QString::number(count) | ||||||
|  | 		+ QString("/") | ||||||
|  | 		+ QString::number(int(Data::ListOfRestrictions().size())); | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 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( | ||||||
|  | 		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::manageGroupButton, | ||||||
|  | 		&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 (chat->canEditPermissions()) { | ||||||
|  | 		AddButtonWithCount( | ||||||
|  | 			content, | ||||||
|  | 			Lang::Viewer(lng_manage_peer_permissions), | ||||||
|  | 			Info::Profile::RestrictionsCountValue(chat) | ||||||
|  | 				| ToPositiveNumberStringRestrictions(), | ||||||
|  | 			[=] { 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 (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); | ||||||
|  | 			}, | ||||||
|  | 			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); | ||||||
|  | 	} | ||||||
|  | 	if (HasRecentActions(channel)) { | ||||||
|  | 		AddButton( | ||||||
|  | 			content, | ||||||
|  | 			Lang::Viewer(lng_manage_peer_recent_actions), | ||||||
|  | 			[=] { ShowRecentActions(navigation, channel); }, | ||||||
|  | 			st::infoIconRecentActions); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } // namespace
 | ||||||
|  | 
 | ||||||
| namespace { | namespace { | ||||||
| 
 | 
 | ||||||
| constexpr auto kUsernameCheckTimeout = crl::time(200); | constexpr auto kUsernameCheckTimeout = crl::time(200); | ||||||
|  | @ -113,6 +344,9 @@ private: | ||||||
| 	object_ptr<Ui::RpWidget> createStickersEdit(); | 	object_ptr<Ui::RpWidget> createStickersEdit(); | ||||||
| 	object_ptr<Ui::RpWidget> createDeleteButton(); | 	object_ptr<Ui::RpWidget> createDeleteButton(); | ||||||
| 
 | 
 | ||||||
|  | 	object_ptr<Ui::RpWidget> createPrivaciesButtons(); | ||||||
|  | 	object_ptr<Ui::RpWidget> createManageGroupButtons(); | ||||||
|  | 
 | ||||||
| 	QString inviteLinkText() const; | 	QString inviteLinkText() const; | ||||||
| 	void observeInviteLink(); | 	void observeInviteLink(); | ||||||
| 
 | 
 | ||||||
|  | @ -221,8 +455,26 @@ object_ptr<Ui::VerticalLayout> Controller::createContent() { | ||||||
| 	_wrap.reset(result.data()); | 	_wrap.reset(result.data()); | ||||||
| 	_controls = Controls(); | 	_controls = Controls(); | ||||||
| 
 | 
 | ||||||
|  | 	const auto addSkip = [](not_null<Ui::VerticalLayout*> container) { | ||||||
|  | 		container->add(object_ptr<Ui::FixedHeightWidget>( | ||||||
|  | 			container, | ||||||
|  | 			7 /*Create skip in style.*/)); | ||||||
|  | 		container->add(object_ptr<BoxContentDivider>(container)); | ||||||
|  | 		/*container->add(object_ptr<Ui::FixedHeightWidget>(
 | ||||||
|  | 			container, | ||||||
|  | 			st::editPeerPrivacyTopSkip));*/ | ||||||
|  | 	}; | ||||||
|  | 
 | ||||||
| 	_wrap->add(createPhotoAndTitleEdit()); | 	_wrap->add(createPhotoAndTitleEdit()); | ||||||
| 	_wrap->add(createDescriptionEdit()); | 	_wrap->add(createDescriptionEdit()); | ||||||
|  | 
 | ||||||
|  | 	addSkip(_wrap); // Divider.
 | ||||||
|  | 	_wrap->add(createPrivaciesButtons()); | ||||||
|  | 	addSkip(_wrap); // Divider.
 | ||||||
|  | 
 | ||||||
|  | 	_wrap->add(createManageGroupButtons()); | ||||||
|  | 	addSkip(_wrap); // Divider.
 | ||||||
|  | 
 | ||||||
| 	_wrap->add(createPrivaciesEdit()); | 	_wrap->add(createPrivaciesEdit()); | ||||||
| 	_wrap->add(createInviteLinkCreate()); | 	_wrap->add(createInviteLinkCreate()); | ||||||
| 	_wrap->add(createInviteLinkEdit()); | 	_wrap->add(createInviteLinkEdit()); | ||||||
|  | @ -429,6 +681,99 @@ object_ptr<Ui::RpWidget> Controller::createPrivaciesEdit() { | ||||||
| 	return std::move(result); | 	return std::move(result); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | object_ptr<Ui::RpWidget> Controller::createPrivaciesButtons() { | ||||||
|  | 	Expects(_wrap != nullptr); | ||||||
|  | 
 | ||||||
|  | 	const auto canEditUsername = [&] { | ||||||
|  | 		if (const auto chat = _peer->asChat()) { | ||||||
|  | 			return chat->canEditUsername(); | ||||||
|  | 		} else if (const auto channel = _peer->asChannel()) { | ||||||
|  | 			return channel->canEditUsername(); | ||||||
|  | 		} | ||||||
|  | 		Unexpected("Peer type in Controller::createPrivaciesEdit."); | ||||||
|  | 	}(); | ||||||
|  | 	if (!canEditUsername) { | ||||||
|  | 		return nullptr; | ||||||
|  | 	} | ||||||
|  | 	auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>( | ||||||
|  | 		_wrap, | ||||||
|  | 		object_ptr<Ui::VerticalLayout>(_wrap), | ||||||
|  | 		st::editHehMargins); | ||||||
|  | 	auto container = result->entity(); | ||||||
|  | 
 | ||||||
|  | 	const auto addPrivaciesButton = [=, &container](LangKey privacyTextKey) { | ||||||
|  | 		const auto button = container->add(object_ptr<Info::Profile::Button>( | ||||||
|  | 			container, | ||||||
|  | 			std::move(Lang::Viewer(privacyTextKey)), | ||||||
|  | 			st::heeehButton | ||||||
|  | 		)); | ||||||
|  | 	}; | ||||||
|  | 
 | ||||||
|  | 	addPrivaciesButton(lng_manage_peer_group_type); | ||||||
|  | 	addPrivaciesButton(lng_manage_history_visibility_title); | ||||||
|  | 
 | ||||||
|  | 	// style::InfoProfileCountButton a = st::heehPermissionsButton;
 | ||||||
|  | 	// const auto name = Ui::CreateChild<Ui::FlatLabel>(
 | ||||||
|  | 	// 	button,
 | ||||||
|  | 	// 	std::move(rpl::single(QString("Heh"))),
 | ||||||
|  | 	// 	a.label);
 | ||||||
|  | 	// rpl::combine(
 | ||||||
|  | 	// 	button->widthValue(),
 | ||||||
|  | 	// 	std::move(rpl::single(QString("Heh"))),
 | ||||||
|  | 	// 	std::move(rpl::single(QString("Heh")))
 | ||||||
|  | 	// ) | rpl::start_with_next([=, &a](
 | ||||||
|  | 	// 		int width,
 | ||||||
|  | 	// 		const QString &button,
 | ||||||
|  | 	// 		const QString &text) {
 | ||||||
|  | 	// 	/*const auto available = width
 | ||||||
|  | 	// 		- a.padding.left()
 | ||||||
|  | 	// 		- a.padding.right()
 | ||||||
|  | 	// 		- a.font->width(button)
 | ||||||
|  | 	// 		- st::hehButtonRightSkip;
 | ||||||
|  | 	// 	name->setText(text);
 | ||||||
|  | 	// 	name->resizeToNaturalWidth(available);
 | ||||||
|  | 	// 	name->moveToRight(st::hehButtonRightSkip, st.padding.top());*/
 | ||||||
|  | 	// }, name->lifetime());
 | ||||||
|  | 	// name->setAttribute(Qt::WA_TransparentForMouseEvents);
 | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	// style::InfoProfileCountButton a = st::managePeerButton;
 | ||||||
|  | 	// const auto label = Ui::CreateChild<Ui::FlatLabel>(
 | ||||||
|  | 	// 	button,
 | ||||||
|  | 	// 	std::move(rpl::single(QString("5"))),
 | ||||||
|  | 	// 	a.label);
 | ||||||
|  | 	// label->setAttribute(Qt::WA_TransparentForMouseEvents);
 | ||||||
|  | 	// rpl::combine(
 | ||||||
|  | 	// 	button->widthValue(),
 | ||||||
|  | 	// 	label->widthValue()
 | ||||||
|  | 	// ) | rpl::start_with_next([=, &a](int outerWidth, int width) {
 | ||||||
|  | 	// 	LOG(("POSITION: %1 %2").arg(a.labelPosition.x()).arg(a.labelPosition.y()));
 | ||||||
|  | 	// 	label->moveToRight(0, 0);
 | ||||||
|  | 	// }, label->lifetime());
 | ||||||
|  | 
 | ||||||
|  | 	return std::move(result); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | object_ptr<Ui::RpWidget> Controller::createManageGroupButtons() { | ||||||
|  | 	Expects(_wrap != nullptr); | ||||||
|  | 
 | ||||||
|  | 	auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>( | ||||||
|  | 		_wrap, | ||||||
|  | 		object_ptr<Ui::VerticalLayout>(_wrap), | ||||||
|  | 		st::editHehMargins); | ||||||
|  | 	auto container = result->entity(); | ||||||
|  | 
 | ||||||
|  | 	if (const auto chat = _peer->asChat()) { | ||||||
|  | 		FillManageChatBox(App::wnd()->controller(), chat, container); | ||||||
|  | 	} else if (const auto channel = _peer->asChannel()) { | ||||||
|  | 		FillManageChannelBox(App::wnd()->controller(), channel, container); | ||||||
|  | 	} | ||||||
|  | 	// setDimensionsToContent(st::boxWidth, content);
 | ||||||
|  | 
 | ||||||
|  | 	return std::move(result); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| object_ptr<Ui::RpWidget> Controller::createUsernameEdit() { | object_ptr<Ui::RpWidget> Controller::createUsernameEdit() { | ||||||
| 	Expects(_wrap != nullptr); | 	Expects(_wrap != nullptr); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -80,21 +80,24 @@ void ApplyDependencies( | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<std::pair<ChatRestrictions, LangKey>> RestrictionLabels() { | std::vector<std::pair<ChatRestrictions, LangKey>> RestrictionLabels() { | ||||||
| 	using Flag = ChatRestriction; | 	const auto langKeys = { | ||||||
| 
 | 		lng_rights_chat_send_text, | ||||||
| 	return { | 		lng_rights_chat_send_media, | ||||||
| 		{ Flag::f_send_messages, lng_rights_chat_send_text }, | 		lng_rights_chat_send_stickers, | ||||||
| 		{ Flag::f_send_media, lng_rights_chat_send_media }, | 		lng_rights_chat_send_links, | ||||||
| 		{ Flag::f_send_stickers | 		lng_rights_chat_send_polls, | ||||||
| 		| Flag::f_send_gifs | 		lng_rights_chat_add_members, | ||||||
| 		| Flag::f_send_games | 		lng_rights_group_pin, | ||||||
| 		| Flag::f_send_inline, lng_rights_chat_send_stickers }, | 		lng_rights_group_info, | ||||||
| 		{ Flag::f_embed_links, lng_rights_chat_send_links }, |  | ||||||
| 		{ Flag::f_send_polls, lng_rights_chat_send_polls }, |  | ||||||
| 		{ Flag::f_invite_users, lng_rights_chat_add_members }, |  | ||||||
| 		{ Flag::f_pin_messages, lng_rights_group_pin }, |  | ||||||
| 		{ Flag::f_change_info, lng_rights_group_info }, |  | ||||||
| 	}; | 	}; | ||||||
|  | 
 | ||||||
|  | 	std::vector<std::pair<ChatRestrictions, LangKey>> vector; | ||||||
|  | 	const auto restrictions = Data::ListOfRestrictions(); | ||||||
|  | 	auto i = 0; | ||||||
|  | 	for (const auto key : langKeys) { | ||||||
|  | 		vector.push_back({restrictions[i++], key}); | ||||||
|  | 	} | ||||||
|  | 	return vector; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<std::pair<ChatAdminRights, LangKey>> AdminRightLabels( | std::vector<std::pair<ChatAdminRights, LangKey>> AdminRightLabels( | ||||||
|  |  | ||||||
|  | @ -644,6 +644,24 @@ Data::RestrictionCheckResult PeerData::amRestricted( | ||||||
| 
 | 
 | ||||||
| namespace Data { | namespace Data { | ||||||
| 
 | 
 | ||||||
|  | std::vector<ChatRestrictions> ListOfRestrictions() { | ||||||
|  | 	using Flag = ChatRestriction; | ||||||
|  | 
 | ||||||
|  | 	return { | ||||||
|  | 		Flag::f_send_messages, | ||||||
|  | 		Flag::f_send_media, | ||||||
|  | 		Flag::f_send_stickers | ||||||
|  | 		| Flag::f_send_gifs | ||||||
|  | 		| Flag::f_send_games | ||||||
|  | 		| Flag::f_send_inline, | ||||||
|  | 		Flag::f_embed_links, | ||||||
|  | 		Flag::f_send_polls, | ||||||
|  | 		Flag::f_invite_users, | ||||||
|  | 		Flag::f_pin_messages, | ||||||
|  | 		Flag::f_change_info, | ||||||
|  | 	}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| std::optional<LangKey> RestrictionErrorKey( | std::optional<LangKey> RestrictionErrorKey( | ||||||
| 		not_null<PeerData*> peer, | 		not_null<PeerData*> peer, | ||||||
| 		ChatRestriction restriction) { | 		ChatRestriction restriction) { | ||||||
|  |  | ||||||
|  | @ -338,6 +338,8 @@ private: | ||||||
| 
 | 
 | ||||||
| namespace Data { | namespace Data { | ||||||
| 
 | 
 | ||||||
|  | std::vector<ChatRestrictions> ListOfRestrictions(); | ||||||
|  | 
 | ||||||
| std::optional<LangKey> RestrictionErrorKey( | std::optional<LangKey> RestrictionErrorKey( | ||||||
| 	not_null<PeerData*> peer, | 	not_null<PeerData*> peer, | ||||||
| 	ChatRestriction restriction); | 	ChatRestriction restriction); | ||||||
|  |  | ||||||
|  | @ -597,6 +597,26 @@ peerPermissionsButton: InfoProfileCountButton(managePeerButton) { | ||||||
| 	iconPosition: point(24px, 5px); | 	iconPosition: point(24px, 5px); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | manageGroupButton: InfoProfileCountButton(managePeerButton) { | ||||||
|  | 	button: InfoProfileButton(infoProfileButton) { | ||||||
|  | 		padding: margins(72px, 12px, 24px, 10px); | ||||||
|  | 	} | ||||||
|  | 	iconPosition: point(20px, 5px); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | heeehButton: InfoProfileButton(infoProfileButton) { | ||||||
|  | 	font: boxTextFont; | ||||||
|  | 	padding: margins(23px, 10px, 22px, 11px); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | hehButtonRightSkip: 28px; | ||||||
|  | hehButtonRight: FlatLabel(defaultFlatLabel) { | ||||||
|  | 	textFg: windowActiveTextFg; | ||||||
|  | 	style: boxTextStyle; | ||||||
|  | 	maxHeight: 20px; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| terminateSessionsButton: InfoProfileButton(infoBlockButton) { | terminateSessionsButton: InfoProfileButton(infoBlockButton) { | ||||||
| 	padding: margins(23px, 12px, 23px, 10px); | 	padding: margins(23px, 12px, 23px, 10px); | ||||||
| } | } | ||||||
|  | @ -616,6 +636,8 @@ infoEmptyLabel: FlatLabel(defaultFlatLabel) { | ||||||
| 	textFg: windowSubTextFg; | 	textFg: windowSubTextFg; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | editHehMargins: margins(0px, 10px, 0px, 0px); | ||||||
|  | 
 | ||||||
| editPeerDeleteButtonMargins: margins(23px, 16px, 23px, 16px); | editPeerDeleteButtonMargins: margins(23px, 16px, 23px, 16px); | ||||||
| editPeerDeleteButton: sessionTerminateAllButton; | editPeerDeleteButton: sessionTerminateAllButton; | ||||||
| editPeerPhotoMargins: margins(23px, 16px, 23px, 8px); | editPeerPhotoMargins: margins(23px, 16px, 23px, 8px); | ||||||
|  |  | ||||||
|  | @ -23,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "data/data_user.h" | #include "data/data_user.h" | ||||||
| #include "data/data_session.h" | #include "data/data_session.h" | ||||||
| 
 | 
 | ||||||
|  | #include "boxes/peers/edit_peer_permissions_box.h" | ||||||
|  | 
 | ||||||
| namespace Info { | namespace Info { | ||||||
| namespace Profile { | namespace Profile { | ||||||
| 
 | 
 | ||||||
|  | @ -215,6 +217,35 @@ rpl::producer<int> AdminsCountValue(not_null<PeerData*> peer) { | ||||||
| 	Unexpected("User in AdminsCountValue()."); | 	Unexpected("User in AdminsCountValue()."); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | rpl::producer<int> RestrictionsCountValue(not_null<PeerData*> peer) { | ||||||
|  | 	const auto countOfRestrictions = [](ChatRestrictions restrictions) { | ||||||
|  | 		auto count = 0; | ||||||
|  | 		for (const auto f : Data::ListOfRestrictions()) { | ||||||
|  | 			if (restrictions & f) count++; | ||||||
|  | 		} | ||||||
|  | 		return int(Data::ListOfRestrictions().size()) - count; | ||||||
|  | 	}; | ||||||
|  | 
 | ||||||
|  | 	using Flag = Notify::PeerUpdate::Flag; | ||||||
|  | 	if (const auto chat = peer->asChat()) { | ||||||
|  | 		return Notify::PeerUpdateValue( | ||||||
|  | 			chat, | ||||||
|  | 			Flag::RightsChanged | ||||||
|  | 		) | rpl::map([=] { | ||||||
|  | 			return countOfRestrictions(chat->defaultRestrictions()); | ||||||
|  | 		}); | ||||||
|  | 	} else if (const auto channel = peer->asChannel()) { | ||||||
|  | 		return Notify::PeerUpdateValue( | ||||||
|  | 			channel, | ||||||
|  | 			Flag::RightsChanged | ||||||
|  | 		) | rpl::map([=] { | ||||||
|  | 			return countOfRestrictions(channel->defaultRestrictions()); | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  | 	Unexpected("User in RestrictionsCountValue()."); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| rpl::producer<int> RestrictedCountValue(not_null<ChannelData*> channel) { | rpl::producer<int> RestrictedCountValue(not_null<ChannelData*> channel) { | ||||||
| 	using Flag = Notify::PeerUpdate::Flag; | 	using Flag = Notify::PeerUpdate::Flag; | ||||||
| 	return Notify::PeerUpdateValue( | 	return Notify::PeerUpdateValue( | ||||||
|  |  | ||||||
|  | @ -56,6 +56,7 @@ rpl::producer<bool> CanAddContactValue(not_null<UserData*> user); | ||||||
| rpl::producer<bool> AmInChannelValue(not_null<ChannelData*> channel); | rpl::producer<bool> AmInChannelValue(not_null<ChannelData*> channel); | ||||||
| rpl::producer<int> MembersCountValue(not_null<PeerData*> peer); | rpl::producer<int> MembersCountValue(not_null<PeerData*> peer); | ||||||
| rpl::producer<int> AdminsCountValue(not_null<PeerData*> peer); | rpl::producer<int> AdminsCountValue(not_null<PeerData*> peer); | ||||||
|  | rpl::producer<int> RestrictionsCountValue(not_null<PeerData*> peer); | ||||||
| rpl::producer<int> RestrictedCountValue(not_null<ChannelData*> channel); | rpl::producer<int> RestrictedCountValue(not_null<ChannelData*> channel); | ||||||
| rpl::producer<int> KickedCountValue(not_null<ChannelData*> channel); | rpl::producer<int> KickedCountValue(not_null<ChannelData*> channel); | ||||||
| rpl::producer<int> SharedMediaCountValue( | rpl::producer<int> SharedMediaCountValue( | ||||||
|  |  | ||||||
|  | @ -358,7 +358,7 @@ void Filler::addChatActions(not_null<ChatData*> chat) { | ||||||
| 		if (ManagePeerBox::Available(chat)) { | 		if (ManagePeerBox::Available(chat)) { | ||||||
| 			const auto text = lang(lng_manage_group_title); | 			const auto text = lang(lng_manage_group_title); | ||||||
| 			_addAction(text, [=] { | 			_addAction(text, [=] { | ||||||
| 				Ui::show(Box<ManagePeerBox>(chat)); | 				Ui::show(Box<EditPeerInfoBox>(chat)); | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 		if (chat->canAddMembers()) { | 		if (chat->canAddMembers()) { | ||||||
|  | @ -402,7 +402,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) { | ||||||
| 				? lng_manage_group_title | 				? lng_manage_group_title | ||||||
| 				: lng_manage_channel_title); | 				: lng_manage_channel_title); | ||||||
| 			_addAction(text, [channel] { | 			_addAction(text, [channel] { | ||||||
| 				Ui::show(Box<ManagePeerBox>(channel)); | 				Ui::show(Box<EditPeerInfoBox>(channel)); | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 		if (channel->canAddMembers()) { | 		if (channel->canAddMembers()) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 23rd
						23rd