diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index fb0aa1fac..a9949e7d6 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -309,8 +309,8 @@ tl_object_ptr AnimationsManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { - return make_tl_object(0, file_view.remote_location().as_input_document(), 0); + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { + return make_tl_object(0, file_view.main_remote_location().as_input_document(), 0); } if (file_view.has_url()) { return make_tl_object(0, file_view.url(), 0); @@ -362,7 +362,7 @@ SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file return SecretInputMedia{}; } if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return SecretInputMedia{}; diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index acb45a69e..df831307e 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -194,7 +194,7 @@ SecretInputMedia AudiosManager::get_secret_input_media(FileId audio_file_id, return SecretInputMedia{}; } if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return SecretInputMedia{}; @@ -225,8 +225,8 @@ tl_object_ptr AudiosManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { - return make_tl_object(0, file_view.remote_location().as_input_document(), 0); + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { + return make_tl_object(0, file_view.main_remote_location().as_input_document(), 0); } if (file_view.has_url()) { return make_tl_object(0, file_view.url(), 0); diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a99e945b5..ffdacbc3b 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4023,9 +4023,9 @@ void ContactsManager::set_profile_photo(const tl_object_ptr & FileView file_view = td_->file_manager_->get_file_view(file_id); CHECK(!file_view.is_encrypted()); - if (file_view.has_remote_location() && !file_view.remote_location().is_web()) { + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web()) { td_->create_handler(std::move(promise)) - ->send(td_->file_manager_->dup_file_id(file_id), file_view.remote_location().as_input_photo()); + ->send(td_->file_manager_->dup_file_id(file_id), file_view.main_remote_location().as_input_photo()); return; } @@ -10418,14 +10418,14 @@ void ContactsManager::on_upload_profile_photo(FileId file_id, tl_object_ptrfile_manager_->get_file_view(file_id); if (file_view.has_remote_location() && input_file == nullptr) { - if (file_view.remote_location().is_web()) { + if (file_view.main_remote_location().is_web()) { // TODO reupload promise.set_error(Status::Error(400, "Can't use web photo as profile photo")); return; } td_->create_handler(std::move(promise)) - ->send(file_id, file_view.remote_location().as_input_photo()); + ->send(file_id, file_view.main_remote_location().as_input_photo()); return; } CHECK(input_file != nullptr); diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 51ee96b17..009daf6c4 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -523,7 +523,7 @@ SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_i return SecretInputMedia{}; } if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return SecretInputMedia{}; @@ -550,8 +550,8 @@ tl_object_ptr DocumentsManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { - return make_tl_object(0, file_view.remote_location().as_input_document(), 0); + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { + return make_tl_object(0, file_view.main_remote_location().as_input_document(), 0); } if (file_view.has_url()) { return make_tl_object(0, file_view.url(), 0); diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 53313759c..68c1f128f 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -650,19 +650,19 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe if (file_view.is_encrypted()) { return promise.set_error(Status::Error(400, "Can't send encrypted file")); } - if (file_view.remote_location().is_web()) { + if (file_view.main_remote_location().is_web()) { return promise.set_error(Status::Error(400, "Can't send web file")); } if (file_type == FileType::Photo) { auto result = make_tl_object( - id, type, file_view.remote_location().as_input_photo(), std::move(inline_message)); + id, type, file_view.main_remote_location().as_input_photo(), std::move(inline_message)); results.push_back(std::move(result)); continue; } auto result = make_tl_object( - flags, id, type, title, description, file_view.remote_location().as_input_document(), + flags, id, type, title, description, file_view.main_remote_location().as_input_document(), std::move(inline_message)); results.push_back(std::move(result)); continue; diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 26f078fde..14352cb35 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2972,9 +2972,9 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo if (new_file_view.remote_location().is_web()) { LOG(ERROR) << "Have remote web photo location"; } else if (!old_file_view.has_remote_location() || - old_file_view.remote_location().get_file_reference() != + old_file_view.main_remote_location().get_file_reference() != new_file_view.remote_location().get_file_reference() || - old_file_view.remote_location().get_access_hash() != + old_file_view.main_remote_location().get_access_hash() != new_file_view.remote_location().get_access_hash()) { FileId file_id = td->file_manager_->register_remote( FullRemoteFileLocation({FileType::Photo, 'i'}, new_file_view.remote_location().get_id(), diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c71396eec..73e9e9070 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6681,12 +6681,12 @@ void MessagesManager::on_upload_dialog_photo(FileId file_id, tl_object_ptrfile_manager_->get_file_view(file_id); CHECK(!file_view.is_encrypted()); if (input_file == nullptr && file_view.has_remote_location()) { - if (file_view.remote_location().is_web()) { + if (file_view.main_remote_location().is_web()) { // TODO reupload promise.set_error(Status::Error(400, "Can't use web photo as profile photo")); return; } - auto input_photo = file_view.remote_location().as_input_photo(); + auto input_photo = file_view.main_remote_location().as_input_photo(); input_chat_photo = make_tl_object(std::move(input_photo)); } else { input_chat_photo = make_tl_object(std::move(input_file)); @@ -22210,9 +22210,9 @@ void MessagesManager::set_dialog_photo(DialogId dialog_id, const tl_object_ptrfile_manager_->get_file_view(file_id); CHECK(!file_view.is_encrypted()); - if (file_view.has_remote_location() && !file_view.remote_location().is_web()) { + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web()) { // file has already been uploaded, just send change photo request - auto input_photo = file_view.remote_location().as_input_photo(); + auto input_photo = file_view.main_remote_location().as_input_photo(); send_edit_dialog_photo_query( dialog_id, file_id, make_tl_object(std::move(input_photo)), std::move(promise)); return; diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 51e657011..db7dc4345 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -627,12 +627,13 @@ tl_object_ptr photo_get_input_media(FileManager *file_ if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { int32 flags = 0; if (ttl != 0) { flags |= telegram_api::inputMediaPhoto::TTL_SECONDS_MASK; } - return make_tl_object(flags, file_view.remote_location().as_input_photo(), ttl); + return make_tl_object(flags, file_view.main_remote_location().as_input_photo(), + ttl); } if (file_view.has_url()) { int32 flags = 0; @@ -695,8 +696,8 @@ SecretInputMedia photo_get_secret_input_media(FileManager *file_manager, const P return {}; } if (file_view.has_remote_location()) { - LOG(INFO) << "HAS REMOTE LOCATION"; - input_file = file_view.remote_location().as_input_encrypted_file(); + LOG(INFO) << "Photo has remote location"; + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (input_file == nullptr) { return {}; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 4767b7ed5..3e861c1fb 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1648,7 +1648,7 @@ SecretInputMedia StickersManager::get_secret_input_media(FileId sticker_file_id, auto file_view = td_->file_manager_->get_file_view(sticker_file_id); if (file_view.is_encrypted_secret()) { if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return {}; @@ -1715,8 +1715,8 @@ tl_object_ptr StickersManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { - return make_tl_object(0, file_view.remote_location().as_input_document(), 0); + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { + return make_tl_object(0, file_view.main_remote_location().as_input_document(), 0); } if (file_view.has_url()) { return make_tl_object(0, file_view.url(), 0); @@ -3296,12 +3296,12 @@ void StickersManager::send_get_attached_stickers_query(FileId file_id, Promise input_stickered_media; string file_reference; - if (file_view.remote_location().is_photo()) { - auto input_photo = file_view.remote_location().as_input_photo(); + if (file_view.main_remote_location().is_photo()) { + auto input_photo = file_view.main_remote_location().as_input_photo(); file_reference = input_photo->file_reference_.as_slice().str(); input_stickered_media = make_tl_object(std::move(input_photo)); } else { - auto input_document = file_view.remote_location().as_input_document(); + auto input_document = file_view.main_remote_location().as_input_document(); file_reference = input_document->file_reference_.as_slice().str(); input_stickered_media = make_tl_object(std::move(input_document)); } @@ -3429,13 +3429,13 @@ Result> StickersManager::prepare_input_file( return Status::Error(400, "Can't use encrypted file"); } - if (file_view.has_remote_location() && file_view.remote_location().is_web()) { + if (file_view.has_remote_location() && file_view.main_remote_location().is_web()) { return Status::Error(400, "Can't use web file to create a sticker"); } bool is_url = false; bool is_local = false; if (file_view.has_remote_location()) { - CHECK(file_view.remote_location().is_document()); + CHECK(file_view.main_remote_location().is_document()); } else { if (file_view.has_url()) { is_url = true; @@ -3487,7 +3487,7 @@ tl_object_ptr StickersManager::get_input_stic FileId file_id) const { FileView file_view = td_->file_manager_->get_file_view(file_id); CHECK(file_view.has_remote_location()); - auto input_document = file_view.remote_location().as_input_document(); + auto input_document = file_view.main_remote_location().as_input_document(); tl_object_ptr mask_coords; if (sticker->mask_position_ != nullptr && sticker->mask_position_->point_ != nullptr) { @@ -3808,13 +3808,13 @@ void StickersManager::set_sticker_position_in_set(const tl_object_ptrfile_manager_->get_file_view(file_id); - if (!file_view.has_remote_location() || !file_view.remote_location().is_document() || - file_view.remote_location().is_web()) { + if (!file_view.has_remote_location() || !file_view.main_remote_location().is_document() || + file_view.main_remote_location().is_web()) { return promise.set_error(Status::Error(7, "Wrong sticker file specified")); } td_->create_handler(std::move(promise)) - ->send(file_view.remote_location().as_input_document(), position); + ->send(file_view.main_remote_location().as_input_document(), position); } void StickersManager::remove_sticker_from_set(const tl_object_ptr &sticker, @@ -3826,13 +3826,13 @@ void StickersManager::remove_sticker_from_set(const tl_object_ptrfile_manager_->get_file_view(file_id); - if (!file_view.has_remote_location() || !file_view.remote_location().is_document() || - file_view.remote_location().is_web()) { + if (!file_view.has_remote_location() || !file_view.main_remote_location().is_document() || + file_view.main_remote_location().is_web()) { return promise.set_error(Status::Error(7, "Wrong sticker file specified")); } td_->create_handler(std::move(promise)) - ->send(file_view.remote_location().as_input_document()); + ->send(file_view.main_remote_location().as_input_document()); } vector StickersManager::get_attached_sticker_file_ids(const vector &int_file_ids) { diff --git a/td/telegram/VideoNotesManager.cpp b/td/telegram/VideoNotesManager.cpp index 9002454e1..cc0840d28 100644 --- a/td/telegram/VideoNotesManager.cpp +++ b/td/telegram/VideoNotesManager.cpp @@ -174,7 +174,7 @@ SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_fil return SecretInputMedia{}; } if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return SecretInputMedia{}; @@ -202,8 +202,8 @@ tl_object_ptr VideoNotesManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { - return make_tl_object(0, file_view.remote_location().as_input_document(), 0); + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { + return make_tl_object(0, file_view.main_remote_location().as_input_document(), 0); } if (file_view.has_url()) { return make_tl_object(0, file_view.url(), 0); diff --git a/td/telegram/VideosManager.cpp b/td/telegram/VideosManager.cpp index 36c85098c..67f17ce24 100644 --- a/td/telegram/VideosManager.cpp +++ b/td/telegram/VideosManager.cpp @@ -201,7 +201,7 @@ SecretInputMedia VideosManager::get_secret_input_media(FileId video_file_id, return SecretInputMedia{}; } if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return SecretInputMedia{}; @@ -228,12 +228,12 @@ tl_object_ptr VideosManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { int32 flags = 0; if (ttl != 0) { flags |= telegram_api::inputMediaDocument::TTL_SECONDS_MASK; } - return make_tl_object(flags, file_view.remote_location().as_input_document(), + return make_tl_object(flags, file_view.main_remote_location().as_input_document(), ttl); } if (file_view.has_url()) { diff --git a/td/telegram/VoiceNotesManager.cpp b/td/telegram/VoiceNotesManager.cpp index 85dfdf287..2bcd22f88 100644 --- a/td/telegram/VoiceNotesManager.cpp +++ b/td/telegram/VoiceNotesManager.cpp @@ -147,7 +147,7 @@ SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_file_id, return SecretInputMedia{}; } if (file_view.has_remote_location()) { - input_file = file_view.remote_location().as_input_encrypted_file(); + input_file = file_view.main_remote_location().as_input_encrypted_file(); } if (!input_file) { return SecretInputMedia{}; @@ -169,8 +169,8 @@ tl_object_ptr VoiceNotesManager::get_input_media( if (file_view.is_encrypted()) { return nullptr; } - if (file_view.has_remote_location() && !file_view.remote_location().is_web() && input_file == nullptr) { - return make_tl_object(0, file_view.remote_location().as_input_document(), 0); + if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { + return make_tl_object(0, file_view.main_remote_location().as_input_document(), 0); } if (file_view.has_url()) { return make_tl_object(0, file_view.url(), 0); diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 335e6608d..7f1753147 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -469,13 +469,16 @@ bool FileView::has_alive_remote_location() const { } bool FileView::has_active_upload_remote_location() const { + if (!has_remote_location()) { + return false; + } if (!has_alive_remote_location()) { return false; } - if (remote_location().is_encrypted_any()) { + if (main_remote_location().is_encrypted_any()) { return true; } - return remote_location().has_file_reference(); + return main_remote_location().has_file_reference(); } bool FileView::has_active_download_remote_location() const { @@ -497,6 +500,11 @@ const FullRemoteFileLocation &FileView::remote_location() const { return node_->remote_.full.value(); } +const FullRemoteFileLocation &FileView::main_remote_location() const { + CHECK(has_remote_location()); + return node_->remote_.full.value(); +} + bool FileView::has_generate_location() const { return node_->generate_ != nullptr; } diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index c342b108e..9ac93d3b6 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -240,6 +240,7 @@ class FileView { bool has_active_upload_remote_location() const; bool has_active_download_remote_location() const; const FullRemoteFileLocation &remote_location() const; + const FullRemoteFileLocation &main_remote_location() const; bool has_generate_location() const; const FullGenerateFileLocation &generate_location() const;