diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 52f68a108..8f05bd413 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -849,6 +849,8 @@ PRIVATE info/profile/info_profile_members.h info/profile/info_profile_members_controllers.cpp info/profile/info_profile_members_controllers.h + info/profile/info_profile_phone_menu.cpp + info/profile/info_profile_phone_menu.h info/profile/info_profile_text.cpp info/profile/info_profile_text.h info/profile/info_profile_values.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 3f1ed5c03..247ce7e3c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1196,6 +1196,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_info_tab_media" = "Media"; "lng_info_public_photo" = "public photo"; "lng_info_mobile_label" = "Mobile"; +"lng_info_mobile_context_menu_fragment_about" = "This number is not tied to a SIM card and was acquired on {link}."; +"lng_info_mobile_context_menu_fragment_about_link" = "Fragment"; "lng_info_mobile_hidden" = "Hidden"; "lng_info_username_label" = "Username"; "lng_info_usernames_label" = "also"; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 354042fa1..c319afaf5 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -45,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "info/info_memento.h" #include "info/profile/info_profile_icon.h" +#include "info/profile/info_profile_phone_menu.h" #include "info/profile/info_profile_values.h" #include "info/profile/info_profile_text.h" #include "support/support_helper.h" @@ -391,10 +392,17 @@ object_ptr DetailsFiller::setupInfo() { user->session().supportHelper().infoTextValue(user)); } - addInfoOneLine( - tr::lng_info_mobile_label(), - PhoneOrHiddenValue(user), - tr::lng_profile_copy_phone(tr::now)); + { + const auto phoneLabel = addInfoOneLine( + tr::lng_info_mobile_label(), + PhoneOrHiddenValue(user), + tr::lng_profile_copy_phone(tr::now)).text; + const auto hook = [=](Ui::FlatLabel::ContextMenuRequest request) { + phoneLabel->fillContextMenu(request); + AddPhoneMenu(request.menu, user); + }; + phoneLabel->setContextMenuHook(hook); + } auto label = user->isBot() ? tr::lng_info_about_label() : tr::lng_info_bio_label(); diff --git a/Telegram/SourceFiles/info/profile/info_profile_phone_menu.cpp b/Telegram/SourceFiles/info/profile/info_profile_phone_menu.cpp new file mode 100644 index 000000000..916c5e602 --- /dev/null +++ b/Telegram/SourceFiles/info/profile/info_profile_phone_menu.cpp @@ -0,0 +1,123 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "info/profile/info_profile_phone_menu.h" + +#include "data/data_user.h" +#include "lang/lang_keys.h" +#include "main/main_account.h" +#include "main/main_app_config.h" +#include "main/main_session.h" +#include "ui/text/text_utilities.h" +#include "ui/widgets/labels.h" +#include "ui/widgets/menu/menu_action.h" +#include "ui/widgets/popup_menu.h" +#include "styles/style_chat.h" // expandedMenuSeparator. + +namespace Info { +namespace Profile { +namespace { + +class TextItem final : public Ui::Menu::ItemBase { +public: + TextItem( + not_null parent, + const style::Menu &st, + rpl::producer &&text); + + not_null action() const override; + bool isEnabled() const override; + +protected: + int contentHeight() const override; + +private: + const base::unique_qptr _label; + const not_null _dummyAction; + +}; + +TextItem::TextItem( + not_null parent, + const style::Menu &st, + rpl::producer &&text) +: ItemBase(parent, st) +, _label(base::make_unique_q( + this, + std::move(text), + st::historyMessagesTTLLabel)) +, _dummyAction(Ui::CreateChild(parent.get())) { + + setMinWidth(st::historyMessagesTTLLabel.minWidth + + st.itemPadding.left()); + + sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + _label->moveToLeft( + st.itemPadding.left(), + (s.height() - _label->height()) / 2); + }, lifetime()); + + initResizeHook(parent->sizeValue()); +} + +not_null TextItem::action() const { + return _dummyAction; +} + +bool TextItem::isEnabled() const { + return false; +} + +int TextItem::contentHeight() const { + return _label->height(); +} + +} // namespace + +void AddPhoneMenu(not_null menu, not_null user) { + if (user->isSelf()) { + return; + } + using Strings = std::vector; + const auto prefixes = user->session().account().appConfig().get( + u"fragment_prefixes"_q, + std::vector()); + { + const auto proj = [&phone = user->phone()](const QString &p) { + return phone.startsWith(p); + }; + if (ranges::none_of(prefixes, proj)) { + return; + } + } + const auto domains = user->session().account().appConfig().get( + u"whitelisted_domains"_q, + std::vector()); + const auto proj = [&, domain = u"fragment"_q](const QString &p) { + return p.contains(domain); + }; + const auto it = ranges::find_if(domains, proj); + if (it == end(domains)) { + return; + } + + menu->addSeparator(&st::expandedMenuSeparator); + const auto link = Ui::Text::Link( + tr::lng_info_mobile_context_menu_fragment_about_link(tr::now), + *it); + menu->addAction(base::make_unique_q( + menu->menu(), + st::reactionMenu.menu, + tr::lng_info_mobile_context_menu_fragment_about( + lt_link, + rpl::single(link), + Ui::Text::RichLangValue))); +} + +} // namespace Profile +} // namespace Info diff --git a/Telegram/SourceFiles/info/profile/info_profile_phone_menu.h b/Telegram/SourceFiles/info/profile/info_profile_phone_menu.h new file mode 100644 index 000000000..82ed6bb8c --- /dev/null +++ b/Telegram/SourceFiles/info/profile/info_profile_phone_menu.h @@ -0,0 +1,22 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class UserData; + +namespace Ui { +class PopupMenu; +} // namespace Ui + +namespace Info { +namespace Profile { + +void AddPhoneMenu(not_null menu, not_null user); + +} // namespace Profile +} // namespace Info