From 984ccd3d75e7a6d2fc3f0782f81b3e7ccb6ace26 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 Jun 2019 18:40:46 +0300 Subject: [PATCH] Update remote location when source is changed. GitOrigin-RevId: fc2f41f1f47cc65b5aadbec14a302d8ab2d03d5f --- td/telegram/Photo.cpp | 25 +++++++++++++++++++++++++ td/telegram/Photo.h | 4 +++- td/telegram/files/FileLocation.h | 17 +++++++++++++++++ td/telegram/files/FileManager.cpp | 6 ++++-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 69f1d2eb..9297e3c9 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -54,6 +54,31 @@ tl_object_ptr OfflineInputPeer::get_input_peer() const } } +bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) { + if (lhs.type != rhs.type || lhs.file_type != rhs.file_type) { + return false; + } + switch (lhs.type) { + case PhotoSizeSource::Type::DialogPhoto: + return lhs.dialog_photo().input_peer.dialog_id == rhs.dialog_photo().input_peer.dialog_id && + lhs.dialog_photo().input_peer.dialog_access_hash == rhs.dialog_photo().input_peer.dialog_access_hash && + lhs.dialog_photo().is_big == rhs.dialog_photo().is_big; + case PhotoSizeSource::Type::StickerSetThumbnail: + return lhs.sticker_set_thumbnail().input_sticker_set.sticker_set_id == + rhs.sticker_set_thumbnail().input_sticker_set.sticker_set_id && + lhs.sticker_set_thumbnail().input_sticker_set.sticker_set_access_hash == + rhs.sticker_set_thumbnail().input_sticker_set.sticker_set_access_hash; + case PhotoSizeSource::Type::Thumbnail: + return lhs.thumbnail().thumbnail_type == rhs.thumbnail().thumbnail_type; + case PhotoSizeSource::Type::Empty: + return true; + } +} + +bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) { + return !(lhs == rhs); +} + static uint16 get_dimension(int32 size) { if (size < 0 || size > 65535) { LOG(ERROR) << "Wrong image dimension = " << size; diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 004f0b07..66d34f85 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -115,7 +115,6 @@ struct PhotoSizeSource { PhotoSizeSource() : type(Type::Empty), file_type(FileType::None) { } - PhotoSizeSource(FileType file_type, int32 thumbnail_type) : type(Type::Thumbnail), file_type(file_type), variant(Thumbnail(thumbnail_type)) { } @@ -149,6 +148,9 @@ struct PhotoSizeSource { void parse(ParserT &parser); }; +bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs); +bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs); + struct Photo { int64 id = 0; int32 date = 0; diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index cbdd05f1..3c693f10 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -318,6 +318,21 @@ class FullRemoteFileLocation { return 0; } } + + PhotoSizeSource get_source() const { + switch (location_type()) { + case LocationType::Photo: + return photo().source_; + case LocationType::Common: + case LocationType::Web: + return PhotoSizeSource(); + case LocationType::None: + default: + UNREACHABLE(); + return PhotoSizeSource(); + } + } + void clear_file_reference() { file_reference_.clear(); } @@ -329,9 +344,11 @@ class FullRemoteFileLocation { } return false; } + bool has_file_reference() const { return file_reference_ != FileReferenceView::invalid_file_reference(); } + Slice get_file_reference() const { return file_reference_; } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index e1b7171f..d015e238 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -203,7 +203,8 @@ void FileNode::set_new_remote_location(NewRemoteFileLocation new_remote) { if (new_remote.full) { if (remote_.full && remote_.full.value() == new_remote.full.value()) { if (remote_.full.value().get_access_hash() != new_remote.full.value().get_access_hash() || - remote_.full.value().get_file_reference() != new_remote.full.value().get_file_reference()) { + remote_.full.value().get_file_reference() != new_remote.full.value().get_file_reference() || + remote_.full.value().get_source() != new_remote.full.value().get_source()) { on_pmc_changed(); } } else { @@ -1148,7 +1149,8 @@ static int merge_choose_remote_location(const FullRemoteFileLocation &x, FileLoc return merge_choose_file_source_location(x_source, y_source); } } - if (x.get_access_hash() != y.get_access_hash() && (x_source != y_source || x.is_web() || x.get_id() == y.get_id())) { + if ((x.get_access_hash() != y.get_access_hash() || x.get_source() != y.get_source()) && + (x_source != y_source || x.is_web() || x.get_id() == y.get_id())) { return merge_choose_file_source_location(x_source, y_source); } return 2;