2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Show inline path thumbnails for stickers.

This commit is contained in:
John Preston
2021-07-02 13:13:48 +03:00
parent f09b91ebb5
commit 4124c2eb57
21 changed files with 355 additions and 38 deletions

View File

@@ -134,18 +134,25 @@ std::vector<UnavailableReason> ExtractUnavailableReasons(
}) | ranges::to_vector;
}
[[nodiscard]] QByteArray FindInlineThumbnail(
[[nodiscard]] InlineImageLocation FindInlineThumbnail(
const QVector<MTPPhotoSize> &sizes) {
const auto i = ranges::find(
sizes,
mtpc_photoStrippedSize,
&MTPPhotoSize::type);
const auto j = ranges::find(
sizes,
mtpc_photoPathSize,
&MTPPhotoSize::type);
return (i != sizes.end())
? i->c_photoStrippedSize().vbytes().v
: QByteArray();
? InlineImageLocation{ i->c_photoStrippedSize().vbytes().v, false }
: (j != sizes.end())
? InlineImageLocation{ j->c_photoPathSize().vbytes().v, true }
: InlineImageLocation();
}
[[nodiscard]] QByteArray FindDocumentInlineThumbnail(const MTPDdocument &data) {
[[nodiscard]] InlineImageLocation FindDocumentInlineThumbnail(
const MTPDdocument &data) {
return FindInlineThumbnail(data.vthumbs().value_or_empty());
}
@@ -193,7 +200,8 @@ std::vector<UnavailableReason> ExtractUnavailableReasons(
}
[[nodiscard]] QByteArray FindPhotoInlineThumbnail(const MTPDphoto &data) {
return FindInlineThumbnail(data.vsizes().v);
const auto thumbnail = FindInlineThumbnail(data.vsizes().v);
return !thumbnail.isPath ? thumbnail.bytes : QByteArray();
}
[[nodiscard]] int VideoStartTime(const MTPDvideoSize &data) {
@@ -2656,7 +2664,7 @@ not_null<DocumentData*> Session::processDocument(
data.vdate().v,
data.vattributes().v,
qs(data.vmime_type()),
QByteArray(),
InlineImageLocation(),
thumbnail,
ImageWithLocation(),
data.vdc_id().v,
@@ -2673,7 +2681,7 @@ not_null<DocumentData*> Session::document(
TimeId date,
const QVector<MTPDocumentAttribute> &attributes,
const QString &mime,
const QByteArray &inlineThumbnailBytes,
const InlineImageLocation &inlineThumbnail,
const ImageWithLocation &thumbnail,
const ImageWithLocation &videoThumbnail,
int32 dc,
@@ -2686,7 +2694,7 @@ not_null<DocumentData*> Session::document(
date,
attributes,
mime,
inlineThumbnailBytes,
inlineThumbnail,
thumbnail,
videoThumbnail,
dc,
@@ -2754,7 +2762,7 @@ DocumentData *Session::documentFromWeb(
base::unixtime::now(),
data.vattributes().v,
data.vmime_type().v,
QByteArray(),
InlineImageLocation(),
ImageWithLocation{ .location = thumbnailLocation },
ImageWithLocation{ .location = videoThumbnailLocation },
session().mainDcId(),
@@ -2776,7 +2784,7 @@ DocumentData *Session::documentFromWeb(
base::unixtime::now(),
data.vattributes().v,
data.vmime_type().v,
QByteArray(),
InlineImageLocation(),
ImageWithLocation{ .location = thumbnailLocation },
ImageWithLocation{ .location = videoThumbnailLocation },
session().mainDcId(),
@@ -2796,7 +2804,7 @@ void Session::documentApplyFields(
void Session::documentApplyFields(
not_null<DocumentData*> document,
const MTPDdocument &data) {
const auto inlineThumbnailBytes = FindDocumentInlineThumbnail(data);
const auto inlineThumbnail = FindDocumentInlineThumbnail(data);
const auto thumbnailSize = FindDocumentThumbnail(data);
const auto videoThumbnailSize = FindDocumentVideoThumbnail(data);
const auto prepared = Images::FromPhotoSize(
@@ -2813,7 +2821,7 @@ void Session::documentApplyFields(
data.vdate().v,
data.vattributes().v,
qs(data.vmime_type()),
inlineThumbnailBytes,
inlineThumbnail,
prepared,
videoThumbnail,
data.vdc_id().v,
@@ -2827,7 +2835,7 @@ void Session::documentApplyFields(
TimeId date,
const QVector<MTPDocumentAttribute> &attributes,
const QString &mime,
const QByteArray &inlineThumbnailBytes,
const InlineImageLocation &inlineThumbnail,
const ImageWithLocation &thumbnail,
const ImageWithLocation &videoThumbnail,
int32 dc,
@@ -2838,7 +2846,7 @@ void Session::documentApplyFields(
document->date = date;
document->setMimeString(mime);
document->updateThumbnails(
inlineThumbnailBytes,
inlineThumbnail,
thumbnail,
videoThumbnail);
document->size = size;