[Improvement] Click-to-copy for phone
This commit is contained in:
		
							parent
							
								
									802035dde5
								
							
						
					
					
						commit
						f66b40cd42
					
				
					 2 changed files with 27 additions and 3 deletions
				
			
		| 
						 | 
					@ -107,6 +107,7 @@
 | 
				
			||||||
	"ktg_group_id_copied": "Group ID copied to clipboard.",
 | 
						"ktg_group_id_copied": "Group ID copied to clipboard.",
 | 
				
			||||||
	"ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.",
 | 
						"ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.",
 | 
				
			||||||
	"ktg_channel_id_copied": "Channel ID copied to clipboard.",
 | 
						"ktg_channel_id_copied": "Channel ID copied to clipboard.",
 | 
				
			||||||
 | 
						"ktg_phone_copied": "Phone copied to clipboard.",
 | 
				
			||||||
	"ktg_forward_go_to_chat": "Go to chat",
 | 
						"ktg_forward_go_to_chat": "Go to chat",
 | 
				
			||||||
	"ktg_settings_forward": "Forward",
 | 
						"ktg_settings_forward": "Forward",
 | 
				
			||||||
	"ktg_settings_forward_retain_selection": "Retain selection after forward",
 | 
						"ktg_settings_forward_retain_selection": "Retain selection after forward",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1040,7 +1040,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 | 
				
			||||||
			std::move(label),
 | 
								std::move(label),
 | 
				
			||||||
			std::move(text),
 | 
								std::move(text),
 | 
				
			||||||
			st::infoLabeledOneLineInline);
 | 
								st::infoLabeledOneLineInline);
 | 
				
			||||||
		result->setContextCopyText(contextCopyText);
 | 
							result.text->setContextCopyText(contextCopyText);
 | 
				
			||||||
		return result;
 | 
							return result;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	if (const auto user = _peer->asUser()) {
 | 
						if (const auto user = _peer->asUser()) {
 | 
				
			||||||
| 
						 | 
					@ -1058,7 +1058,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 | 
				
			||||||
				std::move(idDrawableText),
 | 
									std::move(idDrawableText),
 | 
				
			||||||
				ktr("ktg_profile_copy_id"));
 | 
									ktr("ktg_profile_copy_id"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			idInfo->setClickHandlerFilter([user](auto&&...) {
 | 
								idInfo.text->setClickHandlerFilter([user](auto&&...) {
 | 
				
			||||||
				const auto idText = IDString(user);
 | 
									const auto idText = IDString(user);
 | 
				
			||||||
				if (!idText.isEmpty()) {
 | 
									if (!idText.isEmpty()) {
 | 
				
			||||||
					QGuiApplication::clipboard()->setText(idText);
 | 
										QGuiApplication::clipboard()->setText(idText);
 | 
				
			||||||
| 
						 | 
					@ -1076,6 +1076,21 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 | 
				
			||||||
				user->session().supportHelper().infoTextValue(user));
 | 
									user->session().supportHelper().infoTextValue(user));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							auto phoneDrawableText = rpl::combine(
 | 
				
			||||||
 | 
								PhoneValue(user),
 | 
				
			||||||
 | 
								UsernameValue(user),
 | 
				
			||||||
 | 
								AboutValue(user),
 | 
				
			||||||
 | 
								tr::lng_info_mobile_hidden()
 | 
				
			||||||
 | 
							) | rpl::map([](
 | 
				
			||||||
 | 
									const TextWithEntities &phone,
 | 
				
			||||||
 | 
									const TextWithEntities &username,
 | 
				
			||||||
 | 
									const TextWithEntities &bio,
 | 
				
			||||||
 | 
									const QString &hidden) {
 | 
				
			||||||
 | 
								return (phone.text.isEmpty() && username.text.isEmpty() && bio.text.isEmpty())
 | 
				
			||||||
 | 
									? Ui::Text::WithEntities(hidden)
 | 
				
			||||||
 | 
									: Ui::Text::Link(phone.text);
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			const auto phoneLabel = addInfoOneLine(
 | 
								const auto phoneLabel = addInfoOneLine(
 | 
				
			||||||
				tr::lng_info_mobile_label(),
 | 
									tr::lng_info_mobile_label(),
 | 
				
			||||||
| 
						 | 
					@ -1086,6 +1101,14 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 | 
				
			||||||
				AddPhoneMenu(request.menu, user);
 | 
									AddPhoneMenu(request.menu, user);
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
			phoneLabel->setContextMenuHook(hook);
 | 
								phoneLabel->setContextMenuHook(hook);
 | 
				
			||||||
 | 
								phoneLabel->setClickHandlerFilter([user](auto&&...) {
 | 
				
			||||||
 | 
									const auto phoneText = user->phone();
 | 
				
			||||||
 | 
									if (!phoneText.isEmpty()) {
 | 
				
			||||||
 | 
										QGuiApplication::clipboard()->setText(Ui::FormatPhone(phoneText));
 | 
				
			||||||
 | 
										Ui::Toast::Show(ktr("ktg_phone_copied"));
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return false;
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		auto label = user->isBot()
 | 
							auto label = user->isBot()
 | 
				
			||||||
			? tr::lng_info_about_label()
 | 
								? tr::lng_info_about_label()
 | 
				
			||||||
| 
						 | 
					@ -1204,7 +1227,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 | 
				
			||||||
				std::move(idDrawableText),
 | 
									std::move(idDrawableText),
 | 
				
			||||||
				ktr("ktg_profile_copy_id"));
 | 
									ktr("ktg_profile_copy_id"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			idInfo->setClickHandlerFilter([peer = _peer](auto&&...) {
 | 
								idInfo.text->setClickHandlerFilter([peer = _peer](auto&&...) {
 | 
				
			||||||
				const auto idText = IDString(peer);
 | 
									const auto idText = IDString(peer);
 | 
				
			||||||
				if (!idText.isEmpty()) {
 | 
									if (!idText.isEmpty()) {
 | 
				
			||||||
					QGuiApplication::clipboard()->setText(idText);
 | 
										QGuiApplication::clipboard()->setText(idText);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue