Add source to PhotoSizeSource::get_type.

This commit is contained in:
levlam 2021-11-14 10:47:02 +03:00
parent 6dd7c73765
commit e52508bdc1
8 changed files with 26 additions and 24 deletions

View File

@ -362,7 +362,7 @@ void FileReferenceManager::repair_file_reference(NodeId node_id, Promise<> promi
}
void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> promise) {
switch (source.get_type()) {
switch (source.get_type("reload_photo")) {
case PhotoSizeSource::Type::DialogPhotoBig:
case PhotoSizeSource::Type::DialogPhotoSmall:
case PhotoSizeSource::Type::DialogPhotoBigLegacy:

View File

@ -1727,7 +1727,7 @@ static Result<InputMessageContent> create_input_message_content(
int32 type = 'i';
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
auto photo_size_source = file_view.remote_location().get_source();
if (photo_size_source.get_type() == PhotoSizeSource::Type::Thumbnail) {
if (photo_size_source.get_type("create_input_message_content") == PhotoSizeSource::Type::Thumbnail) {
auto old_type = photo_size_source.thumbnail().thumbnail_type;
if (old_type != 't') {
type = old_type;

View File

@ -138,7 +138,8 @@ static StringBuilder &operator<<(StringBuilder &string_builder, PhotoFormat form
static FileId register_photo(FileManager *file_manager, const PhotoSizeSource &source, int64 id, int64 access_hash,
std::string file_reference, DialogId owner_dialog_id, int32 file_size, DcId dc_id,
PhotoFormat format) {
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type() << " from " << dc_id;
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type("register_photo")
<< " from " << dc_id;
auto suggested_name = PSTRING() << source.get_unique_name(id) << '.' << format;
auto file_location_source = owner_dialog_id.get_type() == DialogType::SecretChat ? FileLocationSource::FromUser
: FileLocationSource::FromServer;
@ -429,7 +430,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
res.type = 0;
}
}
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
if (source.get_type("get_photo_size") == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type;
}
@ -462,7 +463,7 @@ AnimationSize get_animation_size(FileManager *file_manager, PhotoSizeSource sour
res.main_frame_timestamp = size->video_start_ts_;
}
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
if (source.get_type("get_animation_size") == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type;
}

View File

@ -43,8 +43,8 @@ tl_object_ptr<telegram_api::InputPeer> PhotoSizeSource::DialogPhoto::get_input_p
}
}
FileType PhotoSizeSource::get_file_type() const {
switch (get_type()) {
FileType PhotoSizeSource::get_file_type(const char *source) const {
switch (get_type(source)) {
case Type::Thumbnail:
return thumbnail().file_type;
case Type::DialogPhotoSmall:
@ -68,7 +68,7 @@ string PhotoSizeSource::get_unique() const {
auto ptr = StackAllocator::alloc(16);
MutableSlice data = ptr.as_slice();
TlStorerUnsafe storer(data.ubegin());
switch (get_type()) {
switch (get_type("get_unique")) {
case Type::Legacy:
UNREACHABLE();
break;
@ -129,7 +129,7 @@ string PhotoSizeSource::get_unique() const {
}
string PhotoSizeSource::get_unique_name(int64 photo_id) const {
switch (get_type()) {
switch (get_type("get_unique_name")) {
case Type::Thumbnail:
CHECK(0 <= thumbnail().thumbnail_type && thumbnail().thumbnail_type <= 127);
return PSTRING() << photo_id << '_' << thumbnail().thumbnail_type;
@ -226,7 +226,7 @@ bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
}
StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source) {
switch (source.get_type()) {
switch (source.get_type("operator<<")) {
case PhotoSizeSource::Type::Legacy:
return string_builder << "PhotoSizeSourceLegacy[]";
case PhotoSizeSource::Type::Thumbnail:

View File

@ -11,6 +11,7 @@
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/Variant.h"
@ -177,13 +178,13 @@ struct PhotoSizeSource {
return PhotoSizeSource(StickerSetThumbnailVersion(sticker_set_id, sticker_set_access_hash, version));
}
Type get_type() const {
Type get_type(const char *source) const {
auto offset = variant_.get_offset();
CHECK(offset >= 0);
LOG_CHECK(offset >= 0) << offset << ' ' << source;
return static_cast<Type>(offset);
}
FileType get_file_type() const;
FileType get_file_type(const char *source) const;
Thumbnail &thumbnail() {
return variant_.get<Thumbnail>();

View File

@ -334,7 +334,7 @@ class FullRemoteFileLocation {
void set_source(PhotoSizeSource source) {
CHECK(is_photo());
file_type_ = source.get_file_type();
file_type_ = source.get_file_type("set_source");
photo().source_ = std::move(source);
}
@ -399,7 +399,7 @@ class FullRemoteFileLocation {
const auto &id = photo().id_;
const auto &access_hash = photo().access_hash_;
const auto &source = photo().source_;
switch (source.get_type()) {
switch (source.get_type("as_input_file_location")) {
case PhotoSizeSource::Type::Legacy:
UNREACHABLE();
break;
@ -423,7 +423,7 @@ class FullRemoteFileLocation {
case PhotoSizeSource::Type::DialogPhotoSmall:
case PhotoSizeSource::Type::DialogPhotoBig: {
auto &dialog_photo = source.dialog_photo();
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBig;
bool is_big = source.get_type("as_input_file_location 2") == PhotoSizeSource::Type::DialogPhotoBig;
return make_tl_object<telegram_api::inputPeerPhotoFileLocation>(
is_big * telegram_api::inputPeerPhotoFileLocation::BIG_MASK, false /*ignored*/,
dialog_photo.get_input_peer(), id);
@ -440,7 +440,7 @@ class FullRemoteFileLocation {
case PhotoSizeSource::Type::DialogPhotoSmallLegacy:
case PhotoSizeSource::Type::DialogPhotoBigLegacy: {
auto &dialog_photo = source.dialog_photo_legacy();
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBigLegacy;
bool is_big = source.get_type("as_input_file_location 3") == PhotoSizeSource::Type::DialogPhotoBigLegacy;
return make_tl_object<telegram_api::inputPeerPhotoFileLocationLegacy>(
is_big * telegram_api::inputPeerPhotoFileLocationLegacy::BIG_MASK, false /*ignored*/,
dialog_photo.get_input_peer(), dialog_photo.volume_id, dialog_photo.local_id);
@ -510,7 +510,7 @@ class FullRemoteFileLocation {
// photo
FullRemoteFileLocation(const PhotoSizeSource &source, int64 id, int64 access_hash, DcId dc_id,
std::string file_reference)
: file_type_(source.get_file_type())
: file_type_(source.get_file_type("FullRemoteFileLocation"))
, dc_id_(dc_id)
, file_reference_(std::move(file_reference))
, variant_(PhotoRemoteFileLocation{id, access_hash, source}) {

View File

@ -73,7 +73,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
return;
}
switch (source.get_type()) {
switch (source.get_type("PhotoRemoteFileLocation::parse")) {
case PhotoSizeSource::Type::Legacy:
source_ = PhotoSizeSource::full_legacy(volume_id, local_id, source.legacy().secret);
break;
@ -84,7 +84,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
case PhotoSizeSource::Type::DialogPhotoSmall:
case PhotoSizeSource::Type::DialogPhotoBig: {
auto &dialog_photo = source.dialog_photo();
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBig;
bool is_big = source.get_type("PhotoRemoteFileLocation::parse") == PhotoSizeSource::Type::DialogPhotoBig;
source_ = PhotoSizeSource::dialog_photo_legacy(dialog_photo.dialog_id, dialog_photo.dialog_access_hash, is_big,
volume_id, local_id);
break;
@ -106,7 +106,7 @@ template <class StorerT>
void PhotoRemoteFileLocation::AsKey::store(StorerT &storer) const {
using td::store;
auto unique = key.source_.get_unique();
switch (key.source_.get_type()) {
switch (key.source_.get_type("PhotoRemoteFileLocation::AsKey::store")) {
case PhotoSizeSource::Type::Legacy:
case PhotoSizeSource::Type::StickerSetThumbnail:
UNREACHABLE();
@ -231,12 +231,12 @@ void FullRemoteFileLocation::parse(ParserT &parser) {
if (parser.get_error() != nullptr) {
return;
}
switch (photo().source_.get_type()) {
switch (photo().source_.get_type("FullRemoteFileLocation::parse")) {
case PhotoSizeSource::Type::Legacy:
case PhotoSizeSource::Type::FullLegacy:
break;
case PhotoSizeSource::Type::Thumbnail:
if (photo().source_.get_file_type() != file_type_ ||
if (photo().source_.get_file_type("FullRemoteFileLocation::parse") != file_type_ ||
(file_type_ != FileType::Photo && file_type_ != FileType::Thumbnail &&
file_type_ != FileType::EncryptedThumbnail)) {
parser.set_error("Invalid FileType in PhotoRemoteFileLocation Thumbnail");

View File

@ -321,7 +321,7 @@ class FileView {
if (!remote_location().is_photo()) {
return false;
}
auto type = remote_location().get_source().get_type();
auto type = remote_location().get_source().get_type("may_reload_photo");
return type != PhotoSizeSource::Type::Legacy && type != PhotoSizeSource::Type::FullLegacy &&
type != PhotoSizeSource::Type::Thumbnail;
}