Support story reupload in sendStory.

This commit is contained in:
levlam 2023-05-25 21:21:10 +03:00
parent cdb36baa85
commit 2684df5f01
3 changed files with 25 additions and 1 deletions

View File

@ -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_ptr<tele
// callback may be called just before the file upload was canceled
return;
}
CHECK(input_file != nullptr);
auto pending_story = std::move(it->second);
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<SendStoryQuery>()->send(file_id, std::move(pending_story), std::move(input_file));
}

View File

@ -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> story_;
PendingStory(DialogId dialog_id, StoryId story_id, uint64 log_event_id, uint32 send_story_num, int64 random_id,

View File

@ -504,7 +504,9 @@ class FileManager final : public FileLoadManager::Callback {
vector<tl_object_ptr<telegram_api::InputDocument>> get_input_documents(const vector<FileId> &file_ids);
static bool extract_was_uploaded(const tl_object_ptr<telegram_api::InputMedia> &input_media);
static bool extract_was_thumbnail_uploaded(const tl_object_ptr<telegram_api::InputMedia> &input_media);
static string extract_file_reference(const tl_object_ptr<telegram_api::InputMedia> &input_media);
static string extract_file_reference(const tl_object_ptr<telegram_api::InputDocument> &input_document);
@ -512,6 +514,7 @@ class FileManager final : public FileLoadManager::Callback {
static string extract_file_reference(const tl_object_ptr<telegram_api::InputPhoto> &input_photo);
static bool extract_was_uploaded(const tl_object_ptr<telegram_api::InputChatPhoto> &input_chat_photo);
static string extract_file_reference(const tl_object_ptr<telegram_api::InputChatPhoto> &input_chat_photo);
template <class StorerT>