mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Fix working with document thumbnails.
This commit is contained in:
parent
7f598e358a
commit
456a949d01
4 changed files with 29 additions and 17 deletions
|
@ -4009,6 +4009,11 @@ void readSavedGifs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &saved = Auth().data().savedGifsRef();
|
auto &saved = Auth().data().savedGifsRef();
|
||||||
|
const auto failed = [&] {
|
||||||
|
clearKey(_savedGifsKey);
|
||||||
|
_savedGifsKey = 0;
|
||||||
|
saved.clear();
|
||||||
|
};
|
||||||
saved.clear();
|
saved.clear();
|
||||||
|
|
||||||
quint32 cnt;
|
quint32 cnt;
|
||||||
|
@ -4017,7 +4022,11 @@ void readSavedGifs() {
|
||||||
OrderedSet<DocumentId> read;
|
OrderedSet<DocumentId> read;
|
||||||
for (uint32 i = 0; i < cnt; ++i) {
|
for (uint32 i = 0; i < cnt; ++i) {
|
||||||
auto document = Serialize::Document::readFromStream(gifs.version, gifs.stream);
|
auto document = Serialize::Document::readFromStream(gifs.version, gifs.stream);
|
||||||
if (!document || !document->isGifv()) continue;
|
if (!_checkStreamStatus(gifs.stream)) {
|
||||||
|
return failed();
|
||||||
|
} else if (!document || !document->isGifv()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (read.contains(document->id)) continue;
|
if (read.contains(document->id)) continue;
|
||||||
read.insert(document->id);
|
read.insert(document->id);
|
||||||
|
|
|
@ -131,14 +131,14 @@ DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!dc && !access) || !thumb) {
|
if ((!dc && !access)
|
||||||
|
|| !thumb
|
||||||
|
|| (thumb->valid() && !thumb->file().isDocumentThumbnail())) {
|
||||||
|
stream.setStatus(QDataStream::ReadCorruptData);
|
||||||
|
// We can't convert legacy thumbnail location to modern, because
|
||||||
|
// size letter ('s' or 'm') is lost, it was not saved in legacy.
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
using LocationType = StorageFileLocation::Type;
|
|
||||||
const auto location = (thumb->valid()
|
|
||||||
&& thumb->type() == LocationType::Legacy)
|
|
||||||
? thumb->convertToModern(LocationType::Document, id, access)
|
|
||||||
: *thumb;
|
|
||||||
return Auth().data().document(
|
return Auth().data().document(
|
||||||
id,
|
id,
|
||||||
access,
|
access,
|
||||||
|
@ -147,10 +147,10 @@ DocumentData *Document::readFromStreamHelper(int streamAppVersion, QDataStream &
|
||||||
attributes,
|
attributes,
|
||||||
mime,
|
mime,
|
||||||
ImagePtr(),
|
ImagePtr(),
|
||||||
Images::Create(location),
|
Images::Create(*thumb),
|
||||||
dc,
|
dc,
|
||||||
size,
|
size,
|
||||||
location);
|
*thumb);
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentData *Document::readStickerFromStream(int streamAppVersion, QDataStream &stream, const StickerSetInfo &info) {
|
DocumentData *Document::readStickerFromStream(int streamAppVersion, QDataStream &stream, const StickerSetInfo &info) {
|
||||||
|
|
|
@ -134,9 +134,7 @@ StorageFileLocation StorageFileLocation::convertToModern(
|
||||||
uint64 id,
|
uint64 id,
|
||||||
uint64 accessHash) const {
|
uint64 accessHash) const {
|
||||||
Expects(_type == Type::Legacy);
|
Expects(_type == Type::Legacy);
|
||||||
Expects(type == Type::Document
|
Expects(type == Type::PeerPhoto || type == Type::StickerSetThumb);
|
||||||
|| type == Type::PeerPhoto
|
|
||||||
|| type == Type::StickerSetThumb);
|
|
||||||
|
|
||||||
auto result = *this;
|
auto result = *this;
|
||||||
result._type = type;
|
result._type = type;
|
||||||
|
@ -305,10 +303,15 @@ bool StorageFileLocation::valid() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StorageFileLocation::isDocumentThumbnail() const {
|
||||||
|
return (_type == Type::Document) && (_sizeLetter != 0);
|
||||||
|
}
|
||||||
|
|
||||||
Storage::Cache::Key StorageFileLocation::cacheKey() const {
|
Storage::Cache::Key StorageFileLocation::cacheKey() const {
|
||||||
using Key = Storage::Cache::Key;
|
using Key = Storage::Cache::Key;
|
||||||
|
|
||||||
// Skip '1' and '2' for legacy document cache keys.
|
// Skip '1' for legacy document cache keys.
|
||||||
|
// Skip '2' because it is used for good (fullsize) document thumbnails.
|
||||||
const auto shifted = ((uint64(_type) + 3) << 8);
|
const auto shifted = ((uint64(_type) + 3) << 8);
|
||||||
const auto sliced = uint64(_dcId) & 0xFFULL;
|
const auto sliced = uint64(_dcId) & 0xFFULL;
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
|
@ -324,13 +327,10 @@ Storage::Cache::Key StorageFileLocation::cacheKey() const {
|
||||||
return Key{ shifted | sliced, _id };
|
return Key{ shifted | sliced, _id };
|
||||||
|
|
||||||
case Type::Document:
|
case Type::Document:
|
||||||
// Keep old cache keys for documents and document 'm' thumbnails.
|
// Keep old cache keys for documents.
|
||||||
if (_sizeLetter == 0) {
|
if (_sizeLetter == 0) {
|
||||||
return Data::DocumentCacheKey(_dcId, _id);
|
return Data::DocumentCacheKey(_dcId, _id);
|
||||||
//return Key{ 0x100ULL | sliced, _id };
|
//return Key{ 0x100ULL | sliced, _id };
|
||||||
} else if (_sizeLetter == uint8('m')) {
|
|
||||||
return Data::DocumentThumbCacheKey(_dcId, _id);
|
|
||||||
//return Key{ 0x200ULL | sliced, _id };
|
|
||||||
}
|
}
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case Type::Photo:
|
case Type::Photo:
|
||||||
|
|
|
@ -86,6 +86,9 @@ public:
|
||||||
[[nodiscard]] Storage::Cache::Key cacheKey() const;
|
[[nodiscard]] Storage::Cache::Key cacheKey() const;
|
||||||
[[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const;
|
[[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const;
|
||||||
|
|
||||||
|
// We have to allow checking this because of a serialization bug.
|
||||||
|
[[nodiscard]] bool isDocumentThumbnail() const;
|
||||||
|
|
||||||
[[nodiscard]] QByteArray fileReference() const;
|
[[nodiscard]] QByteArray fileReference() const;
|
||||||
bool refreshFileReference(const Data::UpdatedFileReferences &updates);
|
bool refreshFileReference(const Data::UpdatedFileReferences &updates);
|
||||||
bool refreshFileReference(const QByteArray &data);
|
bool refreshFileReference(const QByteArray &data);
|
||||||
|
|
Loading…
Add table
Reference in a new issue