Fix profile photo reuploading.
This commit is contained in:
parent
4a185caa74
commit
13c48e590d
@ -6179,13 +6179,13 @@ void ContactsManager::send_update_profile_photo_query(FileId file_id, int64 old_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::upload_profile_photo(FileId file_id, bool is_animation, double main_frame_timestamp,
|
void ContactsManager::upload_profile_photo(FileId file_id, bool is_animation, double main_frame_timestamp,
|
||||||
Promise<Unit> &&promise, vector<int> bad_parts) {
|
Promise<Unit> &&promise, int reupload_count, vector<int> bad_parts) {
|
||||||
CHECK(file_id.is_valid());
|
CHECK(file_id.is_valid());
|
||||||
CHECK(uploaded_profile_photos_.find(file_id) == uploaded_profile_photos_.end());
|
CHECK(uploaded_profile_photos_.find(file_id) == uploaded_profile_photos_.end());
|
||||||
uploaded_profile_photos_.emplace(
|
uploaded_profile_photos_.emplace(
|
||||||
file_id, UploadedProfilePhoto{main_frame_timestamp, is_animation, !bad_parts.empty(), std::move(promise)});
|
file_id, UploadedProfilePhoto{main_frame_timestamp, is_animation, reupload_count, std::move(promise)});
|
||||||
LOG(INFO) << "Ask to upload profile photo " << file_id;
|
LOG(INFO) << "Ask to upload profile photo " << file_id << " with bad parts " << bad_parts;
|
||||||
// TODO use force_reupload
|
// TODO use force_reupload if reupload_count >= 1, replace reupload_count with is_reupload
|
||||||
td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_profile_photo_callback_, 32, 0);
|
td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_profile_photo_callback_, 32, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15751,7 +15751,7 @@ void ContactsManager::on_upload_profile_photo(FileId file_id, tl_object_ptr<tele
|
|||||||
|
|
||||||
double main_frame_timestamp = it->second.main_frame_timestamp;
|
double main_frame_timestamp = it->second.main_frame_timestamp;
|
||||||
bool is_animation = it->second.is_animation;
|
bool is_animation = it->second.is_animation;
|
||||||
bool is_reupload = it->second.is_reupload;
|
int32 reupload_count = it->second.reupload_count;
|
||||||
auto promise = std::move(it->second.promise);
|
auto promise = std::move(it->second.promise);
|
||||||
|
|
||||||
uploaded_profile_photos_.erase(it);
|
uploaded_profile_photos_.erase(it);
|
||||||
@ -15761,7 +15761,7 @@ void ContactsManager::on_upload_profile_photo(FileId file_id, tl_object_ptr<tele
|
|||||||
if (file_view.main_remote_location().is_web()) {
|
if (file_view.main_remote_location().is_web()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't use web photo as profile photo"));
|
return promise.set_error(Status::Error(400, "Can't use web photo as profile photo"));
|
||||||
}
|
}
|
||||||
if (is_reupload) {
|
if (reupload_count == 3) { // upload, ForceReupload repair file reference, reupload
|
||||||
return promise.set_error(Status::Error(400, "Failed to reupload the file"));
|
return promise.set_error(Status::Error(400, "Failed to reupload the file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15772,10 +15772,10 @@ void ContactsManager::on_upload_profile_photo(FileId file_id, tl_object_ptr<tele
|
|||||||
CHECK(file_view.get_type() == FileType::Photo);
|
CHECK(file_view.get_type() == FileType::Photo);
|
||||||
}
|
}
|
||||||
auto file_reference =
|
auto file_reference =
|
||||||
is_animation ? FileManager::extract_file_reference(file_view.main_remote_location().as_input_photo())
|
is_animation ? FileManager::extract_file_reference(file_view.main_remote_location().as_input_document())
|
||||||
: FileManager::extract_file_reference(file_view.main_remote_location().as_input_document());
|
: FileManager::extract_file_reference(file_view.main_remote_location().as_input_photo());
|
||||||
td_->file_manager_->delete_file_reference(file_id, file_reference);
|
td_->file_manager_->delete_file_reference(file_id, file_reference);
|
||||||
upload_profile_photo(file_id, is_animation, main_frame_timestamp, std::move(promise), {-1});
|
upload_profile_photo(file_id, is_animation, main_frame_timestamp, std::move(promise), reupload_count + 1, {-1});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CHECK(input_file != nullptr);
|
CHECK(input_file != nullptr);
|
||||||
|
@ -1175,7 +1175,7 @@ class ContactsManager final : public Actor {
|
|||||||
const char *source);
|
const char *source);
|
||||||
|
|
||||||
void upload_profile_photo(FileId file_id, bool is_animation, double main_frame_timestamp, Promise<Unit> &&promise,
|
void upload_profile_photo(FileId file_id, bool is_animation, double main_frame_timestamp, Promise<Unit> &&promise,
|
||||||
vector<int> bad_parts = {});
|
int reupload_count = 0, vector<int> bad_parts = {});
|
||||||
|
|
||||||
void on_upload_profile_photo(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);
|
void on_upload_profile_photo(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);
|
||||||
void on_upload_profile_photo_error(FileId file_id, Status status);
|
void on_upload_profile_photo_error(FileId file_id, Status status);
|
||||||
@ -1648,13 +1648,13 @@ class ContactsManager final : public Actor {
|
|||||||
struct UploadedProfilePhoto {
|
struct UploadedProfilePhoto {
|
||||||
double main_frame_timestamp;
|
double main_frame_timestamp;
|
||||||
bool is_animation;
|
bool is_animation;
|
||||||
bool is_reupload;
|
int reupload_count;
|
||||||
Promise<Unit> promise;
|
Promise<Unit> promise;
|
||||||
|
|
||||||
UploadedProfilePhoto(double main_frame_timestamp, bool is_animation, bool is_reupload, Promise<Unit> promise)
|
UploadedProfilePhoto(double main_frame_timestamp, bool is_animation, int32 reupload_count, Promise<Unit> promise)
|
||||||
: main_frame_timestamp(main_frame_timestamp)
|
: main_frame_timestamp(main_frame_timestamp)
|
||||||
, is_animation(is_animation)
|
, is_animation(is_animation)
|
||||||
, is_reupload(is_reupload)
|
, reupload_count(reupload_count)
|
||||||
, promise(std::move(promise)) {
|
, promise(std::move(promise)) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user