From a48534b51a868702383716db3592926980297b02 Mon Sep 17 00:00:00 2001 From: AlexeyZavar Date: Thu, 18 Apr 2024 22:08:42 +0300 Subject: [PATCH] feat: rework `copyUsernameAsLink` --- .../info/profile/info_profile_actions.cpp | 10 ++++++++- .../ui/boxes/collectible_info_box.cpp | 21 ++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 7da9da56b..79a141f95 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -127,6 +127,8 @@ base::options::toggle ShowPeerIdBelowAbout({ const QString &addToLink) { const auto weak = base::make_weak(controller); return [=](QString link) { + auto settings = &AyuSettings::getInstance(); + if (link.startsWith(u"internal:"_q)) { Core::App().openInternalUrl(link, QVariant::fromValue(ClickHandlerContext{ @@ -138,9 +140,15 @@ base::options::toggle ShowPeerIdBelowAbout({ + addToLink; } if (!link.isEmpty()) { + if (!settings->copyUsernameAsLink && addToLink.isEmpty()) { + link = '@' + link.replace("https://t.me/", ""); + } + QGuiApplication::clipboard()->setText(link); if (const auto window = weak.get()) { - window->showToast(tr::lng_username_copied(tr::now)); + window->showToast(settings->copyUsernameAsLink + ? tr::lng_username_copied(tr::now) // "Link copied to clipboard." + : tr::lng_text_copied(tr::now)); // "Text copied to clipboard." } } }; diff --git a/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp b/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp index 4498becad..5975303ee 100644 --- a/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp @@ -26,6 +26,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace Ui { namespace { @@ -188,11 +192,22 @@ void CollectibleInfoBox( Ui::Text::Link(formatted), Ui::Text::WithEntities); const auto copyCallback = [box, type, formatted, text = info.copyText] { - QGuiApplication::clipboard()->setText( - text.isEmpty() ? formatted : text); + auto toCopy = text.isEmpty() ? formatted : text; + const auto settings = &AyuSettings::getInstance(); + if (type == CollectibleType::Username) { + if (settings->copyUsernameAsLink && !text.startsWith("https://")) { + toCopy = "https://t.me/" + toCopy.replace("@", ""); + } else if (!settings->copyUsernameAsLink && !text.startsWith("@")) { + toCopy = "@" + toCopy.replace("https://t.me/", ""); + } + } + + QGuiApplication::clipboard()->setText(toCopy); box->uiShow()->showToast((type == CollectibleType::Phone) ? tr::lng_text_copied(tr::now) - : tr::lng_username_copied(tr::now)); + : settings->copyUsernameAsLink + ? tr::lng_username_copied(tr::now) // "Link copied to clipboard." + : tr::lng_text_copied(tr::now)); // "Text copied to clipboard." }; box->addRow( object_ptr(