Replace the deprecated MXMediaManager and MXMediaLoader interfaces use

This commit is contained in:
Giom Foret
2018-11-10 14:28:08 +01:00
parent 7f636ed48f
commit 0d68e42fb4
3 changed files with 82 additions and 39 deletions
@@ -497,39 +497,73 @@
];
// Do some sanitisation by handling the potential image
MXWeakify(self);
sanitisedGroupLongDescription = [MXKTools sanitiseHTML:_group.summary.profile.longDescription withAllowedHTMLTags:allowedHTMLTags imageHandler:^NSString *(NSString *sourceURL, CGFloat width, CGFloat height) {
NSString *imageURL;
NSString *localSourcePath;
if (width != -1 && height != -1)
{
CGSize size = CGSizeMake(width, height);
imageURL = [self.mxSession.matrixRestClient urlOfContentThumbnail:sourceURL toFitViewSize:size withMethod:MXThumbnailingMethodScale];
// Build the cache path for the a thumbnail of this image.
NSString *cacheFilePath = [MXMediaManager thumbnailCachePathForMatrixContentURI:sourceURL
andType:nil
inFolder:kMXMediaManagerDefaultCacheFolder
toFitViewSize:size
withMethod:MXThumbnailingMethodScale];
// Check whether the provided URL is a valid Matrix Content URI.
if (cacheFilePath)
{
localSourcePath = [NSString stringWithFormat:@"file://%@", cacheFilePath];
// Download the thumbnail if it is not already stored in the cache.
if (![[NSFileManager defaultManager] fileExistsAtPath:cacheFilePath])
{
MXStrongifyAndReturnValueIfNil(self, nil);
MXWeakify(self);
[self.mxSession.mediaManager downloadThumbnailFromMatrixContentURI:sourceURL
withType:nil
inFolder:kMXMediaManagerDefaultCacheFolder
toFitViewSize:size
withMethod:MXThumbnailingMethodScale
success:^(NSString *outputFilePath) {
MXStrongifyAndReturnIfNil(self);
[self renderGroupLongDescription];
}
failure:nil];
}
}
}
else
{
imageURL = [self.mxSession.matrixRestClient urlOfContent:sourceURL];
}
NSString *mimeType = nil;
// Check if the extension could not be deduced from url
if (![imageURL pathExtension].length)
{
// Set default mime type if no information is available
mimeType = @"image/jpeg";
}
NSString *cacheFilePath = [MXMediaManager cachePathForMediaWithURL:imageURL andType:mimeType inFolder:kMXMediaManagerDefaultCacheFolder];
if (![[NSFileManager defaultManager] fileExistsAtPath:cacheFilePath])
{
[MXMediaManager downloadMediaFromURL:imageURL andSaveAtFilePath:cacheFilePath success:^{
// Build the cache path for this image.
NSString* cacheFilePath = [MXMediaManager cachePathForMatrixContentURI:sourceURL
andType:nil
inFolder:kMXMediaManagerDefaultCacheFolder];
// Check whether the provided URL is a valid Matrix Content URI.
if (cacheFilePath)
{
localSourcePath = [NSString stringWithFormat:@"file://%@", cacheFilePath];
[self renderGroupLongDescription];
} failure:nil];
// Download the image if it is not already stored in the cache.
if (![[NSFileManager defaultManager] fileExistsAtPath:cacheFilePath])
{
MXStrongifyAndReturnValueIfNil(self, nil);
MXWeakify(self);
[self.mxSession.mediaManager downloadMediaFromMatrixContentURI:sourceURL
withType:nil
inFolder:kMXMediaManagerDefaultCacheFolder
success:^(NSString *outputFilePath) {
MXStrongifyAndReturnIfNil(self);
[self renderGroupLongDescription];
}
failure:nil];
}
}
}
return localSourcePath;
return [NSString stringWithFormat:@"file://%@", cacheFilePath];
}];
}
else