diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index da2879d4c..5cde0f73c 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -571,16 +571,16 @@ class UploadProfilePhotoQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - if (file_id_.is_valid()) { - td_->file_manager_->delete_partial_remote_location(file_id_); - } - if (!only_suggest_) { td_->contacts_manager_->on_set_profile_photo(user_id_, result_ptr.move_as_ok(), is_fallback_, 0, std::move(promise_)); } else { promise_.set_value(Unit()); } + + if (file_id_.is_valid()) { + td_->file_manager_->delete_partial_remote_location(file_id_); + } } void on_error(Status status) final { diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 42ac997c2..7d748cb22 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -989,11 +989,11 @@ class InitHistoryImportQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - td_->file_manager_->delete_partial_remote_location(file_id_); - auto ptr = result_ptr.move_as_ok(); td_->messages_manager_->start_import_messages(dialog_id_, ptr->id_, std::move(attached_file_ids_), std::move(promise_)); + + td_->file_manager_->delete_partial_remote_location(file_id_); } void on_error(Status status) final { @@ -1005,7 +1005,6 @@ class InitHistoryImportQuery final : public Td::ResultHandler { } td_->file_manager_->delete_partial_remote_location(file_id_); - td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "InitHistoryImportQuery"); promise_.set_error(std::move(status)); } @@ -1043,11 +1042,11 @@ class UploadImportedMediaQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - td_->file_manager_->delete_partial_remote_location(file_id_); - // ignore response promise_.set_value(Unit()); + + td_->file_manager_->delete_partial_remote_location(file_id_); } void on_error(Status status) final { @@ -1148,11 +1147,11 @@ class EditDialogPhotoQuery final : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditDialogPhotoQuery: " << to_string(ptr); + td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); + if (file_id_.is_valid() && was_uploaded_) { td_->file_manager_->delete_partial_remote_location(file_id_); } - - td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(Status status) final { @@ -3614,17 +3613,16 @@ class SendMediaQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - if (was_thumbnail_uploaded_) { - CHECK(thumbnail_file_id_.is_valid()); - // always delete partial remote location for the thumbnail, because it can't be reused anyway - // TODO delete it only in the case it can't be merged with file thumbnail - td_->file_manager_->delete_partial_remote_location(thumbnail_file_id_); - } - auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for SendMediaQuery for " << random_id_ << ": " << to_string(ptr); td_->messages_manager_->check_send_message_result(random_id_, dialog_id_, ptr.get(), "SendMedia"); td_->updates_manager_->on_get_updates(std::move(ptr), Promise()); + + if (was_thumbnail_uploaded_) { + CHECK(thumbnail_file_id_.is_valid()); + // always delete partial remote location for the thumbnail, because it can't be reused anyway + td_->file_manager_->delete_partial_remote_location(thumbnail_file_id_); + } } void on_error(Status status) final { diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index e376d95e0..ac6a26a0e 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -73,11 +73,11 @@ class UploadRingtoneQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - td_->file_manager_->delete_partial_remote_location(file_id_); - auto result = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for UploadRingtoneQuery: " << to_string(result); promise_.set_value(std::move(result)); + + td_->file_manager_->delete_partial_remote_location(file_id_); } void on_error(Status status) final { diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index a91677174..31220c612 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -291,6 +291,12 @@ void FileNode::delete_partial_remote_location() { remote_.partial.reset(); on_changed(); } + if (remote_.ready_size != 0) { + VLOG(update_file) << "File " << main_file_id_ << " has changed remote ready size from " << remote_.ready_size + << " to " << 0; + remote_.ready_size = 0; + on_info_changed(); + } } void FileNode::set_partial_remote_location(PartialRemoteFileLocation remote, int64 ready_size) {