vector-im/element-ios/issues/4577 - Decrypt attachments on a background thread.
MODIFY
MatrixKit/Models/Room/MXKAttachment.m
MatrixKit/Models/Room/MXKAttachment.m
@@ -290,17 +290,18 @@ NSString *const kMXKAttachmentErrorDomain = @"kMXKAttachmentErrorDomain";
MXStrongifyAndReturnIfNil(self);
NSInputStream *instream = [[NSInputStream alloc] initWithFileAtPath:self.thumbnailCachePath];
NSOutputStream *outstream = [[NSOutputStream alloc] initToMemory];
- NSError *err = [MXEncryptedAttachments decryptAttachment:self->thumbnailFile inputStream:instream outputStream:outstream];
+ [MXEncryptedAttachments decryptAttachment:self->thumbnailFile inputStream:instream outputStream:outstream success:^{
+ UIImage *img = [UIImage imageWithData:[outstream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]];
+ // Save this image to in-memory cache.
+ [MXMediaManager cacheImage:img withCachePath:self.thumbnailCachePath];
+ onSuccess(self, img);
+ } failure:^(NSError *err) {
if (err) {
MXLogDebug(@"Error decrypting attachment! %@", err.userInfo);
if (onFailure) onFailure(self, err);
return;
}
-
- UIImage *img = [UIImage imageWithData:[outstream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]];
- // Save this image to in-memory cache.
- [MXMediaManager cacheImage:img withCachePath:self.thumbnailCachePath];
- onSuccess(self, img);
+ }];
};
if ([[NSFileManager defaultManager] fileExistsAtPath:_thumbnailCachePath])
@@ -398,13 +399,15 @@ NSString *const kMXKAttachmentErrorDomain = @"kMXKAttachmentErrorDomain";
// decrypt the encrypted file
NSInputStream *instream = [[NSInputStream alloc] initWithFileAtPath:self.cacheFilePath];
NSOutputStream *outstream = [[NSOutputStream alloc] initToMemory];
- NSError *err = [MXEncryptedAttachments decryptAttachment:self->contentFile inputStream:instream outputStream:outstream];
+ [MXEncryptedAttachments decryptAttachment:self->contentFile inputStream:instream outputStream:outstream success:^{
+ onSuccess([outstream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]);
+ } failure:^(NSError *err) {
if (err)
{
MXLogDebug(@"Error decrypting attachment! %@", err.userInfo);
return;
}
- onSuccess([outstream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]);
+ }];
}
else
{
@@ -428,12 +431,14 @@ NSString *const kMXKAttachmentErrorDomain = @"kMXKAttachmentErrorDomain";
NSInputStream *inStream = [NSInputStream inputStreamWithFileAtPath:self.cacheFilePath];
NSOutputStream *outStream = [NSOutputStream outputStreamToFileAtPath:tempPath append:NO];
- NSError *err = [MXEncryptedAttachments decryptAttachment:self->contentFile inputStream:inStream outputStream:outStream];
+ [MXEncryptedAttachments decryptAttachment:self->contentFile inputStream:inStream outputStream:outStream success:^{
+ onSuccess(tempPath);
+ } failure:^(NSError *err) {
if (err) {
if (onFailure) onFailure(err);
return;
}
- onSuccess(tempPath);
+ }];
} failure:onFailure];
}

MODIFY
MatrixKit/Models/Room/MXKRoomDataSource.h
MatrixKit/Models/Room/MXKRoomDataSource.h
@@ -554,7 +554,7 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
*/
- (void)sendVoiceMessage:(NSURL *)audioFileLocalURL
mimeType:mimeType
- duration:(NSTimeInterval)duration
+ duration:(NSUInteger)duration
samples:(NSArray<NSNumber *> *)samples
success:(void (^)(NSString *))success
failure:(void (^)(NSError *))failure;

MODIFY
MatrixKit/Models/Room/MXKRoomDataSource.m
MatrixKit/Models/Room/MXKRoomDataSource.m
@@ -1896,7 +1896,7 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
- (void)sendVoiceMessage:(NSURL *)audioFileLocalURL
mimeType:mimeType
- duration:(NSTimeInterval)duration
+ duration:(NSUInteger)duration
samples:(NSArray<NSNumber *> *)samples
success:(void (^)(NSString *))success
failure:(void (^)(NSError *))failure

vector-im/element-ios/issues/4577 - Decrypt attachments on a background thread.