From 92f6b6f688ad3ae7c8bf8249765b179635469665 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 10 Sep 2022 20:52:51 +0300 Subject: [PATCH] [Improvement] Click-to-copy for phone --- Telegram/Resources/langs/rewrites/en.json | 1 + .../info/profile/info_profile_actions.cpp | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index a692ccdcf..b174917f5 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -118,6 +118,7 @@ "ktg_group_id_copied": "Group ID copied to clipboard.", "ktg_supergroup_id_copied": "Supergroup 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_settings_forward": "Forward", "ktg_settings_forward_retain_selection": "Retain selection after forward", diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 9a9bb97aa..3ef364036 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/layers/generic_box.h" #include "ui/toast/toast.h" #include "ui/text/text_utilities.h" // Ui::Text::ToUpper +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_variant.h" #include "history/history_location_manager.h" // LocationClickHandler. #include "history/view/history_view_context_menu.h" // HistoryView::ShowReportPeerBox @@ -482,7 +483,7 @@ object_ptr DetailsFiller::setupInfo() { std::move(label), std::move(text), st::infoLabeledOneLineInline); - result->setContextCopyText(contextCopyText); + result.text->setContextCopyText(contextCopyText); return result; }; if (const auto user = _peer->asUser()) { @@ -500,7 +501,7 @@ object_ptr DetailsFiller::setupInfo() { std::move(idDrawableText), ktr("ktg_profile_copy_id")); - idInfo->setClickHandlerFilter([user](auto&&...) { + idInfo.text->setClickHandlerFilter([user](auto&&...) { const auto idText = IDString(user); if (!idText.isEmpty()) { QGuiApplication::clipboard()->setText(idText); @@ -517,6 +518,21 @@ object_ptr DetailsFiller::setupInfo() { user->session().supportHelper().infoLabelValue(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( @@ -528,6 +544,14 @@ object_ptr DetailsFiller::setupInfo() { AddPhoneMenu(request.menu, user); }; 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() ? tr::lng_info_about_label() @@ -625,7 +649,7 @@ object_ptr DetailsFiller::setupInfo() { std::move(idDrawableText), ktr("ktg_profile_copy_id")); - idInfo->setClickHandlerFilter([peer = _peer](auto&&...) { + idInfo.text->setClickHandlerFilter([peer = _peer](auto&&...) { const auto idText = IDString(peer); if (!idText.isEmpty()) { QGuiApplication::clipboard()->setText(idText);