Skip to content

Commit 8f5d91f

Browse files
committed
Use process_file_reference_error in QuickReplyManager.
1 parent 213f714 commit 8f5d91f

1 file changed

Lines changed: 25 additions & 89 deletions

File tree

td/telegram/QuickReplyManager.cpp

Lines changed: 25 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -430,34 +430,13 @@ class QuickReplyManager::SendQuickReplyMediaQuery final : public Td::ResultHandl
430430
return;
431431
}
432432
LOG(INFO) << "Receive error for SendQuickReplyMediaQuery: " << status;
433-
if (FileReferenceManager::is_file_reference_error(status)) {
434-
auto source = FileReferenceManager::get_file_reference_error_source(status);
435-
auto pos = source.pos_;
436-
if (pos > 0) {
437-
pos--;
438-
}
439-
if (source.is_cover_) {
440-
if (pos < cover_file_ids_.size() && pos < cover_file_references_.size()) {
441-
VLOG(file_references) << "Receive " << status << " for cover " << cover_file_ids_[pos];
442-
td_->file_manager_->delete_file_reference(cover_file_ids_[pos], cover_file_references_[pos]);
443-
td_->quick_reply_manager_->on_send_message_file_error(shortcut_id_, message_id_, random_id_, pos, 0, {-1});
444-
return;
445-
} else {
446-
LOG(ERROR) << "Receive file reference error " << pos << ", but cover_file_ids = " << cover_file_ids_
447-
<< ", file_references = " << cover_file_references_;
448-
}
449-
} else {
450-
if (pos < file_upload_ids_.size() && pos < file_references_.size() && !was_uploaded_ &&
451-
file_upload_ids_[pos].is_valid()) {
452-
VLOG(file_references) << "Receive " << status << " for " << file_upload_ids_[pos];
453-
td_->file_manager_->delete_file_reference(file_upload_ids_[pos].get_file_id(), file_references_[pos]);
454-
td_->quick_reply_manager_->on_send_message_file_error(shortcut_id_, message_id_, random_id_, pos, 0, {-1});
455-
return;
456-
} else {
457-
LOG(ERROR) << "Receive file reference error " << pos << ", but file_upload_ids = " << file_upload_ids_
458-
<< ", was_uploaded = " << was_uploaded_ << ", file_references = " << file_references_;
459-
}
460-
}
433+
if (td_->file_reference_manager_->process_file_reference_error(
434+
status, was_uploaded_, file_upload_ids_, file_references_, cover_file_ids_, cover_file_references_, false,
435+
[&](size_t pos) mutable {
436+
td_->quick_reply_manager_->on_send_message_file_error(shortcut_id_, message_id_, random_id_, pos, 0,
437+
{-1});
438+
})) {
439+
return;
461440
}
462441
if (was_uploaded_) {
463442
if (was_thumbnail_uploaded_) {
@@ -551,17 +530,12 @@ class QuickReplyManager::UploadQuickReplyMediaQuery final : public Td::ResultHan
551530
return;
552531
}
553532
LOG(INFO) << "Receive error for UploadQuickReplyMediaQuery: " << status;
554-
if (FileReferenceManager::is_file_reference_error(status)) {
555-
auto source = FileReferenceManager::get_file_reference_error_source(status);
556-
if (source.is_cover_ && source.pos_ <= 1 && cover_file_id_.is_valid()) {
557-
VLOG(file_references) << "Receive " << status << " for cover " << cover_file_id_;
558-
td_->file_manager_->delete_file_reference(cover_file_id_, cover_file_reference_);
559-
td_->quick_reply_manager_->on_send_message_file_error(shortcut_id_, message_id_, random_id_, media_pos_,
560-
edit_generation_, {-1});
561-
return;
562-
} else {
563-
LOG(ERROR) << "Receive file reference error for UploadQuickReplyMediaQuery";
564-
}
533+
if (td_->file_reference_manager_->process_file_reference_error(
534+
status, true, {}, {}, {cover_file_id_}, {cover_file_reference_}, false, [&](size_t pos) mutable {
535+
td_->quick_reply_manager_->on_send_message_file_error(shortcut_id_, message_id_, random_id_, media_pos_,
536+
edit_generation_, {-1});
537+
})) {
538+
return;
565539
}
566540
if (was_uploaded_) {
567541
if (was_thumbnail_uploaded_) {
@@ -642,30 +616,12 @@ class QuickReplyManager::SendQuickReplyMultiMediaQuery final : public Td::Result
642616
return;
643617
}
644618
LOG(INFO) << "Receive error for SendQuickReplyMultiMediaQuery: " << status;
645-
if (FileReferenceManager::is_file_reference_error(status)) {
646-
auto source = FileReferenceManager::get_file_reference_error_source(status);
647-
auto pos = source.pos_;
648-
if (source.is_cover_) {
649-
if (1 <= pos && pos <= cover_file_ids_.size() && cover_file_ids_[pos - 1].is_valid()) {
650-
VLOG(file_references) << "Receive " << status << " for cover " << cover_file_ids_[pos - 1];
651-
td_->file_manager_->delete_file_reference(cover_file_ids_[pos - 1], cover_file_references_[pos - 1]);
652-
td_->quick_reply_manager_->on_send_media_group_file_reference_error(shortcut_id_, std::move(random_ids_));
653-
return;
654-
} else {
655-
LOG(ERROR) << "Receive file reference error " << status << ", but cover_file_ids = " << cover_file_ids_
656-
<< ", message_count = " << cover_file_ids_.size();
657-
}
658-
} else {
659-
if (1 <= pos && pos <= file_ids_.size() && file_ids_[pos - 1].is_valid()) {
660-
VLOG(file_references) << "Receive " << status << " for " << file_ids_[pos - 1];
661-
td_->file_manager_->delete_file_reference(file_ids_[pos - 1], file_references_[pos - 1]);
662-
td_->quick_reply_manager_->on_send_media_group_file_reference_error(shortcut_id_, std::move(random_ids_));
663-
return;
664-
} else {
665-
LOG(ERROR) << "Receive file reference error " << status << ", but file_ids = " << file_ids_
666-
<< ", message_count = " << file_ids_.size();
667-
}
668-
}
619+
if (td_->file_reference_manager_->process_file_reference_error(
620+
status, file_ids_, file_references_, cover_file_ids_, cover_file_references_, true,
621+
[&](size_t pos) mutable {
622+
td_->quick_reply_manager_->on_send_media_group_file_reference_error(shortcut_id_, std::move(random_ids_));
623+
})) {
624+
return;
669625
}
670626
td_->quick_reply_manager_->on_failed_send_quick_reply_messages(shortcut_id_, std::move(random_ids_),
671627
std::move(status));
@@ -3217,32 +3173,12 @@ void QuickReplyManager::fail_edit_quick_reply_message(QuickReplyShortcutId short
32173173
}
32183174
return;
32193175
}
3220-
if (FileReferenceManager::is_file_reference_error(status)) {
3221-
auto source = FileReferenceManager::get_file_reference_error_source(status);
3222-
auto pos = source.pos_;
3223-
if (pos > 0) {
3224-
pos--;
3225-
}
3226-
if (source.is_cover_) {
3227-
if (pos < cover_file_ids.size() && pos < cover_file_references.size()) {
3228-
VLOG(file_references) << "Receive " << status << " for cover " << cover_file_ids[pos];
3229-
td_->file_manager_->delete_file_reference(cover_file_ids[pos], cover_file_references[pos]);
3230-
return on_send_message_file_error(shortcut_id, message_id, 0, pos, edit_generation, {-1});
3231-
} else {
3232-
LOG(ERROR) << "Receive file reference error " << pos << ", but cover_file_ids = " << cover_file_ids
3233-
<< ", file_references = " << cover_file_references;
3234-
}
3235-
} else {
3236-
if (pos < file_upload_ids.size() && pos < file_references.size() && !was_uploaded &&
3237-
file_upload_ids[pos].is_valid()) {
3238-
VLOG(file_references) << "Receive " << status << " for " << file_upload_ids[pos];
3239-
td_->file_manager_->delete_file_reference(file_upload_ids[pos].get_file_id(), file_references[pos]);
3240-
return on_send_message_file_error(shortcut_id, message_id, 0, pos, edit_generation, {-1});
3241-
} else {
3242-
LOG(ERROR) << "Receive file reference error " << pos << ", but file_upload_ids = " << file_upload_ids
3243-
<< ", was_uploaded = " << was_uploaded << ", file_references = " << file_references;
3244-
}
3245-
}
3176+
if (td_->file_reference_manager_->process_file_reference_error(
3177+
status, was_uploaded, file_upload_ids, file_references, cover_file_ids, cover_file_references, false,
3178+
[&](size_t pos) mutable {
3179+
on_send_message_file_error(shortcut_id, message_id, 0, pos, edit_generation, {-1});
3180+
})) {
3181+
return;
32463182
}
32473183
if (was_uploaded) {
32483184
if (was_thumbnail_uploaded) {

0 commit comments

Comments
 (0)