Move file_type inside PhotoSizeSource::Thumbnail.
GitOrigin-RevId: 0cf016d083bbd39d2a7abf7e2e1c267b4af29e90
This commit is contained in:
parent
b92223a61c
commit
c38180f014
@ -54,11 +54,29 @@ tl_object_ptr<telegram_api::InputPeer> PhotoSizeSource::DialogPhoto::get_input_p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileType get_photo_size_source_file_type(const PhotoSizeSource &source) {
|
||||||
|
switch (source.type) {
|
||||||
|
case PhotoSizeSource::Type::Thumbnail:
|
||||||
|
return source.thumbnail().file_type;
|
||||||
|
case PhotoSizeSource::Type::DialogPhoto:
|
||||||
|
return FileType::ProfilePhoto;
|
||||||
|
case PhotoSizeSource::Type::StickerSetThumbnail:
|
||||||
|
return FileType::Thumbnail;
|
||||||
|
case PhotoSizeSource::Type::Empty:
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return FileType::Thumbnail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
|
bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
|
||||||
if (lhs.type != rhs.type || lhs.file_type != rhs.file_type) {
|
if (lhs.type != rhs.type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (lhs.type) {
|
switch (lhs.type) {
|
||||||
|
case PhotoSizeSource::Type::Thumbnail:
|
||||||
|
return lhs.thumbnail().file_type == rhs.thumbnail().file_type &&
|
||||||
|
lhs.thumbnail().thumbnail_type == rhs.thumbnail().thumbnail_type;
|
||||||
case PhotoSizeSource::Type::DialogPhoto:
|
case PhotoSizeSource::Type::DialogPhoto:
|
||||||
return lhs.dialog_photo().dialog_id == rhs.dialog_photo().dialog_id &&
|
return lhs.dialog_photo().dialog_id == rhs.dialog_photo().dialog_id &&
|
||||||
lhs.dialog_photo().dialog_access_hash == rhs.dialog_photo().dialog_access_hash &&
|
lhs.dialog_photo().dialog_access_hash == rhs.dialog_photo().dialog_access_hash &&
|
||||||
@ -66,8 +84,6 @@ bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
|
|||||||
case PhotoSizeSource::Type::StickerSetThumbnail:
|
case PhotoSizeSource::Type::StickerSetThumbnail:
|
||||||
return lhs.sticker_set_thumbnail().sticker_set_id == rhs.sticker_set_thumbnail().sticker_set_id &&
|
return lhs.sticker_set_thumbnail().sticker_set_id == rhs.sticker_set_thumbnail().sticker_set_id &&
|
||||||
lhs.sticker_set_thumbnail().sticker_set_access_hash == rhs.sticker_set_thumbnail().sticker_set_access_hash;
|
lhs.sticker_set_thumbnail().sticker_set_access_hash == rhs.sticker_set_thumbnail().sticker_set_access_hash;
|
||||||
case PhotoSizeSource::Type::Thumbnail:
|
|
||||||
return lhs.thumbnail().thumbnail_type == rhs.thumbnail().thumbnail_type;
|
|
||||||
case PhotoSizeSource::Type::Empty:
|
case PhotoSizeSource::Type::Empty:
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
@ -153,9 +169,9 @@ static FileId register_photo(FileManager *file_manager, const PhotoSizeSource &s
|
|||||||
bool is_png = false) {
|
bool is_png = false) {
|
||||||
int32 local_id = location->local_id_;
|
int32 local_id = location->local_id_;
|
||||||
int64 volume_id = location->volume_id_;
|
int64 volume_id = location->volume_id_;
|
||||||
LOG(DEBUG) << "Receive " << (is_webp ? "webp" : (is_png ? "png" : "jpeg")) << " photo of type " << source.file_type
|
LOG(DEBUG) << "Receive " << (is_webp ? "webp" : (is_png ? "png" : "jpeg")) << " photo of type "
|
||||||
<< " in [" << dc_id << "," << volume_id << "," << local_id << "]. Id: (" << id << ", " << access_hash
|
<< get_photo_size_source_file_type(source) << " in [" << dc_id << "," << volume_id << "," << local_id
|
||||||
<< ")";
|
<< "]. Id: (" << id << ", " << access_hash << ")";
|
||||||
auto suggested_name = PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id)
|
auto suggested_name = PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id)
|
||||||
<< (is_webp ? ".webp" : (is_png ? ".png" : ".jpg"));
|
<< (is_webp ? ".webp" : (is_png ? ".png" : ".jpg"));
|
||||||
auto file_location_source = owner_dialog_id.get_type() == DialogType::SecretChat ? FileLocationSource::FromUser
|
auto file_location_source = owner_dialog_id.get_type() == DialogType::SecretChat ? FileLocationSource::FromUser
|
||||||
|
@ -50,14 +50,20 @@ struct PhotoSize {
|
|||||||
struct PhotoSizeSource {
|
struct PhotoSizeSource {
|
||||||
enum class Type : int32 { Empty, Thumbnail, DialogPhoto, StickerSetThumbnail };
|
enum class Type : int32 { Empty, Thumbnail, DialogPhoto, StickerSetThumbnail };
|
||||||
Type type;
|
Type type;
|
||||||
FileType file_type;
|
|
||||||
|
|
||||||
// for photos, document thumbnails, encrypted thumbnails
|
// for photos, document thumbnails, encrypted thumbnails
|
||||||
struct Thumbnail {
|
struct Thumbnail {
|
||||||
Thumbnail() = default;
|
Thumbnail() = default;
|
||||||
explicit Thumbnail(int32 thumbnail_type) : thumbnail_type(thumbnail_type) {
|
Thumbnail(FileType file_type, int32 thumbnail_type) : thumbnail_type(thumbnail_type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileType file_type;
|
||||||
int32 thumbnail_type = 0;
|
int32 thumbnail_type = 0;
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void store(StorerT &storer) const;
|
||||||
|
template <class ParserT>
|
||||||
|
void parse(ParserT &parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
// for dialog photos
|
// for dialog photos
|
||||||
@ -100,20 +106,16 @@ struct PhotoSizeSource {
|
|||||||
};
|
};
|
||||||
Variant<Thumbnail, DialogPhoto, StickerSetThumbnail> variant;
|
Variant<Thumbnail, DialogPhoto, StickerSetThumbnail> variant;
|
||||||
|
|
||||||
PhotoSizeSource() : type(Type::Empty), file_type(FileType::None) {
|
PhotoSizeSource() : type(Type::Empty) {
|
||||||
}
|
}
|
||||||
PhotoSizeSource(FileType file_type, int32 thumbnail_type)
|
PhotoSizeSource(FileType file_type, int32 thumbnail_type)
|
||||||
: type(Type::Thumbnail), file_type(file_type), variant(Thumbnail(thumbnail_type)) {
|
: type(Type::Thumbnail), variant(Thumbnail(file_type, thumbnail_type)) {
|
||||||
}
|
}
|
||||||
PhotoSizeSource(DialogId dialog_id, int64 dialog_access_hash, bool is_big)
|
PhotoSizeSource(DialogId dialog_id, int64 dialog_access_hash, bool is_big)
|
||||||
: type(Type::DialogPhoto)
|
: type(Type::DialogPhoto), variant(DialogPhoto(dialog_id, dialog_access_hash, is_big)) {
|
||||||
, file_type(FileType::ProfilePhoto)
|
|
||||||
, variant(DialogPhoto(dialog_id, dialog_access_hash, is_big)) {
|
|
||||||
}
|
}
|
||||||
PhotoSizeSource(int64 sticker_set_id, int64 sticker_set_access_hash)
|
PhotoSizeSource(int64 sticker_set_id, int64 sticker_set_access_hash)
|
||||||
: type(Type::StickerSetThumbnail)
|
: type(Type::StickerSetThumbnail), variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) {
|
||||||
, file_type(FileType::Thumbnail)
|
|
||||||
, variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thumbnail &thumbnail() {
|
Thumbnail &thumbnail() {
|
||||||
@ -135,9 +137,6 @@ struct PhotoSizeSource {
|
|||||||
void parse(ParserT &parser);
|
void parse(ParserT &parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
||||||
bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
||||||
|
|
||||||
struct Photo {
|
struct Photo {
|
||||||
int64 id = 0;
|
int64 id = 0;
|
||||||
int32 date = 0;
|
int32 date = 0;
|
||||||
@ -148,6 +147,11 @@ struct Photo {
|
|||||||
vector<FileId> sticker_file_ids;
|
vector<FileId> sticker_file_ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FileType get_photo_size_source_file_type(const PhotoSizeSource &source);
|
||||||
|
|
||||||
|
bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
||||||
|
bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
||||||
|
|
||||||
Dimensions get_dimensions(int32 width, int32 height);
|
Dimensions get_dimensions(int32 width, int32 height);
|
||||||
|
|
||||||
bool operator==(const Dimensions &lhs, const Dimensions &rhs);
|
bool operator==(const Dimensions &lhs, const Dimensions &rhs);
|
||||||
|
@ -13,10 +13,25 @@
|
|||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/tl_helpers.h"
|
#include "td/utils/tl_helpers.h"
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void PhotoSizeSource::Thumbnail::store(StorerT &storer) const {
|
||||||
|
using td::store;
|
||||||
|
store(file_type, storer);
|
||||||
|
store(thumbnail_type, storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void PhotoSizeSource::Thumbnail::parse(ParserT &parser) {
|
||||||
|
using td::parse;
|
||||||
|
parse(file_type, parser);
|
||||||
|
parse(thumbnail_type, parser);
|
||||||
|
if (thumbnail_type < 0 || thumbnail_type > 255) {
|
||||||
|
parser.set_error("Wrong thumbnail type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
void PhotoSizeSource::StickerSetThumbnail::store(StorerT &storer) const {
|
void PhotoSizeSource::StickerSetThumbnail::store(StorerT &storer) const {
|
||||||
using td::store;
|
using td::store;
|
||||||
@ -59,20 +74,17 @@ void PhotoSizeSource::DialogPhoto::parse(ParserT &parser) {
|
|||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
void PhotoSizeSource::store(StorerT &storer) const {
|
void PhotoSizeSource::store(StorerT &storer) const {
|
||||||
using td::store;
|
using td::store;
|
||||||
store(file_type, storer);
|
|
||||||
store(type, storer);
|
store(type, storer);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case Type::Thumbnail:
|
||||||
|
store(thumbnail(), storer);
|
||||||
|
break;
|
||||||
case Type::DialogPhoto:
|
case Type::DialogPhoto:
|
||||||
store(dialog_photo(), storer);
|
store(dialog_photo(), storer);
|
||||||
break;
|
break;
|
||||||
case Type::StickerSetThumbnail:
|
case Type::StickerSetThumbnail:
|
||||||
store(sticker_set_thumbnail(), storer);
|
store(sticker_set_thumbnail(), storer);
|
||||||
break;
|
break;
|
||||||
case Type::Thumbnail: {
|
|
||||||
auto &thumbnail = this->thumbnail();
|
|
||||||
store(thumbnail.thumbnail_type, storer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Type::Empty:
|
case Type::Empty:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -81,9 +93,14 @@ void PhotoSizeSource::store(StorerT &storer) const {
|
|||||||
template <class ParserT>
|
template <class ParserT>
|
||||||
void PhotoSizeSource::parse(ParserT &parser) {
|
void PhotoSizeSource::parse(ParserT &parser) {
|
||||||
using td::parse;
|
using td::parse;
|
||||||
parse(file_type, parser);
|
|
||||||
parse(type, parser);
|
parse(type, parser);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case Type::Thumbnail: {
|
||||||
|
Thumbnail thumbnail;
|
||||||
|
parse(thumbnail, parser);
|
||||||
|
variant = thumbnail;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Type::DialogPhoto: {
|
case Type::DialogPhoto: {
|
||||||
DialogPhoto dialog_photo;
|
DialogPhoto dialog_photo;
|
||||||
parse(dialog_photo, parser);
|
parse(dialog_photo, parser);
|
||||||
@ -96,15 +113,6 @@ void PhotoSizeSource::parse(ParserT &parser) {
|
|||||||
variant = sticker_set_thumbnail;
|
variant = sticker_set_thumbnail;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Type::Thumbnail: {
|
|
||||||
Thumbnail thumbnail;
|
|
||||||
parse(thumbnail.thumbnail_type, parser);
|
|
||||||
if (thumbnail.thumbnail_type < 0 || thumbnail.thumbnail_type > std::numeric_limits<uint8>::max()) {
|
|
||||||
parser.set_error("Wrong thumbnail type");
|
|
||||||
}
|
|
||||||
variant = thumbnail;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Type::Empty:
|
case Type::Empty:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ class FullRemoteFileLocation {
|
|||||||
photo().secret_, BufferSlice(file_reference_));
|
photo().secret_, BufferSlice(file_reference_));
|
||||||
case PhotoSizeSource::Type::Thumbnail: {
|
case PhotoSizeSource::Type::Thumbnail: {
|
||||||
auto &thumbnail = photo().source_.thumbnail();
|
auto &thumbnail = photo().source_.thumbnail();
|
||||||
switch (file_type_) {
|
switch (thumbnail.file_type) {
|
||||||
case FileType::Photo:
|
case FileType::Photo:
|
||||||
return make_tl_object<telegram_api::inputPhotoFileLocation>(
|
return make_tl_object<telegram_api::inputPhotoFileLocation>(
|
||||||
photo().id_, photo().access_hash_, BufferSlice(file_reference_),
|
photo().id_, photo().access_hash_, BufferSlice(file_reference_),
|
||||||
@ -475,7 +475,7 @@ class FullRemoteFileLocation {
|
|||||||
// photo
|
// photo
|
||||||
FullRemoteFileLocation(const PhotoSizeSource &source, int64 id, int64 access_hash, int32 local_id, int64 volume_id,
|
FullRemoteFileLocation(const PhotoSizeSource &source, int64 id, int64 access_hash, int32 local_id, int64 volume_id,
|
||||||
DcId dc_id, std::string file_reference)
|
DcId dc_id, std::string file_reference)
|
||||||
: file_type_(source.file_type)
|
: file_type_(get_photo_size_source_file_type(source))
|
||||||
, dc_id_(dc_id)
|
, dc_id_(dc_id)
|
||||||
, file_reference_(std::move(file_reference))
|
, file_reference_(std::move(file_reference))
|
||||||
, variant_(PhotoRemoteFileLocation{id, access_hash, volume_id, 0, local_id, source}) {
|
, variant_(PhotoRemoteFileLocation{id, access_hash, volume_id, 0, local_id, source}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user