[Improvement] Click-to-copy for phone and username

This commit is contained in:
Eric Kotato 2022-09-10 20:52:51 +03:00
parent 28e1a3f312
commit 03cb40cf15
2 changed files with 50 additions and 4 deletions

View file

@ -145,6 +145,8 @@
"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_mention_copied": "Username copied to clipboard.",
"ktg_forward_go_to_chat": "Go to chat",
"ktg_settings_forward": "Forward",
"ktg_settings_forward_retain_selection": "Retain selection after forward",

View file

@ -27,6 +27,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 "history/history_location_manager.h" // LocationClickHandler.
#include "history/view/history_view_context_menu.h" // HistoryView::ShowReportPeerBox
#include "boxes/abstract_box.h"
@ -312,20 +313,63 @@ object_ptr<Ui::RpWidget> 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);
});
addInfoOneLine(
auto phoneInfo = addInfoOneLineInline(
tr::lng_info_mobile_label(),
PhoneOrHiddenValue(user),
std::move(phoneDrawableText),
tr::lng_profile_copy_phone(tr::now));
phoneInfo->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()
: tr::lng_info_bio_label();
addInfoLine(std::move(label), AboutValue(user));
addInfoOneLine(
auto usernameDrawableText = UsernameValue(
user
) | rpl::map([](TextWithEntities &&username) {
return username.text.isEmpty()
? TextWithEntities()
: Ui::Text::Link(username.text);
});
auto usernameInfo = addInfoOneLineInline(
tr::lng_info_username_label(),
UsernameValue(user),
std::move(usernameDrawableText),
tr::lng_context_copy_mention(tr::now));
usernameInfo->setClickHandlerFilter([user](auto&&...) {
const auto usernameText = user->userName();
if (!usernameText.isEmpty()) {
QGuiApplication::clipboard()->setText('@' + usernameText);
Ui::Toast::Show(ktr("ktg_mention_copied"));
}
return false;
});
const auto controller = _controller->parentController();
AddMainButton(
result,