mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Support external links sponsored messages.
This commit is contained in:
parent
859636ff9c
commit
7ad5520b82
6 changed files with 62 additions and 18 deletions
Telegram
Resources/langs
SourceFiles
|
@ -3707,6 +3707,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_view_button_voice_chat" = "Voice chat";
|
||||
"lng_view_button_voice_chat_channel" = "Live stream";
|
||||
"lng_view_button_request_join" = "Request to Join";
|
||||
"lng_view_button_external_link" = "Open link";
|
||||
|
||||
"lng_sponsored_hide_ads" = "Hide";
|
||||
"lng_sponsored_title" = "What are sponsored messages?";
|
||||
|
|
|
@ -270,28 +270,45 @@ void SponsoredMessages::append(
|
|||
.isForceUserpicDisplay = data.is_show_peer_photo(),
|
||||
};
|
||||
};
|
||||
const auto externalLink = data.vwebpage()
|
||||
? qs(data.vwebpage()->data().vurl())
|
||||
: QString();
|
||||
const auto userpicFromPhoto = [&](const MTPphoto &photo) {
|
||||
return photo.match([&](const MTPDphoto &data) {
|
||||
for (const auto &size : data.vsizes().v) {
|
||||
const auto result = Images::FromPhotoSize(
|
||||
_session,
|
||||
data,
|
||||
size);
|
||||
if (result.location.valid()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return ImageWithLocation{};
|
||||
}, [](const MTPDphotoEmpty &) {
|
||||
return ImageWithLocation{};
|
||||
});
|
||||
};
|
||||
const auto from = [&]() -> SponsoredFrom {
|
||||
if (data.vfrom_id()) {
|
||||
if (const auto webpage = data.vwebpage()) {
|
||||
const auto &data = webpage->data();
|
||||
auto userpic = data.vphoto()
|
||||
? userpicFromPhoto(*data.vphoto())
|
||||
: ImageWithLocation{};
|
||||
return SponsoredFrom{
|
||||
.title = qs(data.vsite_name()),
|
||||
.isExternalLink = true,
|
||||
.userpic = std::move(userpic),
|
||||
.isForceUserpicDisplay = message.data().is_show_peer_photo(),
|
||||
};
|
||||
} else if (const auto fromId = data.vfrom_id()) {
|
||||
return makeFrom(
|
||||
_session->data().peer(peerFromMTP(*data.vfrom_id())),
|
||||
_session->data().peer(peerFromMTP(*fromId)),
|
||||
(data.vchannel_post() != nullptr));
|
||||
}
|
||||
Assert(data.vchat_invite());
|
||||
return data.vchat_invite()->match([&](const MTPDchatInvite &data) {
|
||||
auto userpic = data.vphoto().match([&](const MTPDphoto &data) {
|
||||
for (const auto &size : data.vsizes().v) {
|
||||
const auto result = Images::FromPhotoSize(
|
||||
_session,
|
||||
data,
|
||||
size);
|
||||
if (result.location.valid()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return ImageWithLocation{};
|
||||
}, [](const MTPDphotoEmpty &) {
|
||||
return ImageWithLocation{};
|
||||
});
|
||||
auto userpic = userpicFromPhoto(data.vphoto());
|
||||
return SponsoredFrom{
|
||||
.title = qs(data.vtitle()),
|
||||
.isBroadcast = data.is_broadcast(),
|
||||
|
@ -336,6 +353,7 @@ void SponsoredMessages::append(
|
|||
.history = history,
|
||||
.msgId = data.vchannel_post().value_or_empty(),
|
||||
.chatInviteHash = hash,
|
||||
.externalLink = externalLink,
|
||||
.sponsorInfo = std::move(sponsorInfo),
|
||||
.additionalInfo = std::move(additionalInfo),
|
||||
};
|
||||
|
@ -423,6 +441,7 @@ SponsoredMessages::Details SponsoredMessages::lookupDetails(
|
|||
.peer = data.from.peer,
|
||||
.msgId = data.msgId,
|
||||
.info = std::move(info),
|
||||
.externalLink = data.externalLink,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ struct SponsoredFrom {
|
|||
bool isBot = false;
|
||||
bool isExactPost = false;
|
||||
bool isRecommended = false;
|
||||
bool isExternalLink = false;
|
||||
ImageWithLocation userpic;
|
||||
bool isForceUserpicDisplay = false;
|
||||
};
|
||||
|
@ -42,6 +43,7 @@ struct SponsoredMessage {
|
|||
History *history = nullptr;
|
||||
MsgId msgId;
|
||||
QString chatInviteHash;
|
||||
QString externalLink;
|
||||
TextWithEntities sponsorInfo;
|
||||
TextWithEntities additionalInfo;
|
||||
};
|
||||
|
@ -58,6 +60,7 @@ public:
|
|||
PeerData *peer = nullptr;
|
||||
MsgId msgId;
|
||||
std::vector<TextWithEntities> info;
|
||||
QString externalLink;
|
||||
};
|
||||
using RandomId = QByteArray;
|
||||
explicit SponsoredMessages(not_null<Session*> owner);
|
||||
|
|
|
@ -3201,7 +3201,9 @@ void HistoryItem::setSponsoredFrom(const Data::SponsoredFrom &from) {
|
|||
}
|
||||
|
||||
using Type = HistoryMessageSponsored::Type;
|
||||
sponsored->type = from.isExactPost
|
||||
sponsored->type = from.isExternalLink
|
||||
? Type::ExternalLink
|
||||
: from.isExactPost
|
||||
? Type::Post
|
||||
: from.isBot
|
||||
? Type::Bot
|
||||
|
|
|
@ -139,6 +139,7 @@ struct HistoryMessageSponsored : public RuntimeComponent<HistoryMessageSponsored
|
|||
Broadcast,
|
||||
Post,
|
||||
Bot,
|
||||
ExternalLink,
|
||||
};
|
||||
std::unique_ptr<HiddenSenderInfo> sender;
|
||||
Type type = Type::User;
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "api/api_chat_invite.h"
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "data/data_cloud_themes.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_sponsored_messages.h"
|
||||
|
@ -42,6 +43,8 @@ inline auto SponsoredPhrase(SponsoredType type) {
|
|||
case SponsoredType::Broadcast: return tr::lng_view_button_channel;
|
||||
case SponsoredType::Post: return tr::lng_view_button_message;
|
||||
case SponsoredType::Bot: return tr::lng_view_button_bot;
|
||||
case SponsoredType::ExternalLink:
|
||||
return tr::lng_view_button_external_link;
|
||||
}
|
||||
Unexpected("SponsoredType in SponsoredPhrase.");
|
||||
}();
|
||||
|
@ -115,6 +118,7 @@ struct ViewButton::Inner {
|
|||
const ClickHandlerPtr link;
|
||||
const Fn<void()> updateCallback;
|
||||
bool belowInfo = true;
|
||||
bool externalLink = false;
|
||||
int lastWidth = 0;
|
||||
QPoint lastPoint;
|
||||
std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||
|
@ -158,7 +162,9 @@ ViewButton::Inner::Inner(
|
|||
const auto &data = controller->session().data();
|
||||
const auto itemId = my.itemId;
|
||||
const auto details = data.sponsoredMessages().lookupDetails(itemId);
|
||||
if (details.hash) {
|
||||
if (!details.externalLink.isEmpty()) {
|
||||
File::OpenUrl(details.externalLink);
|
||||
} else if (details.hash) {
|
||||
Api::CheckChatInvite(controller, *details.hash);
|
||||
} else if (details.peer) {
|
||||
controller->showPeerHistory(
|
||||
|
@ -169,6 +175,7 @@ ViewButton::Inner::Inner(
|
|||
}
|
||||
}))
|
||||
, updateCallback(std::move(updateCallback))
|
||||
, externalLink(sponsored->type == SponsoredType::ExternalLink)
|
||||
, text(st::historyViewButtonTextStyle, SponsoredPhrase(sponsored->type)) {
|
||||
}
|
||||
|
||||
|
@ -260,6 +267,17 @@ void ViewButton::draw(
|
|||
r.width(),
|
||||
1,
|
||||
style::al_center);
|
||||
|
||||
if (_inner->externalLink) {
|
||||
const auto &icon = st::msgBotKbUrlIcon;
|
||||
const auto padding = st::msgBotKbIconPadding;
|
||||
icon.paint(
|
||||
p,
|
||||
r.left() + r.width() - icon.width() - padding,
|
||||
r.top() + padding,
|
||||
r.width(),
|
||||
stm->fwdTextPalette.linkFg->c);
|
||||
}
|
||||
}
|
||||
p.restore();
|
||||
if (_inner->lastWidth != r.width()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue