From fe2455dea6f95ae8220a4298c7a8bd1554e21709 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 8 Jun 2022 13:54:19 +0300 Subject: [PATCH] Moved copy link of public user from context menu to button in profile. --- Telegram/SourceFiles/info/info.style | 13 ++++- .../info/profile/info_profile_actions.cpp | 56 ++++++++++++++----- .../SourceFiles/window/window_peer_menu.cpp | 24 -------- 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 559dcb382..f4eb3b852 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -306,16 +306,27 @@ infoVerifiedCheck: icon { }; infoPremiumStar: icon {{ "profile_premium", profileVerifiedCheckBg }}; +infoIconFg: windowBoldFg; + infoProfileSkip: 7px; infoProfileLabeledPadding: margins(79px, 9px, 30px, 7px); +infoProfileLabeledUsernamePadding: margins(79px, 9px, 20px, 7px); infoProfileSeparatorPadding: margins( 77px, infoProfileSkip, 0px, infoProfileSkip); +infoProfileLabeledButtonCopy: IconButton(defaultIconButton) { + width: 34px; + height: 34px; + icon: icon {{ "menu/copy", infoIconFg }}; + iconOver: icon {{ "menu/copy", infoIconFg }}; + rippleAreaPosition: point(0px, 0px); + rippleAreaSize: 34px; + ripple: defaultRippleAnimation; +} -infoIconFg: windowBoldFg; infoIconInformation: icon {{ "info/info_information", infoIconFg }}; infoIconAddMember: icon {{ "info/info_add_member", infoIconFg }}; infoIconNotifications: icon {{ "info/info_notifications", infoIconFg }}; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index d7620d30a..7142389ad 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -244,43 +244,49 @@ object_ptr DetailsFiller::setupInfo() { return true; }; - auto addInfoLineGeneric = [&]( + const auto addInfoLineGeneric = [&]( rpl::producer &&label, rpl::producer &&text, - const style::FlatLabel &textSt = st::infoLabeled) { + const style::FlatLabel &textSt = st::infoLabeled, + const style::margins &padding = st::infoProfileLabeledPadding) { auto line = CreateTextWithLabel( result, std::move(label) | Ui::Text::ToWithEntities(), std::move(text), textSt, - st::infoProfileLabeledPadding); + padding); tracker.track(result->add(std::move(line.wrap))); line.text->setClickHandlerFilter(infoClickFilter); return line.text; }; - auto addInfoLine = [&]( + const auto addInfoLine = [&]( rpl::producer &&label, rpl::producer &&text, - const style::FlatLabel &textSt = st::infoLabeled) { + const style::FlatLabel &textSt = st::infoLabeled, + const style::margins &padding = st::infoProfileLabeledPadding) { return addInfoLineGeneric( std::move(label), std::move(text), - textSt); + textSt, + padding); }; - auto addInfoOneLine = [&]( + const auto addInfoOneLine = [&]( rpl::producer &&label, rpl::producer &&text, - const QString &contextCopyText) { - auto result = addInfoLine( + const QString &contextCopyText, + const style::margins &padding = st::infoProfileLabeledPadding) { + const auto result = addInfoLine( std::move(label), std::move(text), - st::infoLabeledOneLine); + st::infoLabeledOneLine, + padding); result->setDoubleClickSelectsParagraph(true); result->setContextCopyText(contextCopyText); return result; }; if (const auto user = _peer->asUser()) { + const auto controller = _controller->parentController(); if (user->session().supportMode()) { addInfoLineGeneric( user->session().supportHelper().infoLabelValue(user), @@ -295,12 +301,36 @@ object_ptr DetailsFiller::setupInfo() { ? tr::lng_info_about_label() : tr::lng_info_bio_label(); addInfoLine(std::move(label), AboutValue(user)); - addInfoOneLine( + + const auto usernameLabel = addInfoOneLine( tr::lng_info_username_label(), UsernameValue(user), - tr::lng_context_copy_mention(tr::now)); + tr::lng_context_copy_mention(tr::now), + st::infoProfileLabeledUsernamePadding); + if (user->isBot()) { + const auto copyUsername = Ui::CreateChild( + usernameLabel->parentWidget(), + st::infoProfileLabeledButtonCopy); + result->sizeValue( + ) | rpl::start_with_next([=] { + const auto s = usernameLabel->parentWidget()->size(); + copyUsername->moveToRight( + 0, + (s.height() - copyUsername->height()) / 2); + }, copyUsername->lifetime()); + copyUsername->setClickedCallback([=] { + const auto link = user->session().createInternalLinkFull( + user->userName()); + if (!link.isEmpty()) { + QGuiApplication::clipboard()->setText(link); + Ui::Toast::Show( + Window::Show(controller).toastParent(), + tr::lng_username_copied(tr::now)); + } + return false; + }); + } - const auto controller = _controller->parentController(); AddMainButton( result, tr::lng_info_add_as_contact(), diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 39decba98..d2559ea57 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/report_box.h" #include "ui/toast/toast.h" #include "ui/text/format_values.h" -#include "ui/text/text_entity.h" #include "ui/text/text_utilities.h" #include "ui/widgets/labels.h" #include "ui/widgets/checkbox.h" @@ -197,7 +196,6 @@ private: void addExportChat(); void addReport(); void addNewContact(); - void addShareUsername(); void addShareContact(); void addEditContact(); void addBotToGroup(); @@ -653,27 +651,6 @@ void Filler::addNewContact() { &st::menuIconInvite); } -void Filler::addShareUsername() { - const auto user = _peer->asUser(); - if (!user || user->userName().isEmpty()) { - return; - } - _addAction( - tr::lng_group_invite_share(tr::now), - [=, controller = _controller] { - const auto link = controller->session().createInternalLinkFull( - user->userName()); - if (link.isEmpty()) { - return; - } - TextUtilities::SetClipboardText(TextForMimeData::Simple(link)); - Ui::Toast::Show( - Window::Show(controller).toastParent(), - tr::lng_username_copied(tr::now)); - }, - &st::menuIconShare); -} - void Filler::addShareContact() { const auto user = _peer->asUser(); if (!user || !user->canShareThisContact()) { @@ -880,7 +857,6 @@ void Filler::fillProfileActions() { addSupportInfo(); addNewContact(); addShareContact(); - addShareUsername(); addEditContact(); addBotToGroup(); addNewMembers();