From 729da4a6b4722a318bcd1041fbfb5ee3c85b029c Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Thu, 4 Jul 2019 12:07:32 +0200
Subject: [PATCH] Move 'Add to contacts' button up in Info.

---
 Telegram/Resources/langs/lang.strings         |  3 +-
 .../info/profile/info_profile_actions.cpp     | 18 +++----
 .../info/profile/info_profile_values.cpp      | 49 +++++++++++++------
 .../info/profile/info_profile_values.h        |  1 +
 4 files changed, 47 insertions(+), 24 deletions(-)

diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings
index 4f0190555..e3c9635e7 100644
--- a/Telegram/Resources/langs/lang.strings
+++ b/Telegram/Resources/langs/lang.strings
@@ -778,6 +778,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 "lng_profile_info_section" = "Info";
 "lng_info_tab_media" = "Media";
 "lng_info_mobile_label" = "Mobile";
+"lng_info_mobile_hidden" = "Hidden";
 "lng_info_username_label" = "Username";
 "lng_info_bio_label" = "Bio";
 "lng_info_link_label" = "Link";
@@ -789,7 +790,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 "lng_info_channel_title" = "Channel Info";
 "lng_profile_enable_notifications" = "Notifications";
 "lng_profile_send_message" = "Send Message";
-"lng_info_add_as_contact" = "Add as contact";
+"lng_info_add_as_contact" = "Add to contacts";
 "lng_profile_shared_media" = "Shared media";
 "lng_media_type_photos" = "Photos";
 "lng_media_type_videos" = "Videos";
diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp
index 6c99248b0..948fe1660 100644
--- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp
+++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp
@@ -259,7 +259,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 
 		addInfoOneLine(
 			tr::lng_info_mobile_label(),
-			PhoneValue(user),
+			PhoneOrHiddenValue(user),
 			tr::lng_profile_copy_phone(tr::now));
 		if (user->botInfo) {
 			addInfoLine(tr::lng_info_about_label(), AboutValue(user));
@@ -270,6 +270,14 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
 			tr::lng_info_username_label(),
 			UsernameValue(user),
 			tr::lng_context_copy_mention(tr::now));
+
+		const auto window = &_controller->parentController()->window()->controller();
+		AddMainButton(
+			result,
+			tr::lng_info_add_as_contact(),
+			CanAddContactValue(user),
+			[=] { window->show(Box(EditContactBox, window, user)); },
+			tracker);
 	} else {
 		auto linkText = LinkValue(
 			_peer
@@ -419,14 +427,6 @@ Ui::MultiSlideTracker DetailsFiller::fillUserButtons(
 		);
 	} else {
 		addSendMessageButton();
-
-		const auto window = &_controller->parentController()->window()->controller();
-		AddMainButton(
-			_wrap,
-			tr::lng_info_add_as_contact(),
-			CanAddContactValue(user),
-			[=] { window->show(Box(EditContactBox, window, user)); },
-			tracker);
 	}
 	return tracker;
 }
diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp
index 8172e0591..2d6cc9c41 100644
--- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp
+++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp
@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "auth_session.h"
 #include "ui/wrap/slide_wrap.h"
 #include "ui/text/text_utilities.h"
+#include "lang/lang_keys.h"
 #include "data/data_peer_values.h"
 #include "data/data_shared_media.h"
 #include "data/data_folder.h"
@@ -24,6 +25,25 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 namespace Info {
 namespace Profile {
+namespace {
+
+auto PlainBioValue(not_null<UserData*> user) {
+	return Notify::PeerUpdateValue(
+		user,
+		Notify::PeerUpdate::Flag::AboutChanged
+	) | rpl::map([=] { return user->about(); });
+}
+
+auto PlainUsernameValue(not_null<PeerData*> peer) {
+	return Notify::PeerUpdateValue(
+		peer,
+		Notify::PeerUpdate::Flag::UsernameChanged
+	) | rpl::map([=] {
+		return peer->userName();
+	});
+}
+
+} // namespace
 
 rpl::producer<TextWithEntities> NameValue(not_null<PeerData*> peer) {
 	return Notify::PeerUpdateValue(
@@ -43,11 +63,21 @@ rpl::producer<TextWithEntities> PhoneValue(not_null<UserData*> user) {
 	}) | Ui::Text::ToWithEntities();
 }
 
-auto PlainBioValue(not_null<UserData*> user) {
-	return Notify::PeerUpdateValue(
-		user,
-		Notify::PeerUpdate::Flag::AboutChanged
-	) | rpl::map([user] { return user->about(); });
+rpl::producer<TextWithEntities> PhoneOrHiddenValue(not_null<UserData*> user) {
+	return rpl::combine(
+		PhoneValue(user),
+		PlainUsernameValue(user),
+		PlainBioValue(user),
+		tr::lng_info_mobile_hidden()
+	) | rpl::map([](
+			const TextWithEntities &phone,
+			const QString &username,
+			const QString &bio,
+			const QString &hidden) {
+		return (phone.text.isEmpty() && username.isEmpty() && bio.isEmpty())
+			? Ui::Text::WithEntities(hidden)
+			: phone;
+	});
 }
 
 rpl::producer<TextWithEntities> BioValue(not_null<UserData*> user) {
@@ -56,15 +86,6 @@ rpl::producer<TextWithEntities> BioValue(not_null<UserData*> user) {
 		| Ui::Text::ToWithEntities();
 }
 
-auto PlainUsernameValue(not_null<PeerData*> peer) {
-	return Notify::PeerUpdateValue(
-		peer,
-		Notify::PeerUpdate::Flag::UsernameChanged
-	) | rpl::map([peer] {
-		return peer->userName();
-	});
-}
-
 rpl::producer<TextWithEntities> UsernameValue(not_null<UserData*> user) {
 	return PlainUsernameValue(
 		user
diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.h b/Telegram/SourceFiles/info/profile/info_profile_values.h
index 59a9bab73..0e19d17c3 100644
--- a/Telegram/SourceFiles/info/profile/info_profile_values.h
+++ b/Telegram/SourceFiles/info/profile/info_profile_values.h
@@ -34,6 +34,7 @@ inline auto ToSingleLine() {
 
 rpl::producer<TextWithEntities> NameValue(not_null<PeerData*> peer);
 rpl::producer<TextWithEntities> PhoneValue(not_null<UserData*> user);
+rpl::producer<TextWithEntities> PhoneOrHiddenValue(not_null<UserData*> user);
 rpl::producer<TextWithEntities> BioValue(not_null<UserData*> user);
 rpl::producer<TextWithEntities> UsernameValue(not_null<UserData*> user);
 rpl::producer<TextWithEntities> AboutValue(not_null<PeerData*> peer);