From 173ba06d622439f850531a833eb15190d6cc5aeb Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 25 May 2023 15:46:04 +0300 Subject: [PATCH] Support FILE_PART_MISSING errors for stories. --- td/telegram/StoryManager.cpp | 30 ++++++++++----- td/telegram/StoryManager.h | 71 ++++++++++++++++++------------------ 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 8b20d2830..37d3e464c 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -186,7 +186,13 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler { return; } - td_->file_manager_->delete_partial_remote_location(file_id_); + if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { + td_->story_manager_->on_send_story_file_part_missing(std::move(pending_story_), + to_integer(status.message().substr(10))); + return; + } else { + td_->file_manager_->delete_partial_remote_location(file_id_); + } } }; @@ -551,17 +557,17 @@ void StoryManager::send_story(td_api::object_ptr &&in random_id = Random::secure_int64(); } while (random_id == 0); - // auto log_event_id = save_send_story_log_event(dialog_id, random_id, story.get()); + auto story_ptr = story.get(); - do_send_story(dialog_id, StoryId(), 0 /*log_event_id*/, ++send_story_count_, random_id, std::move(story), {}, - std::move(promise)); + do_send_story(dialog_id, StoryId(), 0 /*log_event_id*/, ++send_story_count_, random_id, std::move(story), {}); + + promise.set_value(get_story_object({dialog_id, StoryId()}, story_ptr)); } void StoryManager::do_send_story(DialogId dialog_id, StoryId story_id, uint64 log_event_id, uint32 send_story_num, - int64 random_id, unique_ptr &&story, vector bad_parts, - Promise> &&promise) { - auto story_ptr = story.get(); - auto content = story_ptr->content_.get(); + int64 random_id, unique_ptr &&story, vector bad_parts) { + CHECK(story != nullptr); + auto content = story->content_.get(); CHECK(content != nullptr); FileId file_id = get_story_content_any_file_id(td_, content); @@ -575,8 +581,6 @@ void StoryManager::do_send_story(DialogId dialog_id, StoryId story_id, uint64 lo // need to call resume_upload synchronously to make upload process consistent with being_uploaded_files_ // and to send is_uploading_active == true in response td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_media_callback_, 1, send_story_num); - - promise.set_value(get_story_object({dialog_id, story_id}, story_ptr)); } void StoryManager::on_upload_story(FileId file_id, telegram_api::object_ptr input_file) { @@ -623,4 +627,10 @@ void StoryManager::on_upload_story_error(FileId file_id, Status status) { being_uploaded_files_.erase(it); } +void StoryManager::on_send_story_file_part_missing(unique_ptr &&pending_story, int bad_part) { + do_send_story(pending_story->dialog_id_, pending_story->story_id_, pending_story->log_event_id_, + pending_story->send_story_num_, pending_story->random_id_, std::move(pending_story->story_), + {bad_part}); +} + } // namespace td diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 675e3b6c1..8f1dfd880 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -31,39 +31,6 @@ class StoryContent; class Td; class StoryManager final : public Actor { - public: - StoryManager(Td *td, ActorShared<> parent); - StoryManager(const StoryManager &) = delete; - StoryManager &operator=(const StoryManager &) = delete; - StoryManager(StoryManager &&) = delete; - StoryManager &operator=(StoryManager &&) = delete; - ~StoryManager() final; - - void send_story(td_api::object_ptr &&input_story_content, - td_api::object_ptr &&input_caption, - td_api::object_ptr &&rules, bool is_pinned, - Promise> &&promise); - - void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, - Promise> &&promise); - - void get_dialog_expiring_stories(DialogId owner_dialog_id, Promise> &&promise); - - StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item); - - std::pair> on_get_stories(DialogId owner_dialog_id, - telegram_api::object_ptr &&stories); - - td_api::object_ptr get_story_object(StoryFullId story_full_id) const; - - td_api::object_ptr get_stories_object(int32 total_count, - const vector &story_full_ids) const; - - FileSourceId get_story_file_source_id(StoryFullId story_full_id); - - void reload_story(StoryFullId story_full_id, Promise &&promise); - - private: struct Story { int32 date_ = 0; int32 expire_date_ = 0; @@ -88,6 +55,41 @@ class StoryManager final : public Actor { unique_ptr &&story); }; + public: + StoryManager(Td *td, ActorShared<> parent); + StoryManager(const StoryManager &) = delete; + StoryManager &operator=(const StoryManager &) = delete; + StoryManager(StoryManager &&) = delete; + StoryManager &operator=(StoryManager &&) = delete; + ~StoryManager() final; + + void send_story(td_api::object_ptr &&input_story_content, + td_api::object_ptr &&input_caption, + td_api::object_ptr &&rules, bool is_pinned, + Promise> &&promise); + + void on_send_story_file_part_missing(unique_ptr &&pending_story, int bad_part); + + void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, + Promise> &&promise); + + void get_dialog_expiring_stories(DialogId owner_dialog_id, Promise> &&promise); + + StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item); + + std::pair> on_get_stories(DialogId owner_dialog_id, + telegram_api::object_ptr &&stories); + + td_api::object_ptr get_story_object(StoryFullId story_full_id) const; + + td_api::object_ptr get_stories_object(int32 total_count, + const vector &story_full_ids) const; + + FileSourceId get_story_file_source_id(StoryFullId story_full_id); + + void reload_story(StoryFullId story_full_id, Promise &&promise); + + private: class UploadMediaCallback; class SendStoryQuery; @@ -122,8 +124,7 @@ class StoryManager final : public Actor { static bool is_local_story_id(StoryId story_id); void do_send_story(DialogId dialog_id, StoryId story_id, uint64 log_event_id, uint32 send_story_num, int64 random_id, - unique_ptr &&story, vector bad_parts, - Promise> &&promise); + unique_ptr &&story, vector bad_parts); void on_upload_story(FileId file_id, telegram_api::object_ptr input_file);