Drop old sticker set cover locations.

This commit is contained in:
John Preston 2021-05-19 16:09:07 +04:00
parent 8e3dc76dd7
commit 9510ba07f7
4 changed files with 47 additions and 37 deletions

View file

@ -324,12 +324,10 @@ PeerData *readPeer(
} }
if (apply) { if (apply) {
using LocationType = StorageFileLocation::Type; using LocationType = StorageFileLocation::Type;
const auto location = (userpic->valid() && userpic->isLegacy()) const auto location = userpic->convertToModernPeerPhoto(
? userpic->convertToModern( result->id.value,
LocationType::PeerPhoto, userpicAccessHash,
result->id.value, photoId);
userpicAccessHash)
: *userpic;
result->setUserpic(photoId, location); result->setUserpic(photoId, location);
} }
return result; return result;
@ -342,7 +340,7 @@ QString peekUserPhone(int streamAppVersion, QDataStream &stream) {
DEBUG_LOG(("peekUserPhone.id: %1").arg(peerId.value)); DEBUG_LOG(("peekUserPhone.id: %1").arg(peerId.value));
if (!peerId if (!peerId
|| !peerIsUser(peerId) || !peerIsUser(peerId)
|| !readStorageImageLocation(streamAppVersion, stream)) { || !readImageLocation(streamAppVersion, stream)) {
return QString(); return QString();
} }

View file

@ -1683,10 +1683,8 @@ void Account::readStickerSets(
if (!thumbnail || !CheckStreamStatus(stickers.stream)) { if (!thumbnail || !CheckStreamStatus(stickers.stream)) {
return failed(); return failed();
} else if (thumbnail->valid() && thumbnail->isLegacy()) { } else if (thumbnail->valid() && thumbnail->isLegacy()) {
setThumbnail = thumbnail->convertToModern( // No thumb_version information in legacy location.
LocationType::StickerSetThumb, return failed();
setId,
setAccess);
} else { } else {
setThumbnail = *thumbnail; setThumbnail = *thumbnail;
} }

View file

@ -177,18 +177,25 @@ StorageFileLocation::StorageFileLocation(
}); });
} }
StorageFileLocation StorageFileLocation::convertToModern( StorageFileLocation StorageFileLocation::convertToModernPeerPhoto(
Type type,
uint64 id, uint64 id,
uint64 accessHash) const { uint64 accessHash,
Expects(_type == Type::Legacy); uint64 photoId) const {
Expects(type == Type::PeerPhoto || type == Type::StickerSetThumb); if (_type != Type::Legacy && _type != Type::PeerPhoto) {
return *this;
} else if (!photoId) {
return StorageFileLocation();
}
auto result = *this; auto result = *this;
result._type = type; result._type = Type::PeerPhoto;
result._id = id; result._id = id;
result._accessHash = accessHash; 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; return result;
} }
@ -310,7 +317,7 @@ int StorageFileLocation::serializeSize() const {
} }
std::optional<StorageFileLocation> StorageFileLocation::FromSerialized( std::optional<StorageFileLocation> StorageFileLocation::FromSerialized(
const QByteArray &serialized) { const QByteArray &serialized) {
if (serialized.isEmpty()) { if (serialized.isEmpty()) {
return StorageFileLocation(); return StorageFileLocation();
} }
@ -386,6 +393,11 @@ std::optional<StorageFileLocation> StorageFileLocation::FromSerialized(
: peerFromChannel(ChannelId(-field2))) : peerFromChannel(ChannelId(-field2)))
: PeerId(); : 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()) return (stream.status() == QDataStream::Ok && result.valid())
? std::make_optional(result) ? std::make_optional(result)
@ -882,15 +894,17 @@ std::optional<DownloadLocation> DownloadLocation::FromSerialized(
return std::nullopt; return std::nullopt;
} }
DownloadLocation DownloadLocation::convertToModern( DownloadLocation DownloadLocation::convertToModernPeerPhoto(
StorageFileLocation::Type type,
uint64 id, uint64 id,
uint64 accessHash) const { uint64 accessHash,
uint64 photoId) const {
if (!v::is<StorageFileLocation>(data)) { if (!v::is<StorageFileLocation>(data)) {
return *this; return *this;
} }
auto &file = v::get<StorageFileLocation>(data); auto &file = v::get<StorageFileLocation>(data);
return DownloadLocation{ file.convertToModern(type, id, accessHash) }; return DownloadLocation{
file.convertToModernPeerPhoto(id, accessHash, photoId)
};
} }
Storage::Cache::Key DownloadLocation::cacheKey() const { Storage::Cache::Key DownloadLocation::cacheKey() const {

View file

@ -70,10 +70,10 @@ public:
UserId self, UserId self,
const MTPInputFileLocation &tl); const MTPInputFileLocation &tl);
[[nodiscard]] StorageFileLocation convertToModern( [[nodiscard]] StorageFileLocation convertToModernPeerPhoto(
Type type,
uint64 id, uint64 id,
uint64 accessHash) const; uint64 accessHash,
uint64 photoId) const;
[[nodiscard]] int32 dcId() const; [[nodiscard]] int32 dcId() const;
[[nodiscard]] uint64 objectId() const; [[nodiscard]] uint64 objectId() const;
@ -157,12 +157,12 @@ public:
[[nodiscard]] static std::optional<StorageImageLocation> FromSerialized( [[nodiscard]] static std::optional<StorageImageLocation> FromSerialized(
const QByteArray &serialized); const QByteArray &serialized);
[[nodiscard]] StorageImageLocation convertToModern( [[nodiscard]] StorageImageLocation convertToModernPeerPhoto(
StorageFileLocation::Type type,
uint64 id, uint64 id,
uint64 accessHash) const { uint64 accessHash,
uint64 photoId) const {
return StorageImageLocation( return StorageImageLocation(
_file.convertToModern(type, id, accessHash), _file.convertToModernPeerPhoto(id, accessHash, photoId),
_width, _width,
_height); _height);
} }
@ -461,10 +461,10 @@ public:
[[nodiscard]] static std::optional<DownloadLocation> FromSerialized( [[nodiscard]] static std::optional<DownloadLocation> FromSerialized(
const QByteArray &serialized); const QByteArray &serialized);
[[nodiscard]] DownloadLocation convertToModern( [[nodiscard]] DownloadLocation convertToModernPeerPhoto(
StorageFileLocation::Type type,
uint64 id, uint64 id,
uint64 accessHash) const; uint64 accessHash,
uint64 photoId) const;
[[nodiscard]] Storage::Cache::Key cacheKey() const; [[nodiscard]] Storage::Cache::Key cacheKey() const;
[[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const; [[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const;
@ -524,12 +524,12 @@ public:
[[nodiscard]] static std::optional<ImageLocation> FromSerialized( [[nodiscard]] static std::optional<ImageLocation> FromSerialized(
const QByteArray &serialized); const QByteArray &serialized);
[[nodiscard]] ImageLocation convertToModern( [[nodiscard]] ImageLocation convertToModernPeerPhoto(
StorageFileLocation::Type type,
uint64 id, uint64 id,
uint64 accessHash) const { uint64 accessHash,
uint64 photoId) const {
return ImageLocation( return ImageLocation(
_file.convertToModern(type, id, accessHash), _file.convertToModernPeerPhoto(id, accessHash, photoId),
_width, _width,
_height); _height);
} }