diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/data_sponsored_messages.cpp index 041448d465..696afdfe8b 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/data_sponsored_messages.cpp @@ -10,7 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_text_entities.h" #include "apiwrap.h" #include "base/unixtime.h" +#include "data/data_bot_app.h" #include "data/data_channel.h" +#include "data/data_peer.h" #include "data/data_peer_id.h" #include "data/data_photo.h" #include "data/data_session.h" @@ -273,10 +275,10 @@ void SponsoredMessages::append( .isMegagroup = (channel && channel->isMegagroup()), .isChannel = (channel != nullptr), .isPublic = (channel && channel->isPublic()), - .isBot = (peer->isUser() && peer->asUser()->isBot()), .isExactPost = exactPost, .isRecommended = data.is_recommended(), .isForceUserpicDisplay = data.is_show_peer_photo(), + .buttonText = qs(data.vbutton_text().value_or_empty()), }; }; const auto externalLink = data.vwebpage() @@ -291,13 +293,36 @@ void SponsoredMessages::append( return SponsoredFrom{ .title = qs(data.vsite_name()), .externalLink = externalLink, - .externalLinkPhotoId = photoId, + .webpageOrBotPhotoId = photoId, .isForceUserpicDisplay = message.data().is_show_peer_photo(), }; } else if (const auto fromId = data.vfrom_id()) { - return makeFrom( - _session->data().peer(peerFromMTP(*fromId)), + const auto peerId = peerFromMTP(*fromId); + auto result = makeFrom( + _session->data().peer(peerId), (data.vchannel_post() != nullptr)); + const auto user = result.peer->asUser(); + if (user && user->isBot()) { + const auto botAppData = data.vapp() + ? _session->data().processBotApp(peerId, *data.vapp()) + : nullptr; + result.botLinkInfo = Window::PeerByLinkInfo{ + .usernameOrId = user->userName(), + .resolveType = botAppData + ? Window::ResolveType::BotApp + : data.vstart_param() + ? Window::ResolveType::BotStart + : Window::ResolveType::Default, + .startToken = qs(data.vstart_param().value_or_empty()), + .botAppName = botAppData + ? botAppData->shortName + : QString(), + }; + result.webpageOrBotPhotoId = (botAppData && botAppData->photo) + ? botAppData->photo->id + : PhotoId(0); + } + return result; } Assert(data.vchat_invite()); return data.vchat_invite()->match([&](const MTPDchatInvite &data) { @@ -434,11 +459,14 @@ SponsoredMessages::Details SponsoredMessages::lookupDetails( .info = std::move(info), .externalLink = data.externalLink, .isForceUserpicDisplay = data.from.isForceUserpicDisplay, - .buttonText = !data.externalLink.isEmpty() + .buttonText = !data.from.buttonText.isEmpty() + ? data.from.buttonText + : !data.externalLink.isEmpty() ? tr::lng_view_button_external_link(tr::now) - : data.from.isBot + : data.from.botLinkInfo ? tr::lng_view_button_bot(tr::now) : QString(), + .botLinkInfo = data.from.botLinkInfo, }; } diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.h b/Telegram/SourceFiles/data/data_sponsored_messages.h index b67c46d7fc..d5107fd4ef 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.h +++ b/Telegram/SourceFiles/data/data_sponsored_messages.h @@ -7,9 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "history/history_item.h" #include "base/timer.h" +#include "history/history_item.h" #include "ui/image/image_location.h" +#include "window/window_session_controller_link_info.h" class History; @@ -28,12 +29,13 @@ struct SponsoredFrom { bool isMegagroup = false; bool isChannel = false; bool isPublic = false; - bool isBot = false; + std::optional botLinkInfo; bool isExactPost = false; bool isRecommended = false; QString externalLink; - PhotoId externalLinkPhotoId; + PhotoId webpageOrBotPhotoId = PhotoId(0); bool isForceUserpicDisplay = false; + QString buttonText; }; struct SponsoredMessage { @@ -63,6 +65,7 @@ public: QString externalLink; bool isForceUserpicDisplay = false; QString buttonText; + std::optional botLinkInfo; }; using RandomId = QByteArray; explicit SponsoredMessages(not_null owner); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 8b3e7ea300..14f4e90eaf 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -699,7 +699,9 @@ HistoryItem::HistoryItem( const auto webPageType = from.isExactPost ? WebPageType::Message - : from.isBot + : (from.botLinkInfo && !from.botLinkInfo->botAppName.isEmpty()) + ? WebPageType::BotApp + : from.botLinkInfo ? WebPageType::Bot : from.isBroadcast ? WebPageType::Channel @@ -717,8 +719,8 @@ HistoryItem::HistoryItem( : tr::lng_sponsored_message_title(tr::now), from.title, textWithEntities, - from.externalLinkPhotoId - ? history->owner().photo(from.externalLinkPhotoId) + from.webpageOrBotPhotoId + ? history->owner().photo(from.webpageOrBotPhotoId) : nullptr, nullptr, WebPageCollage(), diff --git a/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp b/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp index c6df994b18..65b030476d 100644 --- a/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sponsored_click_handler.cpp @@ -44,6 +44,8 @@ ClickHandlerPtr SponsoredLink(const QString &externalLink) { File::OpenUrl(details.externalLink); } else if (details.hash) { Api::CheckChatInvite(controller, *details.hash); + } else if (details.botLinkInfo) { + controller->showPeerByLink(*details.botLinkInfo); } else if (details.peer) { controller->showPeerHistory( details.peer,