From f77fdc799dbd5f9d3677277909db58ad140288e2 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Mon, 4 Nov 2024 14:52:42 +0400
Subject: [PATCH] Show special phone number context number.

---
 Telegram/SourceFiles/core/click_handler_types.h      |  1 +
 Telegram/SourceFiles/core/phone_click_handler.cpp    |  1 +
 .../SourceFiles/history/history_inner_widget.cpp     | 12 +++++++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h
index b3aa0bae0..43295e196 100644
--- a/Telegram/SourceFiles/core/click_handler_types.h
+++ b/Telegram/SourceFiles/core/click_handler_types.h
@@ -16,6 +16,7 @@ constexpr auto kDocumentLinkMediaProperty = 0x03;
 constexpr auto kSendReactionEmojiProperty = 0x04;
 constexpr auto kReactionsCountEmojiProperty = 0x05;
 constexpr auto kDocumentFilenameTooltipProperty = 0x06;
+constexpr auto kPhoneNumberLinkProperty = 0x07;
 
 namespace Ui {
 class Show;
diff --git a/Telegram/SourceFiles/core/phone_click_handler.cpp b/Telegram/SourceFiles/core/phone_click_handler.cpp
index 28da63ffa..9723ffe34 100644
--- a/Telegram/SourceFiles/core/phone_click_handler.cpp
+++ b/Telegram/SourceFiles/core/phone_click_handler.cpp
@@ -291,6 +291,7 @@ PhoneClickHandler::PhoneClickHandler(
 	QString text)
 : _session(session)
 , _text(text) {
+	setProperty(kPhoneNumberLinkProperty, _text);
 }
 
 void PhoneClickHandler::onClick(ClickContext context) const {
diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index 73b5cbb17..517006172 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "chat_helpers/stickers_emoji_pack.h"
 #include "core/file_utilities.h"
 #include "core/click_handler_types.h"
+#include "core/phone_click_handler.h"
 #include "history/history_item_helpers.h"
 #include "history/view/controls/history_view_forward_panel.h"
 #include "history/view/controls/history_view_draft_options.h"
@@ -2200,6 +2201,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
 		&& Api::WhoReactedExists(leaderOrSelf, Api::WhoReactedList::All);
 	using namespace HistoryView::Reactions;
 	const auto clickedReaction = ReactionIdOfLink(link);
+	const auto linkPhoneNumber = link
+		? link->property(kPhoneNumberLinkProperty).toString()
+		: QString();
+	const auto session = &this->session();
 	_whoReactedMenuLifetime.destroy();
 	if (!clickedReaction.empty()
 		&& leaderOrSelf
@@ -2214,9 +2219,14 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
 			_whoReactedMenuLifetime);
 		e->accept();
 		return;
+	} else if (!linkPhoneNumber.isEmpty()) {
+		PhoneClickHandler(session, linkPhoneNumber).onClick(
+			prepareClickContext(
+				Qt::LeftButton,
+				_dragStateItem ? _dragStateItem->fullId() : FullMsgId()));
+		return;
 	}
 	_menu = base::make_unique_q<Ui::PopupMenu>(this, st::popupMenuWithIcons);
-	const auto session = &this->session();
 	const auto controller = _controller;
 	const auto addItemActions = [&](
 			HistoryItem *item,