Update remote location when source is changed.

GitOrigin-RevId: fc2f41f1f47cc65b5aadbec14a302d8ab2d03d5f
This commit is contained in:
levlam 2019-06-18 18:40:46 +03:00
parent ff3164ff04
commit 984ccd3d75
4 changed files with 49 additions and 3 deletions

View File

@ -54,6 +54,31 @@ tl_object_ptr<telegram_api::InputPeer> 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;

View File

@ -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;

View File

@ -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_;
}

View File

@ -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;