mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Added initial ability to display media in sponsored messages.
This commit is contained in:
parent
30077133d4
commit
624e068f2f
4 changed files with 85 additions and 14 deletions
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "apiwrap.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
|
@ -269,6 +270,35 @@ void SponsoredMessages::append(
|
|||
const MTPSponsoredMessage &message) {
|
||||
const auto &data = message.data();
|
||||
const auto randomId = data.vrandom_id().v;
|
||||
auto mediaPhotoId = PhotoId(0);
|
||||
auto mediaDocumentId = DocumentId(0);
|
||||
{
|
||||
if (data.vmedia()) {
|
||||
data.vmedia()->match([&](const MTPDmessageMediaPhoto &media) {
|
||||
if (const auto tlPhoto = media.vphoto()) {
|
||||
tlPhoto->match([&](const MTPDphoto &data) {
|
||||
const auto p = history->owner().processPhoto(data);
|
||||
mediaPhotoId = p->id;
|
||||
}, [](const MTPDphotoEmpty &) {
|
||||
});
|
||||
}
|
||||
}, [&](const MTPDmessageMediaDocument &media) {
|
||||
if (const auto tlDocument = media.vdocument()) {
|
||||
tlDocument->match([&](const MTPDdocument &data) {
|
||||
const auto d = history->owner().processDocument(data);
|
||||
if (d->isVideoFile()
|
||||
|| d->isSilentVideo()
|
||||
|| d->isAnimation()
|
||||
|| d->isGifv()) {
|
||||
mediaDocumentId = d->id;
|
||||
}
|
||||
}, [](const MTPDdocumentEmpty &) {
|
||||
});
|
||||
}
|
||||
}, [](const auto &) {
|
||||
});
|
||||
}
|
||||
};
|
||||
const auto from = SponsoredFrom{
|
||||
.title = qs(data.vtitle()),
|
||||
.link = qs(data.vurl()),
|
||||
|
@ -276,6 +306,8 @@ void SponsoredMessages::append(
|
|||
.photoId = data.vphoto()
|
||||
? history->session().data().processPhoto(*data.vphoto())->id
|
||||
: PhotoId(0),
|
||||
.mediaPhotoId = mediaPhotoId,
|
||||
.mediaDocumentId = mediaDocumentId,
|
||||
.backgroundEmojiId = data.vcolor().has_value()
|
||||
? data.vcolor()->data().vbackground_emoji_id().value_or_empty()
|
||||
: uint64(0),
|
||||
|
@ -396,6 +428,8 @@ SponsoredMessages::Details SponsoredMessages::lookupDetails(
|
|||
.colorIndex = data.from.colorIndex,
|
||||
.isLinkInternal = data.from.isLinkInternal,
|
||||
.canReport = data.from.canReport,
|
||||
.mediaPhotoId = data.from.mediaPhotoId,
|
||||
.mediaDocumentId = data.from.mediaDocumentId,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ struct SponsoredFrom {
|
|||
QString link;
|
||||
QString buttonText;
|
||||
PhotoId photoId = PhotoId(0);
|
||||
PhotoId mediaPhotoId = PhotoId(0);
|
||||
DocumentId mediaDocumentId = DocumentId(0);
|
||||
uint64 backgroundEmojiId = 0;
|
||||
uint8 colorIndex : 6 = 0;
|
||||
bool isLinkInternal = false;
|
||||
|
@ -73,6 +75,8 @@ public:
|
|||
QString link;
|
||||
QString buttonText;
|
||||
PhotoId photoId = PhotoId(0);
|
||||
PhotoId mediaPhotoId = PhotoId(0);
|
||||
DocumentId mediaDocumentId = DocumentId(0);
|
||||
uint64 backgroundEmojiId = 0;
|
||||
uint8 colorIndex : 6 = 0;
|
||||
bool isLinkInternal = false;
|
||||
|
|
|
@ -305,6 +305,23 @@ void WebPage::setupAdditionalData() {
|
|||
raw->backgroundEmojiId = details.backgroundEmojiId;
|
||||
raw->colorIndex = details.colorIndex;
|
||||
raw->canReport = details.canReport ? 1 : 0;
|
||||
raw->hasMedia = (details.mediaPhotoId || details.mediaDocumentId)
|
||||
? 1
|
||||
: 0;
|
||||
if (!_attach) {
|
||||
const auto maybePhoto = details.mediaPhotoId
|
||||
? _data->session().data().photo(details.mediaPhotoId)
|
||||
: nullptr;
|
||||
const auto maybeDocument = details.mediaDocumentId
|
||||
? _data->session().data().document(details.mediaDocumentId)
|
||||
: nullptr;
|
||||
_attach = CreateAttach(
|
||||
_parent,
|
||||
maybeDocument,
|
||||
maybePhoto,
|
||||
_collage,
|
||||
_data->url);
|
||||
}
|
||||
} else if (_data->stickerSet) {
|
||||
_additionalData = std::make_unique<AdditionalData>(StickerSetData());
|
||||
const auto raw = stickerSetData();
|
||||
|
@ -460,6 +477,9 @@ QSize WebPage::countOptimalSize() {
|
|||
} else {
|
||||
_asArticle = _data->computeDefaultSmallMedia();
|
||||
}
|
||||
if (sponsored && sponsored->hasMedia) {
|
||||
_asArticle = 0;
|
||||
}
|
||||
|
||||
// init attach
|
||||
if (!_attach && !_asArticle) {
|
||||
|
@ -567,9 +587,10 @@ QSize WebPage::countOptimalSize() {
|
|||
minHeight += st::factcheckFooterSkip + factcheck->footer.minHeight();
|
||||
}
|
||||
if (_attach) {
|
||||
const auto attachAtTop = _siteName.isEmpty()
|
||||
&& _title.isEmpty()
|
||||
&& _description.isEmpty();
|
||||
const auto attachAtTop = (_siteName.isEmpty()
|
||||
&& _title.isEmpty()
|
||||
&& _description.isEmpty())
|
||||
|| (sponsored && sponsored->hasMedia);
|
||||
if (!attachAtTop) {
|
||||
minHeight += st::mediaInBubbleSkip;
|
||||
}
|
||||
|
@ -622,7 +643,9 @@ QSize WebPage::countCurrentSize(int newWidth) {
|
|||
|
||||
const auto stickerSet = stickerSetData();
|
||||
const auto factcheck = factcheckData();
|
||||
const auto specialRightPix = (sponsoredData() || stickerSet);
|
||||
const auto sponsored = sponsoredData();
|
||||
const auto specialRightPix = ((sponsored && !sponsored->hasMedia)
|
||||
|| stickerSet);
|
||||
const auto lineHeight = UnitedLineHeight();
|
||||
const auto factcheckMetrics = factcheck
|
||||
? computeFactcheckMetrics(_description.countHeight(innerWidth))
|
||||
|
@ -720,9 +743,10 @@ QSize WebPage::countCurrentSize(int newWidth) {
|
|||
}
|
||||
|
||||
if (_attach) {
|
||||
const auto attachAtTop = !_siteNameLines
|
||||
&& !_titleLines
|
||||
&& !_descriptionLines;
|
||||
const auto attachAtTop = (!_siteNameLines
|
||||
&& !_titleLines
|
||||
&& !_descriptionLines)
|
||||
|| (sponsored && sponsored->hasMedia);
|
||||
if (!attachAtTop) {
|
||||
newHeight += st::mediaInBubbleSkip;
|
||||
}
|
||||
|
@ -818,6 +842,11 @@ void WebPage::draw(Painter &p, const PaintContext &context) const {
|
|||
const auto sponsored = sponsoredData();
|
||||
const auto factcheck = factcheckData();
|
||||
|
||||
const auto hasSponsoredMedia = sponsored && sponsored->hasMedia;
|
||||
if (hasSponsoredMedia && _attach) {
|
||||
tshift += _attach->height() + st::mediaInBubbleSkip;
|
||||
}
|
||||
|
||||
const auto selected = context.selected();
|
||||
const auto view = parent();
|
||||
const auto from = view->data()->contentColorsFrom();
|
||||
|
@ -1078,9 +1107,8 @@ void WebPage::draw(Painter &p, const PaintContext &context) const {
|
|||
tshift += factcheck->footerHeight;
|
||||
}
|
||||
if (_attach) {
|
||||
const auto attachAtTop = !_siteNameLines
|
||||
&& !_titleLines
|
||||
&& !_descriptionLines;
|
||||
const auto attachAtTop = hasSponsoredMedia
|
||||
|| (!_siteNameLines && !_titleLines && !_descriptionLines);
|
||||
if (!attachAtTop) {
|
||||
tshift += st::mediaInBubbleSkip;
|
||||
}
|
||||
|
@ -1088,7 +1116,9 @@ void WebPage::draw(Painter &p, const PaintContext &context) const {
|
|||
const auto attachLeft = rtl()
|
||||
? (width() - (inner.left() - bubble.left()) - _attach->width())
|
||||
: (inner.left() - bubble.left());
|
||||
const auto attachTop = tshift - bubble.top();
|
||||
const auto attachTop = hasSponsoredMedia
|
||||
? inner.top()
|
||||
: (tshift - bubble.top());
|
||||
|
||||
p.translate(attachLeft, attachTop);
|
||||
|
||||
|
@ -1305,9 +1335,10 @@ TextState WebPage::textState(QPoint point, StateRequest request) const {
|
|||
if (inThumb) {
|
||||
result.link = _openl;
|
||||
} else if (_attach) {
|
||||
const auto attachAtTop = !_siteNameLines
|
||||
&& !_titleLines
|
||||
&& !_descriptionLines;
|
||||
const auto attachAtTop = (!_siteNameLines
|
||||
&& !_titleLines
|
||||
&& !_descriptionLines)
|
||||
|| (sponsored && sponsored->hasMedia);
|
||||
if (!attachAtTop) {
|
||||
tshift += st::mediaInBubbleSkip;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/userpic_view.h"
|
||||
|
||||
namespace Data {
|
||||
class DocumentMedia;
|
||||
class Media;
|
||||
class PhotoMedia;
|
||||
} // namespace Data
|
||||
|
@ -127,6 +128,7 @@ private:
|
|||
uint8 colorIndex : 6 = 0;
|
||||
uint8 isLinkInternal : 1 = 0;
|
||||
uint8 canReport : 1 = 0;
|
||||
uint8 hasMedia : 1 = 0;
|
||||
|
||||
HintData hint;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue