mirror of https://github.com/procxx/kepka.git
Save video thumbnail location to local storage.
This commit is contained in:
parent
c63e2c01ac
commit
f4ed2c26ba
|
@ -716,6 +716,10 @@ const ImageLocation &DocumentData::thumbnailLocation() const {
|
||||||
return _thumbnailLocation;
|
return _thumbnailLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DocumentData::thumbnailByteSize() const {
|
||||||
|
return _thumbnailByteSize;
|
||||||
|
}
|
||||||
|
|
||||||
bool DocumentData::hasVideoThumbnail() const {
|
bool DocumentData::hasVideoThumbnail() const {
|
||||||
return _videoThumbnailLocation.valid()
|
return _videoThumbnailLocation.valid()
|
||||||
&& (_videoThumbnailLocation.width() > 0)
|
&& (_videoThumbnailLocation.width() > 0)
|
||||||
|
@ -775,6 +779,10 @@ const ImageLocation &DocumentData::videoThumbnailLocation() const {
|
||||||
return _videoThumbnailLocation;
|
return _videoThumbnailLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DocumentData::videoThumbnailByteSize() const {
|
||||||
|
return _videoThumbnailByteSize;
|
||||||
|
}
|
||||||
|
|
||||||
Storage::Cache::Key DocumentData::goodThumbnailCacheKey() const {
|
Storage::Cache::Key DocumentData::goodThumbnailCacheKey() const {
|
||||||
return Data::DocumentThumbCacheKey(_dc, id);
|
return Data::DocumentThumbCacheKey(_dc, id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,12 +160,14 @@ public:
|
||||||
[[nodiscard]] bool thumbnailFailed() const;
|
[[nodiscard]] bool thumbnailFailed() const;
|
||||||
void loadThumbnail(Data::FileOrigin origin);
|
void loadThumbnail(Data::FileOrigin origin);
|
||||||
const ImageLocation &thumbnailLocation() const;
|
const ImageLocation &thumbnailLocation() const;
|
||||||
|
int thumbnailByteSize() const;
|
||||||
|
|
||||||
[[nodiscard]] bool hasVideoThumbnail() const;
|
[[nodiscard]] bool hasVideoThumbnail() const;
|
||||||
[[nodiscard]] bool videoThumbnailLoading() const;
|
[[nodiscard]] bool videoThumbnailLoading() const;
|
||||||
[[nodiscard]] bool videoThumbnailFailed() const;
|
[[nodiscard]] bool videoThumbnailFailed() const;
|
||||||
void loadVideoThumbnail(Data::FileOrigin origin);
|
void loadVideoThumbnail(Data::FileOrigin origin);
|
||||||
const ImageLocation &videoThumbnailLocation() const;
|
const ImageLocation &videoThumbnailLocation() const;
|
||||||
|
int videoThumbnailByteSize() const;
|
||||||
|
|
||||||
void updateThumbnails(
|
void updateThumbnails(
|
||||||
const QByteArray &inlineThumbnailBytes,
|
const QByteArray &inlineThumbnailBytes,
|
||||||
|
|
|
@ -13,8 +13,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
|
||||||
|
namespace Serialize {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kVersionTag = int32(0x7FFFFFFF);
|
||||||
|
constexpr auto kVersion = 1;
|
||||||
|
|
||||||
enum StickerSetType {
|
enum StickerSetType {
|
||||||
StickerSetTypeEmpty = 0,
|
StickerSetTypeEmpty = 0,
|
||||||
StickerSetTypeID = 1,
|
StickerSetTypeID = 1,
|
||||||
|
@ -23,12 +27,9 @@ enum StickerSetType {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace Serialize {
|
|
||||||
|
|
||||||
void Document::writeToStream(QDataStream &stream, DocumentData *document) {
|
void Document::writeToStream(QDataStream &stream, DocumentData *document) {
|
||||||
const auto version = 0;
|
|
||||||
stream << quint64(document->id) << quint64(document->_access) << qint32(document->date);
|
stream << quint64(document->id) << quint64(document->_access) << qint32(document->date);
|
||||||
stream << document->_fileReference << qint32(version);
|
stream << document->_fileReference << qint32(kVersionTag) << qint32(kVersion);
|
||||||
stream << document->filename() << document->mimeString() << qint32(document->_dc) << qint32(document->size);
|
stream << document->filename() << document->mimeString() << qint32(document->_dc) << qint32(document->size);
|
||||||
stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height());
|
stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height());
|
||||||
stream << qint32(document->type);
|
stream << qint32(document->type);
|
||||||
|
@ -50,20 +51,27 @@ void Document::writeToStream(QDataStream &stream, DocumentData *document) {
|
||||||
stream << qint32(document->getDuration());
|
stream << qint32(document->getDuration());
|
||||||
}
|
}
|
||||||
writeImageLocation(stream, document->thumbnailLocation());
|
writeImageLocation(stream, document->thumbnailLocation());
|
||||||
|
stream << qint32(document->thumbnailByteSize());
|
||||||
|
writeImageLocation(stream, document->videoThumbnailLocation());
|
||||||
|
stream << qint32(document->videoThumbnailByteSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &stream, const StickerSetInfo *info) {
|
DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &stream, const StickerSetInfo *info) {
|
||||||
quint64 id, access;
|
quint64 id, access;
|
||||||
QString name, mime;
|
QString name, mime;
|
||||||
qint32 date, dc, size, width, height, type, version;
|
qint32 date, dc, size, width, height, type, versionTag, version = 0;
|
||||||
QByteArray fileReference;
|
QByteArray fileReference;
|
||||||
stream >> id >> access >> date;
|
stream >> id >> access >> date;
|
||||||
if (streamAppVersion >= 9061) {
|
if (streamAppVersion >= 9061) {
|
||||||
if (streamAppVersion >= 1003013) {
|
if (streamAppVersion >= 1003013) {
|
||||||
stream >> fileReference;
|
stream >> fileReference;
|
||||||
}
|
}
|
||||||
stream >> version;
|
stream >> versionTag;
|
||||||
|
if (versionTag == kVersionTag) {
|
||||||
|
stream >> version;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
versionTag = 0;
|
||||||
version = 0;
|
version = 0;
|
||||||
}
|
}
|
||||||
stream >> name >> mime >> dc >> size;
|
stream >> name >> mime >> dc >> size;
|
||||||
|
@ -76,7 +84,6 @@ DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &
|
||||||
}
|
}
|
||||||
|
|
||||||
qint32 duration = -1;
|
qint32 duration = -1;
|
||||||
std::optional<ImageLocation> thumb;
|
|
||||||
if (type == StickerDocument) {
|
if (type == StickerDocument) {
|
||||||
QString alt;
|
QString alt;
|
||||||
qint32 typeOfSet;
|
qint32 typeOfSet;
|
||||||
|
@ -110,7 +117,16 @@ DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &
|
||||||
attributes.push_back(MTP_documentAttributeAnimated());
|
attributes.push_back(MTP_documentAttributeAnimated());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thumb = readImageLocation(streamAppVersion, stream);
|
std::optional<ImageLocation> videoThumb;
|
||||||
|
qint32 thumbnailByteSize = 0, videoThumbnailByteSize = 0;
|
||||||
|
const auto thumb = readImageLocation(streamAppVersion, stream);
|
||||||
|
if (version >= 1) {
|
||||||
|
stream >> thumbnailByteSize;
|
||||||
|
videoThumb = readImageLocation(streamAppVersion, stream);
|
||||||
|
stream >> videoThumbnailByteSize;
|
||||||
|
} else {
|
||||||
|
videoThumb = ImageLocation();
|
||||||
|
}
|
||||||
if (width > 0 && height > 0) {
|
if (width > 0 && height > 0) {
|
||||||
if (duration >= 0) {
|
if (duration >= 0) {
|
||||||
auto flags = MTPDdocumentAttributeVideo::Flags(0);
|
auto flags = MTPDdocumentAttributeVideo::Flags(0);
|
||||||
|
@ -125,7 +141,8 @@ DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &
|
||||||
|
|
||||||
const auto storage = base::get_if<StorageFileLocation>(
|
const auto storage = base::get_if<StorageFileLocation>(
|
||||||
&thumb->file().data);
|
&thumb->file().data);
|
||||||
if ((!dc && !access)
|
if ((stream.status() != QDataStream::Ok)
|
||||||
|
|| (!dc && !access)
|
||||||
|| !thumb
|
|| !thumb
|
||||||
|| (thumb->valid()
|
|| (thumb->valid()
|
||||||
&& (!storage || !storage->isDocumentThumbnail()))) {
|
&& (!storage || !storage->isDocumentThumbnail()))) {
|
||||||
|
@ -142,8 +159,14 @@ DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &
|
||||||
attributes,
|
attributes,
|
||||||
mime,
|
mime,
|
||||||
QByteArray(),
|
QByteArray(),
|
||||||
ImageWithLocation{ .location = *thumb },
|
ImageWithLocation{
|
||||||
ImageWithLocation(),
|
.location = *thumb,
|
||||||
|
.bytesCount = thumbnailByteSize
|
||||||
|
},
|
||||||
|
ImageWithLocation{
|
||||||
|
.location = *videoThumb,
|
||||||
|
.bytesCount = videoThumbnailByteSize
|
||||||
|
},
|
||||||
dc,
|
dc,
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue