Improve delete_pending_story.
This commit is contained in:
parent
93149d09fd
commit
c19cb9b623
@ -574,9 +574,7 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler {
|
|||||||
LOG(INFO) << "Receive result for SendStoryQuery: " << to_string(ptr);
|
LOG(INFO) << "Receive result for SendStoryQuery: " << to_string(ptr);
|
||||||
td_->updates_manager_->on_get_updates(std::move(ptr), Promise<Unit>());
|
td_->updates_manager_->on_get_updates(std::move(ptr), Promise<Unit>());
|
||||||
|
|
||||||
td_->story_manager_->delete_pending_story(std::move(pending_story_));
|
td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), Status::OK());
|
||||||
|
|
||||||
td_->file_manager_->delete_partial_remote_location(file_id_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
@ -591,8 +589,7 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler {
|
|||||||
to_integer<int32>(status.message().substr(10)));
|
to_integer<int32>(status.message().substr(10)));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
td_->file_manager_->delete_partial_remote_location(file_id_);
|
td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), std::move(status));
|
||||||
td_->story_manager_->delete_pending_story(std::move(pending_story_));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -642,8 +639,8 @@ class StoryManager::EditStoryQuery final : public Td::ResultHandler {
|
|||||||
td_->updates_manager_->on_get_updates(
|
td_->updates_manager_->on_get_updates(
|
||||||
std::move(ptr), PromiseCreator::lambda([file_id = file_id_, pending_story = std::move(pending_story_)](
|
std::move(ptr), PromiseCreator::lambda([file_id = file_id_, pending_story = std::move(pending_story_)](
|
||||||
Result<Unit> &&result) mutable {
|
Result<Unit> &&result) mutable {
|
||||||
send_closure(G()->story_manager(), &StoryManager::on_story_edited, file_id, std::move(pending_story),
|
send_closure(G()->story_manager(), &StoryManager::delete_pending_story, file_id, std::move(pending_story),
|
||||||
std::move(result));
|
result.is_ok() ? Status::OK() : result.move_as_error());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +652,7 @@ class StoryManager::EditStoryQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!td_->auth_manager_->is_bot() && status.message() == "STORY_NOT_MODIFIED") {
|
if (!td_->auth_manager_->is_bot() && status.message() == "STORY_NOT_MODIFIED") {
|
||||||
return td_->story_manager_->on_story_edited(file_id_, std::move(pending_story_), Status::OK());
|
return td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), Status::OK());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) {
|
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) {
|
||||||
@ -663,7 +660,7 @@ class StoryManager::EditStoryQuery final : public Td::ResultHandler {
|
|||||||
to_integer<int32>(status.message().substr(10)));
|
to_integer<int32>(status.message().substr(10)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
td_->story_manager_->on_story_edited(file_id_, std::move(pending_story_), std::move(status));
|
td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), std::move(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2657,13 +2654,6 @@ int64 StoryManager::save_send_story_log_event(const PendingStory *pending_story)
|
|||||||
get_log_event_storer(SendStoryLogEvent(pending_story)));
|
get_log_event_storer(SendStoryLogEvent(pending_story)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryManager::delete_pending_story(unique_ptr<PendingStory> &&pending_story) {
|
|
||||||
CHECK(pending_story != nullptr);
|
|
||||||
if (pending_story->log_event_id_ != 0) {
|
|
||||||
binlog_erase(G()->td_db()->get_binlog(), pending_story->log_event_id_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StoryManager::do_send_story(unique_ptr<PendingStory> &&pending_story, vector<int> bad_parts) {
|
void StoryManager::do_send_story(unique_ptr<PendingStory> &&pending_story, vector<int> bad_parts) {
|
||||||
CHECK(pending_story != nullptr);
|
CHECK(pending_story != nullptr);
|
||||||
CHECK(pending_story->story_ != nullptr);
|
CHECK(pending_story->story_ != nullptr);
|
||||||
@ -2703,13 +2693,11 @@ void StoryManager::on_upload_story(FileId file_id, telegram_api::object_ptr<tele
|
|||||||
CHECK(!file_view.is_encrypted());
|
CHECK(!file_view.is_encrypted());
|
||||||
if (input_file == nullptr && file_view.has_remote_location()) {
|
if (input_file == nullptr && file_view.has_remote_location()) {
|
||||||
if (file_view.main_remote_location().is_web()) {
|
if (file_view.main_remote_location().is_web()) {
|
||||||
LOG(ERROR) << "Can't use web photo as story";
|
delete_pending_story(file_id, std::move(pending_story), Status::Error(400, "Can't use web photo as a story"));
|
||||||
delete_pending_story(std::move(pending_story));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pending_story->was_reuploaded_) {
|
if (pending_story->was_reuploaded_) {
|
||||||
LOG(ERROR) << "Failed to reupload story";
|
delete_pending_story(file_id, std::move(pending_story), Status::Error(500, "Failed to reupload story"));
|
||||||
delete_pending_story(std::move(pending_story));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pending_story->was_reuploaded_ = true;
|
pending_story->was_reuploaded_ = true;
|
||||||
@ -2747,12 +2735,7 @@ void StoryManager::on_upload_story_error(FileId file_id, Status status) {
|
|||||||
|
|
||||||
being_uploaded_files_.erase(it);
|
being_uploaded_files_.erase(it);
|
||||||
|
|
||||||
bool is_edit = pending_story->story_id_.is_server();
|
delete_pending_story(file_id, std::move(pending_story), std::move(status));
|
||||||
if (is_edit) {
|
|
||||||
on_story_edited(file_id, std::move(pending_story), std::move(status));
|
|
||||||
} else {
|
|
||||||
delete_pending_story(std::move(pending_story));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryManager::on_send_story_file_part_missing(unique_ptr<PendingStory> &&pending_story, int bad_part) {
|
void StoryManager::on_send_story_file_part_missing(unique_ptr<PendingStory> &&pending_story, int bad_part) {
|
||||||
@ -2836,7 +2819,6 @@ void StoryManager::do_edit_story(FileId file_id, unique_ptr<PendingStory> &&pend
|
|||||||
if (file_id.is_valid()) {
|
if (file_id.is_valid()) {
|
||||||
td_->file_manager_->cancel_upload(file_id);
|
td_->file_manager_->cancel_upload(file_id);
|
||||||
}
|
}
|
||||||
delete_pending_story(std::move(pending_story));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CHECK(story->content_ != nullptr);
|
CHECK(story->content_ != nullptr);
|
||||||
@ -2844,35 +2826,39 @@ void StoryManager::do_edit_story(FileId file_id, unique_ptr<PendingStory> &&pend
|
|||||||
it->second.get());
|
it->second.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryManager::on_story_edited(FileId file_id, unique_ptr<PendingStory> pending_story, Result<Unit> result) {
|
void StoryManager::delete_pending_story(FileId file_id, unique_ptr<PendingStory> &&pending_story, Status status) {
|
||||||
G()->ignore_result_if_closing(result);
|
|
||||||
|
|
||||||
if (file_id.is_valid()) {
|
if (file_id.is_valid()) {
|
||||||
td_->file_manager_->delete_partial_remote_location(file_id);
|
td_->file_manager_->delete_partial_remote_location(file_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK(pending_story != nullptr);
|
||||||
|
bool is_edit = pending_story->story_id_.is_server();
|
||||||
|
if (is_edit) {
|
||||||
StoryFullId story_full_id{pending_story->dialog_id_, pending_story->story_id_};
|
StoryFullId story_full_id{pending_story->dialog_id_, pending_story->story_id_};
|
||||||
const Story *story = get_story(story_full_id);
|
const Story *story = get_story(story_full_id);
|
||||||
auto it = being_edited_stories_.find(story_full_id);
|
auto it = being_edited_stories_.find(story_full_id);
|
||||||
if (story == nullptr || story->edit_generation_ != pending_story->random_id_ || it == being_edited_stories_.end()) {
|
if (story == nullptr || story->edit_generation_ != pending_story->random_id_ || it == being_edited_stories_.end()) {
|
||||||
LOG(INFO) << "Ignore outdated edit of " << story_full_id;
|
LOG(INFO) << "Ignore outdated edit of " << story_full_id;
|
||||||
delete_pending_story(std::move(pending_story));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete_pending_story(std::move(pending_story));
|
|
||||||
CHECK(story->content_ != nullptr);
|
CHECK(story->content_ != nullptr);
|
||||||
auto promises = std::move(it->second->promises_);
|
auto promises = std::move(it->second->promises_);
|
||||||
bool is_changed = it->second->content_ != nullptr ||
|
bool is_changed = it->second->content_ != nullptr ||
|
||||||
(it->second->edit_caption_ && it->second->caption_ != story->caption_) ||
|
(it->second->edit_caption_ && it->second->caption_ != story->caption_) ||
|
||||||
(result.is_error() && !story->is_edited_);
|
(status.is_error() && !story->is_edited_);
|
||||||
being_edited_stories_.erase(it);
|
being_edited_stories_.erase(it);
|
||||||
|
|
||||||
on_story_changed(story_full_id, story, is_changed, true);
|
on_story_changed(story_full_id, story, is_changed, true);
|
||||||
|
|
||||||
if (result.is_ok()) {
|
if (status.is_ok()) {
|
||||||
set_promises(promises);
|
set_promises(promises);
|
||||||
} else {
|
} else {
|
||||||
fail_promises(promises, result.move_as_error());
|
fail_promises(promises, std::move(status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pending_story->log_event_id_ != 0) {
|
||||||
|
binlog_erase(G()->td_db()->get_binlog(), pending_story->log_event_id_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ class StoryManager final : public Actor {
|
|||||||
|
|
||||||
int64 save_send_story_log_event(const PendingStory *pending_story);
|
int64 save_send_story_log_event(const PendingStory *pending_story);
|
||||||
|
|
||||||
static void delete_pending_story(unique_ptr<PendingStory> &&pending_story);
|
void delete_pending_story(FileId file_id, unique_ptr<PendingStory> &&pending_story, Status status);
|
||||||
|
|
||||||
void do_send_story(unique_ptr<PendingStory> &&pending_story, vector<int> bad_parts);
|
void do_send_story(unique_ptr<PendingStory> &&pending_story, vector<int> bad_parts);
|
||||||
|
|
||||||
@ -353,8 +353,6 @@ class StoryManager final : public Actor {
|
|||||||
void do_edit_story(FileId file_id, unique_ptr<PendingStory> &&pending_story,
|
void do_edit_story(FileId file_id, unique_ptr<PendingStory> &&pending_story,
|
||||||
telegram_api::object_ptr<telegram_api::InputFile> input_file);
|
telegram_api::object_ptr<telegram_api::InputFile> input_file);
|
||||||
|
|
||||||
void on_story_edited(FileId file_id, unique_ptr<PendingStory> pending_story, Result<Unit> result);
|
|
||||||
|
|
||||||
void on_toggle_story_is_pinned(StoryId story_id, bool is_pinned, Promise<Unit> &&promise);
|
void on_toggle_story_is_pinned(StoryId story_id, bool is_pinned, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id, vector<StoryId> &&story_ids);
|
void on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id, vector<StoryId> &&story_ids);
|
||||||
|
Loading…
Reference in New Issue
Block a user