@ -160,7 +160,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
void ( ^markAndHandleFailure ) ( NSError * ) = ^( NSError * error ) {
void ( ^markAndHandleFailure ) ( NSError * ) = ^( NSError * error ) {
/ / Ensure enclosing transaction is complete .
/ / Ensure enclosing transaction is complete .
dispatch_async ( dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_DEFAULT , 0 ) , ^{
dispatch_async ( dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_DEFAULT , 0 ) , ^{
[ self setAttachment : attachment didFailInMessage : message ] ;
[ self setAttachment : attachment didFailInMessage : message error : error ] ;
failureHandler ( error ) ;
failureHandler ( error ) ;
} ) ;
} ) ;
} ;
} ;
@ -246,21 +246,32 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
success : ( void ( ^) ( TSAttachmentStream * attachmentStream ) ) successHandler
success : ( void ( ^) ( TSAttachmentStream * attachmentStream ) ) successHandler
failure : ( void ( ^) ( NSError * error ) ) failureHandler
failure : ( void ( ^) ( NSError * error ) ) failureHandler
{
{
NSData * plaintext =
NSError * decryptError ;
[ Cryptography decryptAttachment : cipherText withKey : attachment . encryptionKey digest : attachment . digest ] ;
NSData * plaintext = [ Cryptography decryptAttachment : cipherText
withKey : attachment . encryptionKey
digest : attachment . digest
error : & decryptError ] ;
if ( decryptError ) {
DDLogError ( @ "%@ failed to decrypt with error: %@", self.tag, decryptError);
failureHandler ( decryptError ) ;
return ;
}
if ( !plaintext ) {
if ( !plaintext ) {
NSError * error = OWSErrorWithCodeDescription ( OWSErrorCodeFailedToDecryptMessage , NSLocalizedString ( @ "ERROR_MESSAGE_INVALID_MESSAGE ", @ "") ) ;
NSError * error = OWSErrorWithCodeDescription ( OWSErrorCodeFailedToDecryptMessage , NSLocalizedString ( @ "ERROR_MESSAGE_INVALID_MESSAGE ", @ "") ) ;
return failureHandler ( error ) ;
failureHandler ( error ) ;
return ;
}
}
TSAttachmentStream * stream = [ [ TSAttachmentStream alloc ] initWithPointer : attachment ] ;
TSAttachmentStream * stream = [ [ TSAttachmentStream alloc ] initWithPointer : attachment ] ;
NSError * error ;
NSError * writeError ;
[ stream writeData : plaintext error : & error ] ;
[ stream writeData : plaintext error : & writeError ] ;
if ( error ) {
if ( writeError ) {
DDLogError ( @ "%@ Failed writing attachment stream with error: %@", self.tag, error);
DDLogError ( @ "%@ Failed writing attachment stream with error: %@", self.tag, writeError);
return failureHandler ( error ) ;
failureHandler ( writeError ) ;
return ;
}
}
[ stream save ] ;
[ stream save ] ;
@ -405,8 +416,11 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
}
}
}
- ( void ) setAttachment : ( TSAttachmentPointer * ) pointer didFailInMessage : ( nullable TSMessage * ) message
- ( void ) setAttachment : ( TSAttachmentPointer * ) pointer
didFailInMessage : ( nullable TSMessage * ) message
error : ( NSError * ) error
{
{
pointer . mostRecentFailureLocalizedText = error . localizedDescription ;
pointer . state = TSAttachmentPointerStateFailed ;
pointer . state = TSAttachmentPointerStateFailed ;
[ pointer save ] ;
[ pointer save ] ;
if ( message ) {
if ( message ) {