diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 59ecc317b..d3831b8d0 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -250,6 +250,7 @@ StoryManager::PendingStory::PendingStory(DialogId dialog_id, StoryId story_id, u , log_event_id_(log_event_id) , send_story_num_(send_story_num) , random_id_(random_id) + , was_reuploaded_(false) , story_(std::move(story)) { } @@ -627,12 +628,31 @@ void StoryManager::on_upload_story(FileId file_id, telegram_api::object_ptrsecond); being_uploaded_files_.erase(it); + FileView file_view = td_->file_manager_->get_file_view(file_id); + CHECK(!file_view.is_encrypted()); + if (input_file == nullptr && file_view.has_remote_location()) { + if (file_view.main_remote_location().is_web()) { + LOG(ERROR) << "Can't use web photo as story"; + return; + } + if (pending_story->was_reuploaded_) { + LOG(ERROR) << "Failed to reupload story"; + return; + } + pending_story->was_reuploaded_ = true; + + // delete file reference and forcely reupload the file + td_->file_manager_->delete_file_reference(file_id, file_view.main_remote_location().get_file_reference()); + do_send_story(std::move(pending_story), {-1}); + return; + } + CHECK(input_file != nullptr); + td_->create_handler()->send(file_id, std::move(pending_story), std::move(input_file)); } diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 1c36bc232..69e9e17c6 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -49,6 +49,7 @@ class StoryManager final : public Actor { uint64 log_event_id_ = 0; uint32 send_story_num_ = 0; int64 random_id_ = 0; + bool was_reuploaded_ = false; unique_ptr story_; PendingStory(DialogId dialog_id, StoryId story_id, uint64 log_event_id, uint32 send_story_num, int64 random_id, diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 8a73da915..990e3bee0 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -504,7 +504,9 @@ class FileManager final : public FileLoadManager::Callback { vector> get_input_documents(const vector &file_ids); static bool extract_was_uploaded(const tl_object_ptr &input_media); + static bool extract_was_thumbnail_uploaded(const tl_object_ptr &input_media); + static string extract_file_reference(const tl_object_ptr &input_media); static string extract_file_reference(const tl_object_ptr &input_document); @@ -512,6 +514,7 @@ class FileManager final : public FileLoadManager::Callback { static string extract_file_reference(const tl_object_ptr &input_photo); static bool extract_was_uploaded(const tl_object_ptr &input_chat_photo); + static string extract_file_reference(const tl_object_ptr &input_chat_photo); template