Add is_file_reference_error.

GitOrigin-RevId: 7c36433edff5de1a9ef6c2ffb0b4745e4aede0be
This commit is contained in:
levlam 2019-01-23 19:00:56 +03:00
parent 3648434fa4
commit 6633b87d51
4 changed files with 15 additions and 7 deletions

View File

@ -22,6 +22,10 @@ namespace td {
int VERBOSITY_NAME(file_references) = VERBOSITY_NAME(WARNING); int VERBOSITY_NAME(file_references) = VERBOSITY_NAME(WARNING);
bool FileReferenceManager::is_file_reference_error(const Status &error) {
return error.is_error() && error.code() == 400 && begins_with(error.message(), "FILE_REFERENCE_");
}
/* /*
fileSourceMessage chat_id:int53 message_id:int53 = FileSource; // repaired with get_messages_from_server fileSourceMessage chat_id:int53 message_id:int53 = FileSource; // repaired with get_messages_from_server
fileSourceUserProfilePhoto user_id:int32 photo_id:int64 = FileSource; // repaired with photos.getUserPhotos fileSourceUserProfilePhoto user_id:int32 photo_id:int64 = FileSource; // repaired with photos.getUserPhotos

View File

@ -30,6 +30,8 @@ extern int VERBOSITY_NAME(file_references);
class FileReferenceManager : public Actor { class FileReferenceManager : public Actor {
public: public:
static bool is_file_reference_error(const Status &error);
FileSourceId create_message_file_source(FullMessageId full_message_id); FileSourceId create_message_file_source(FullMessageId full_message_id);
FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id); FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id);
FileSourceId create_chat_photo_file_source(ChatId chat_id); FileSourceId create_chat_photo_file_source(ChatId chat_id);

View File

@ -8,6 +8,7 @@
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileLoaderUtils.h" #include "td/telegram/files/FileLoaderUtils.h"
#include "td/telegram/files/FileType.h" #include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -272,9 +273,9 @@ Result<std::pair<NetQueryPtr, bool>> FileDownloader::start_part(Part part, int32
Status FileDownloader::check_net_query(NetQueryPtr &net_query) { Status FileDownloader::check_net_query(NetQueryPtr &net_query) {
if (net_query->is_error()) { if (net_query->is_error()) {
auto error = net_query->move_as_error(); auto error = net_query->move_as_error();
if (error.code() == 400 && begins_with(error.message(), "FILE_REFERENCE_")) { if (FileReferenceManager::is_file_reference_error(error)) {
error = Status::Error(400, PSLICE() error = Status::Error(error.code(),
<< "FILE_REFERENCE_EXPIRED_BASE64" << base64_encode(remote_.get_file_reference())); PSLICE() << error.message() << "#BASE64" << base64_encode(remote_.get_file_reference()));
} }
return error; return error;
} }

View File

@ -2822,11 +2822,12 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type,
if (begins_with(status.message(), "FILE_GENERATE_LOCATION_INVALID")) { if (begins_with(status.message(), "FILE_GENERATE_LOCATION_INVALID")) {
node->set_generate_location(nullptr); node->set_generate_location(nullptr);
} }
if (begins_with(status.message(), "FILE_REFERENCE_")) { if (FileReferenceManager::is_file_reference_error(status)) {
string file_reference; string file_reference;
Slice prefix = "FILE_REFERENCE_EXPIRED_BASE64"; Slice prefix = "#BASE64";
if (begins_with(status.message(), prefix)) { auto pos = status.message().rfind('#');
auto r_file_reference = base64_decode(status.message().substr(prefix.size())); if (pos < status.message().size() && begins_with(status.message().substr(pos), prefix)) {
auto r_file_reference = base64_decode(status.message().substr(pos + prefix.size()));
if (r_file_reference.is_ok()) { if (r_file_reference.is_ok()) {
file_reference = r_file_reference.move_as_ok(); file_reference = r_file_reference.move_as_ok();
} else { } else {