From 3f49796c435d370a90216a9d10c5033e6e34c142 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 25 Mar 2019 12:56:56 +0400 Subject: [PATCH] Fix file reference updating. --- .../SourceFiles/storage/file_download.cpp | 28 +++++++++++++++++-- Telegram/SourceFiles/storage/file_download.h | 4 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index 9dbad9e3f..8dd948018 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -762,7 +762,9 @@ void mtpFileLoader::makeRequest(int offset) { MTP_int(offset), MTP_int(limit)), rpcDone(&mtpFileLoader::normalPartLoaded), - rpcFail(&mtpFileLoader::partFailed), + rpcFail( + &mtpFileLoader::normalPartFailed, + computeFileReference()), shiftedDcId, 50); } @@ -785,6 +787,15 @@ MTPInputFileLocation mtpFileLoader::computeLocation() const { MTP_string(QString())); } +QByteArray mtpFileLoader::computeFileReference() const { + if (_location) { + return _location->fileReference(); + } else if (_locationType == SecureFileLocation) { + return QByteArray(); + } + return _fileReference; +} + void mtpFileLoader::requestMoreCdnFileHashes() { Expects(!_finished); @@ -1076,7 +1087,8 @@ void mtpFileLoader::partLoaded(int offset, bytes::const_span buffer) { } } -bool mtpFileLoader::partFailed( +bool mtpFileLoader::normalPartFailed( + QByteArray fileReference, const RPCError &error, mtpRequestId requestId) { if (MTP::isDefaultHandledError(error)) { @@ -1088,9 +1100,19 @@ bool mtpFileLoader::partFailed( _origin, this, requestId, - _location ? _location->fileReference() : _fileReference); + fileReference); return true; } + return partFailed(error, requestId); +} + + +bool mtpFileLoader::partFailed( + const RPCError &error, + mtpRequestId requestId) { + if (MTP::isDefaultHandledError(error)) { + return false; + } cancel(true); return true; } diff --git a/Telegram/SourceFiles/storage/file_download.h b/Telegram/SourceFiles/storage/file_download.h index 61254d45b..a5aea0490 100644 --- a/Telegram/SourceFiles/storage/file_download.h +++ b/Telegram/SourceFiles/storage/file_download.h @@ -273,7 +273,8 @@ private: RequestData prepareRequest(int offset) const; void makeRequest(int offset); - MTPInputFileLocation computeLocation() const; + [[nodiscard]] MTPInputFileLocation computeLocation() const; + [[nodiscard]] QByteArray computeFileReference() const; bool loadPart() override; void normalPartLoaded(const MTPupload_File &result, mtpRequestId requestId); void webPartLoaded(const MTPupload_WebFile &result, mtpRequestId requestId); @@ -286,6 +287,7 @@ private: void partLoaded(int offset, bytes::const_span buffer); bool partFailed(const RPCError &error, mtpRequestId requestId); + bool normalPartFailed(QByteArray fileReference, const RPCError &error, mtpRequestId requestId); bool cdnPartFailed(const RPCError &error, mtpRequestId requestId); void placeSentRequest(mtpRequestId requestId, const RequestData &requestData);