From b92223a61c224843ab4cdf0d7b6893f5cb219c4a Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 Jun 2019 19:17:31 +0300 Subject: [PATCH] Remove OfflineInputPeer. GitOrigin-RevId: 1a3706ab5c923ba3dfb065c642e103fd9df688c9 --- td/telegram/Photo.cpp | 7 ++++--- td/telegram/Photo.h | 34 +++++++++++++------------------- td/telegram/Photo.hpp | 17 ++++++++-------- td/telegram/files/FileLocation.h | 2 +- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index e0bd62827..3131b4f01 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -30,7 +30,7 @@ namespace td { -tl_object_ptr OfflineInputPeer::get_input_peer() const { +tl_object_ptr PhotoSizeSource::DialogPhoto::get_input_peer() const { switch (dialog_id.get_type()) { case DialogType::User: { UserId user_id = dialog_id.get_user_id(); @@ -60,8 +60,8 @@ bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) { } 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 && + 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().is_big == rhs.dialog_photo().is_big; case PhotoSizeSource::Type::StickerSetThumbnail: return lhs.sticker_set_thumbnail().sticker_set_id == rhs.sticker_set_thumbnail().sticker_set_id && @@ -69,6 +69,7 @@ bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) { case PhotoSizeSource::Type::Thumbnail: return lhs.thumbnail().thumbnail_type == rhs.thumbnail().thumbnail_type; case PhotoSizeSource::Type::Empty: + default: return true; } } diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 937c01183..27d1704dc 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -47,23 +47,6 @@ struct PhotoSize { FileId file_id; }; -struct OfflineInputPeer { - DialogId dialog_id; - int64 dialog_access_hash = 0; - - OfflineInputPeer() = default; - OfflineInputPeer(DialogId dialog_id, int64 dialog_access_hash) - : dialog_id(dialog_id), dialog_access_hash(dialog_access_hash) { - } - - tl_object_ptr get_input_peer() const; - - template - void store(StorerT &storer) const; - template - void parse(ParserT &parser); -}; - struct PhotoSizeSource { enum class Type : int32 { Empty, Thumbnail, DialogPhoto, StickerSetThumbnail }; Type type; @@ -76,15 +59,26 @@ struct PhotoSizeSource { } int32 thumbnail_type = 0; }; + // for dialog photos struct DialogPhoto { DialogPhoto() = default; - DialogPhoto(OfflineInputPeer input_peer, bool is_big) : input_peer(input_peer), is_big(is_big) { + DialogPhoto(DialogId dialog_id, int64 dialog_access_hash, bool is_big) + : dialog_id(dialog_id), dialog_access_hash(dialog_access_hash), is_big(is_big) { } - OfflineInputPeer input_peer; + tl_object_ptr get_input_peer() const; + + DialogId dialog_id; + int64 dialog_access_hash = 0; bool is_big = false; + + template + void store(StorerT &storer) const; + template + void parse(ParserT &parser); }; + // for sticker set thumbnails struct StickerSetThumbnail { int64 sticker_set_id = 0; @@ -114,7 +108,7 @@ struct PhotoSizeSource { PhotoSizeSource(DialogId dialog_id, int64 dialog_access_hash, bool is_big) : type(Type::DialogPhoto) , file_type(FileType::ProfilePhoto) - , variant(DialogPhoto(OfflineInputPeer(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) diff --git a/td/telegram/Photo.hpp b/td/telegram/Photo.hpp index de46e0ef4..98d288ec4 100644 --- a/td/telegram/Photo.hpp +++ b/td/telegram/Photo.hpp @@ -32,17 +32,20 @@ void PhotoSizeSource::StickerSetThumbnail::parse(ParserT &parser) { } template -void OfflineInputPeer::store(StorerT &storer) const { +void PhotoSizeSource::DialogPhoto::store(StorerT &storer) const { using td::store; store(dialog_id, storer); store(dialog_access_hash, storer); + store(is_big, storer); } template -void OfflineInputPeer::parse(ParserT &parser) { +void PhotoSizeSource::DialogPhoto::parse(ParserT &parser) { using td::parse; parse(dialog_id, parser); parse(dialog_access_hash, parser); + parse(is_big, parser); + switch (dialog_id.get_type()) { case DialogType::SecretChat: case DialogType::None: @@ -59,12 +62,9 @@ void PhotoSizeSource::store(StorerT &storer) const { store(file_type, storer); store(type, storer); switch (type) { - case Type::DialogPhoto: { - auto &dialog_photo = this->dialog_photo(); - store(dialog_photo.input_peer, storer); - store(dialog_photo.is_big, storer); + case Type::DialogPhoto: + store(dialog_photo(), storer); break; - } case Type::StickerSetThumbnail: store(sticker_set_thumbnail(), storer); break; @@ -86,8 +86,7 @@ void PhotoSizeSource::parse(ParserT &parser) { switch (type) { case Type::DialogPhoto: { DialogPhoto dialog_photo; - parse(dialog_photo.input_peer, parser); - parse(dialog_photo.is_big, parser); + parse(dialog_photo, parser); variant = dialog_photo; break; } diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 422f58dbf..f8996f26a 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -418,7 +418,7 @@ class FullRemoteFileLocation { auto &dialog_photo = photo().source_.dialog_photo(); return make_tl_object( dialog_photo.is_big * telegram_api::inputPeerPhotoFileLocation::Flags::BIG_MASK, dialog_photo.is_big, - dialog_photo.input_peer.get_input_peer(), photo().volume_id_, photo().local_id_); + dialog_photo.get_input_peer(), photo().volume_id_, photo().local_id_); } case PhotoSizeSource::Type::StickerSetThumbnail: { auto &sticker_set_thumbnail = photo().source_.sticker_set_thumbnail();