mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Support external links sponsored messages.
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user