diff --git a/Telegram/SourceFiles/storage/serialize_peer.cpp b/Telegram/SourceFiles/storage/serialize_peer.cpp index 15312a8ae..28c128399 100644 --- a/Telegram/SourceFiles/storage/serialize_peer.cpp +++ b/Telegram/SourceFiles/storage/serialize_peer.cpp @@ -324,12 +324,10 @@ PeerData *readPeer( } if (apply) { using LocationType = StorageFileLocation::Type; - const auto location = (userpic->valid() && userpic->isLegacy()) - ? userpic->convertToModern( - LocationType::PeerPhoto, - result->id.value, - userpicAccessHash) - : *userpic; + const auto location = userpic->convertToModernPeerPhoto( + result->id.value, + userpicAccessHash, + photoId); result->setUserpic(photoId, location); } return result; @@ -342,7 +340,7 @@ QString peekUserPhone(int streamAppVersion, QDataStream &stream) { DEBUG_LOG(("peekUserPhone.id: %1").arg(peerId.value)); if (!peerId || !peerIsUser(peerId) - || !readStorageImageLocation(streamAppVersion, stream)) { + || !readImageLocation(streamAppVersion, stream)) { return QString(); } diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index f77f9b8a1..c35b6c5ce 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -1683,10 +1683,8 @@ void Account::readStickerSets( if (!thumbnail || !CheckStreamStatus(stickers.stream)) { return failed(); } else if (thumbnail->valid() && thumbnail->isLegacy()) { - setThumbnail = thumbnail->convertToModern( - LocationType::StickerSetThumb, - setId, - setAccess); + // No thumb_version information in legacy location. + return failed(); } else { setThumbnail = *thumbnail; } diff --git a/Telegram/SourceFiles/ui/image/image_location.cpp b/Telegram/SourceFiles/ui/image/image_location.cpp index 8be9a22b5..942a94ab5 100644 --- a/Telegram/SourceFiles/ui/image/image_location.cpp +++ b/Telegram/SourceFiles/ui/image/image_location.cpp @@ -177,18 +177,25 @@ StorageFileLocation::StorageFileLocation( }); } -StorageFileLocation StorageFileLocation::convertToModern( - Type type, +StorageFileLocation StorageFileLocation::convertToModernPeerPhoto( uint64 id, - uint64 accessHash) const { - Expects(_type == Type::Legacy); - Expects(type == Type::PeerPhoto || type == Type::StickerSetThumb); + uint64 accessHash, + uint64 photoId) const { + if (_type != Type::Legacy && _type != Type::PeerPhoto) { + return *this; + } else if (!photoId) { + return StorageFileLocation(); + } auto result = *this; - result._type = type; + result._type = Type::PeerPhoto; result._id = id; result._accessHash = accessHash; - result._sizeLetter = (type == Type::PeerPhoto) ? uint8('a') : uint8(0); + result._sizeLetter = uint8('a'); + result._volumeId = photoId; + result._localId = 0; + result._inMessagePeerId = 0; + result._inMessageId = 0; return result; } @@ -310,7 +317,7 @@ int StorageFileLocation::serializeSize() const { } std::optional StorageFileLocation::FromSerialized( - const QByteArray &serialized) { + const QByteArray &serialized) { if (serialized.isEmpty()) { return StorageFileLocation(); } @@ -386,6 +393,11 @@ std::optional StorageFileLocation::FromSerialized( : peerFromChannel(ChannelId(-field2))) : PeerId(); } + if (result._type == Type::StickerSetThumb && result._volumeId != 0) { + // Legacy field values that cannot be converted to modern. + // No information about thumb_version, which is required. + return std::nullopt; + } return (stream.status() == QDataStream::Ok && result.valid()) ? std::make_optional(result) @@ -882,15 +894,17 @@ std::optional DownloadLocation::FromSerialized( return std::nullopt; } -DownloadLocation DownloadLocation::convertToModern( - StorageFileLocation::Type type, +DownloadLocation DownloadLocation::convertToModernPeerPhoto( uint64 id, - uint64 accessHash) const { + uint64 accessHash, + uint64 photoId) const { if (!v::is(data)) { return *this; } auto &file = v::get(data); - return DownloadLocation{ file.convertToModern(type, id, accessHash) }; + return DownloadLocation{ + file.convertToModernPeerPhoto(id, accessHash, photoId) + }; } Storage::Cache::Key DownloadLocation::cacheKey() const { diff --git a/Telegram/SourceFiles/ui/image/image_location.h b/Telegram/SourceFiles/ui/image/image_location.h index efa1d88a2..f406e10a5 100644 --- a/Telegram/SourceFiles/ui/image/image_location.h +++ b/Telegram/SourceFiles/ui/image/image_location.h @@ -70,10 +70,10 @@ public: UserId self, const MTPInputFileLocation &tl); - [[nodiscard]] StorageFileLocation convertToModern( - Type type, + [[nodiscard]] StorageFileLocation convertToModernPeerPhoto( uint64 id, - uint64 accessHash) const; + uint64 accessHash, + uint64 photoId) const; [[nodiscard]] int32 dcId() const; [[nodiscard]] uint64 objectId() const; @@ -157,12 +157,12 @@ public: [[nodiscard]] static std::optional FromSerialized( const QByteArray &serialized); - [[nodiscard]] StorageImageLocation convertToModern( - StorageFileLocation::Type type, + [[nodiscard]] StorageImageLocation convertToModernPeerPhoto( uint64 id, - uint64 accessHash) const { + uint64 accessHash, + uint64 photoId) const { return StorageImageLocation( - _file.convertToModern(type, id, accessHash), + _file.convertToModernPeerPhoto(id, accessHash, photoId), _width, _height); } @@ -461,10 +461,10 @@ public: [[nodiscard]] static std::optional FromSerialized( const QByteArray &serialized); - [[nodiscard]] DownloadLocation convertToModern( - StorageFileLocation::Type type, + [[nodiscard]] DownloadLocation convertToModernPeerPhoto( uint64 id, - uint64 accessHash) const; + uint64 accessHash, + uint64 photoId) const; [[nodiscard]] Storage::Cache::Key cacheKey() const; [[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const; @@ -524,12 +524,12 @@ public: [[nodiscard]] static std::optional FromSerialized( const QByteArray &serialized); - [[nodiscard]] ImageLocation convertToModern( - StorageFileLocation::Type type, + [[nodiscard]] ImageLocation convertToModernPeerPhoto( uint64 id, - uint64 accessHash) const { + uint64 accessHash, + uint64 photoId) const { return ImageLocation( - _file.convertToModern(type, id, accessHash), + _file.convertToModernPeerPhoto(id, accessHash, photoId), _width, _height); }