diff options
| author | levlam <levlam@telegram.org> | 2026-06-29 15:19:11 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-06-29 15:19:11 +0300 |
| commit | 6745519705d221e27e303794ac45bb6b31a51393 (patch) | |
| tree | 6506541b6bcc89d73e618bd014eece759601a63c | |
| parent | dd582be7860a1b135aaf6c6f1a68ad13ff461c51 (diff) | |
Simplify get_file_reference_error_source.
| -rw-r--r-- | td/telegram/FileReferenceManager.cpp | 34 | ||||
| -rw-r--r-- | td/telegram/FileReferenceManager.h | 2 |
2 files changed, 12 insertions, 24 deletions
diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 66c46f3b2..e46b3d578 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -59,27 +59,25 @@ bool FileReferenceManager::is_file_reference_error(const Status &error) { } FileReferenceManager::FileReferenceErrorSource FileReferenceManager::get_file_reference_error_source( - const Status &error) { - if (!is_file_reference_error(error)) { - return {0, false}; - } + const Status &error, bool expect_index) { + CHECK(is_file_reference_error(error)); auto offset = Slice("FILE_REFERENCE_").size(); Slice message = error.message(); message = message.substr(offset); size_t pos = 0; if (begins_with(message, "ATTACH_")) { - pos = 1; + pos = 0; message = message.substr(7); } else if (begins_with(message, "SOLUTION_")) { - pos = 2; + pos = 1; message = message.substr(9); } else if (begins_with(message, "ANSWER_")) { message = message.substr(7); if (message.empty() || !is_digit(message[0])) { // add poll answer - pos = 1; + pos = 0; } else { - pos = 3 + to_integer<size_t>(message); + pos = 2 + to_integer<size_t>(message); auto underscore_pos = message.find('_'); if (underscore_pos == Slice::npos) { message = Slice(); @@ -88,13 +86,15 @@ FileReferenceManager::FileReferenceErrorSource FileReferenceManager::get_file_re } } } else if (!message.empty() || is_digit(message[0])) { - pos = 1 + to_integer<size_t>(message); + pos = to_integer<size_t>(message); auto underscore_pos = message.find('_'); if (underscore_pos == Slice::npos) { message = Slice(); } else { message = message.substr(underscore_pos + 1); } + } else if (expect_index) { + LOG(ERROR) << "Expected a file reference error with an index, but receive " << error.message(); } if (!message.empty() && message[0] == '_') { message = message.substr(1); @@ -124,14 +124,8 @@ bool FileReferenceManager::process_file_reference_error(const Status &status, bo if (td_->auth_manager_->is_bot() || !is_file_reference_error(status)) { return false; } - auto source = get_file_reference_error_source(status); + auto source = get_file_reference_error_source(status, expect_index); auto pos = source.pos_; - if (pos > 0) { - pos--; - } else if (expect_index) { - LOG(ERROR) << "Expected a file reference error with an index"; - return false; - } if (source.is_cover_) { if (pos < cover_file_ids.size() && pos < cover_file_references.size()) { return on_file_reference_error(status, pos, cover_file_ids[pos], cover_file_references[pos], std::move(on_error)); @@ -159,14 +153,8 @@ bool FileReferenceManager::process_file_reference_error(const Status &status, co if (td_->auth_manager_->is_bot() || !is_file_reference_error(status)) { return false; } - auto source = get_file_reference_error_source(status); + auto source = get_file_reference_error_source(status, expect_index); auto pos = source.pos_; - if (pos > 0) { - pos--; - } else if (expect_index) { - LOG(ERROR) << "Expected a file reference error with an index"; - return false; - } if (source.is_cover_) { if (pos < cover_file_ids.size() && pos < cover_file_references.size()) { return on_file_reference_error(status, pos, cover_file_ids[pos], cover_file_references[pos], std::move(on_error)); diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index 7f3c5a867..380595ccb 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -55,7 +55,7 @@ class FileReferenceManager final : public Actor { size_t pos_; bool is_cover_; }; - static FileReferenceErrorSource get_file_reference_error_source(const Status &error); + static FileReferenceErrorSource get_file_reference_error_source(const Status &error, bool expect_index); bool process_file_reference_error(const Status &status, bool was_uploaded, const vector<FileUploadId> &file_upload_ids, const vector<string> &file_references, |
