Remove PhotoSizeSource.type field.

GitOrigin-RevId: ef13086515430194150728f7ede427b6c87ba175
This commit is contained in:
levlam 2019-06-18 19:56:59 +03:00
parent c38180f014
commit 0a380017d4
4 changed files with 18 additions and 13 deletions

View File

@ -55,7 +55,7 @@ tl_object_ptr<telegram_api::InputPeer> PhotoSizeSource::DialogPhoto::get_input_p
}
FileType get_photo_size_source_file_type(const PhotoSizeSource &source) {
switch (source.type) {
switch (source.get_type()) {
case PhotoSizeSource::Type::Thumbnail:
return source.thumbnail().file_type;
case PhotoSizeSource::Type::DialogPhoto:
@ -70,10 +70,10 @@ FileType get_photo_size_source_file_type(const PhotoSizeSource &source) {
}
bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
if (lhs.type != rhs.type) {
if (lhs.get_type() != rhs.get_type()) {
return false;
}
switch (lhs.type) {
switch (lhs.get_type()) {
case PhotoSizeSource::Type::Thumbnail:
return lhs.thumbnail().file_type == rhs.thumbnail().file_type &&
lhs.thumbnail().thumbnail_type == rhs.thumbnail().thumbnail_type;
@ -398,7 +398,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
} else {
res.type = static_cast<uint8>(type[0]);
}
if (source.type == PhotoSizeSource::Type::Thumbnail) {
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type;
}

View File

@ -49,7 +49,6 @@ struct PhotoSize {
struct PhotoSizeSource {
enum class Type : int32 { Empty, Thumbnail, DialogPhoto, StickerSetThumbnail };
Type type;
// for photos, document thumbnails, encrypted thumbnails
struct Thumbnail {
@ -104,18 +103,19 @@ struct PhotoSizeSource {
template <class ParserT>
void parse(ParserT &parser);
};
Variant<Thumbnail, DialogPhoto, StickerSetThumbnail> variant;
PhotoSizeSource() : type(Type::Empty) {
}
PhotoSizeSource(FileType file_type, int32 thumbnail_type)
: type(Type::Thumbnail), variant(Thumbnail(file_type, thumbnail_type)) {
PhotoSizeSource() = default;
PhotoSizeSource(FileType file_type, int32 thumbnail_type) : variant(Thumbnail(file_type, thumbnail_type)) {
}
PhotoSizeSource(DialogId dialog_id, int64 dialog_access_hash, bool is_big)
: type(Type::DialogPhoto), variant(DialogPhoto(dialog_id, dialog_access_hash, is_big)) {
: variant(DialogPhoto(dialog_id, dialog_access_hash, is_big)) {
}
PhotoSizeSource(int64 sticker_set_id, int64 sticker_set_access_hash)
: type(Type::StickerSetThumbnail), variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) {
: variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) {
}
Type get_type() const {
return static_cast<Type>(variant.get_offset() + 1);
}
Thumbnail &thumbnail() {
@ -135,6 +135,9 @@ struct PhotoSizeSource {
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
private:
Variant<Thumbnail, DialogPhoto, StickerSetThumbnail> variant;
};
struct Photo {

View File

@ -74,6 +74,7 @@ void PhotoSizeSource::DialogPhoto::parse(ParserT &parser) {
template <class StorerT>
void PhotoSizeSource::store(StorerT &storer) const {
using td::store;
auto type = get_type();
store(type, storer);
switch (type) {
case Type::Thumbnail:
@ -93,6 +94,7 @@ void PhotoSizeSource::store(StorerT &storer) const {
template <class ParserT>
void PhotoSizeSource::parse(ParserT &parser) {
using td::parse;
Type type;
parse(type, parser);
switch (type) {
case Type::Thumbnail: {

View File

@ -395,7 +395,7 @@ class FullRemoteFileLocation {
tl_object_ptr<telegram_api::InputFileLocation> as_input_file_location() const {
switch (location_type()) {
case LocationType::Photo: {
switch (photo().source_.type) {
switch (photo().source_.get_type()) {
case PhotoSizeSource::Type::Empty:
return make_tl_object<telegram_api::inputFileLocation>(photo().volume_id_, photo().local_id_,
photo().secret_, BufferSlice(file_reference_));