From 3332f012cf9c553195945bd95318268005a0d22b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 11 Sep 2023 13:38:53 +0300 Subject: [PATCH] Added tooltip and ability to copy external link to sponsored messages. --- .../data/data_sponsored_messages.cpp | 2 +- .../data/data_sponsored_messages.h | 2 +- .../history/history_inner_widget.cpp | 4 +- Telegram/SourceFiles/history/history_item.cpp | 3 +- .../history/history_item_components.h | 1 + .../history/view/history_view_view_button.cpp | 49 ++++++++++++------- Telegram/lib_ui | 2 +- 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/data_sponsored_messages.cpp index fa21af469c..ea42a0fe2f 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/data_sponsored_messages.cpp @@ -297,7 +297,7 @@ void SponsoredMessages::append( : ImageWithLocation{}; return SponsoredFrom{ .title = qs(data.vsite_name()), - .isExternalLink = true, + .externalLink = externalLink, .userpic = std::move(userpic), .isForceUserpicDisplay = message.data().is_show_peer_photo(), }; diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.h b/Telegram/SourceFiles/data/data_sponsored_messages.h index e9cd46b453..2c8b1e72b5 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.h +++ b/Telegram/SourceFiles/data/data_sponsored_messages.h @@ -31,7 +31,7 @@ struct SponsoredFrom { bool isBot = false; bool isExactPost = false; bool isRecommended = false; - bool isExternalLink = false; + QString externalLink; ImageWithLocation userpic; bool isForceUserpicDisplay = false; }; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 0071fd7726..80534e1a9f 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2544,7 +2544,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }, &st::menuIconLink); } if (item && item->isSponsored()) { - _menu->addSeparator(&st::expandedMenuSeparator); + if (!_menu->empty()) { + _menu->addSeparator(&st::expandedMenuSeparator); + } auto item = base::make_unique_q( _menu, st::menuWithIcons, diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index d81196689d..03129e338a 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -3234,8 +3234,9 @@ void HistoryItem::setSponsoredFrom(const Data::SponsoredFrom &from) { from.userpic); } + sponsored->externalLink = from.externalLink; using Type = HistoryMessageSponsored::Type; - sponsored->type = from.isExternalLink + sponsored->type = (!from.externalLink.isEmpty()) ? Type::ExternalLink : from.isExactPost ? Type::Post diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 75581f9696..e5c7ec37bd 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -146,6 +146,7 @@ struct HistoryMessageSponsored : public RuntimeComponent webpage) { }); } +[[nodiscard]] ClickHandlerPtr SponsoredLink( + not_null sponsored) { + if (!sponsored->externalLink.isEmpty()) { + return std::make_shared( + sponsored->externalLink, + false); + } else { + return std::make_shared([](ClickContext context) { + const auto my = context.other.value(); + const auto controller = my.sessionWindow.get(); + if (!controller) { + return; + } + const auto &data = controller->session().data(); + const auto details = data.sponsoredMessages().lookupDetails( + my.itemId); + if (!details.externalLink.isEmpty()) { + File::OpenUrl(details.externalLink); + } else if (details.hash) { + Api::CheckChatInvite(controller, *details.hash); + } else if (details.peer) { + controller->showPeerHistory( + details.peer, + Window::SectionShow::Way::Forward, + details.msgId); + } + }); + } +} + } // namespace struct ViewButton::Inner { @@ -156,24 +186,7 @@ ViewButton::Inner::Inner( not_null sponsored, Fn updateCallback) : margins(st::historyViewButtonMargins) -, link(std::make_shared([=](ClickContext context) { - const auto my = context.other.value(); - if (const auto controller = my.sessionWindow.get()) { - const auto &data = controller->session().data(); - const auto itemId = my.itemId; - const auto details = data.sponsoredMessages().lookupDetails(itemId); - if (!details.externalLink.isEmpty()) { - File::OpenUrl(details.externalLink); - } else if (details.hash) { - Api::CheckChatInvite(controller, *details.hash); - } else if (details.peer) { - controller->showPeerHistory( - details.peer, - Window::SectionShow::Way::Forward, - details.msgId); - } - } -})) +, link(SponsoredLink(sponsored)) , updateCallback(std::move(updateCallback)) , externalLink(sponsored->type == SponsoredType::ExternalLink) , text(st::historyViewButtonTextStyle, SponsoredPhrase(sponsored->type)) { diff --git a/Telegram/lib_ui b/Telegram/lib_ui index e24eaa6b32..aaa88be9d7 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit e24eaa6b32799119caa78caacd57216f81d3e1a7 +Subproject commit aaa88be9d7eaba529b31d742444e80846a2aa003