Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MXMediaManager/MXMediaLoader: Do not allow non-mxc content URLs #2095

Merged
merged 6 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
Changes in 0.7.x (2018-xx-xx)
===============================================

Improvements:
* Replace the deprecated MXMediaManager and MXMediaLoader interfaces use (see matrix-org/matrix-ios-sdk/pull/593).
* Replace the deprecated MXKAttachment and MXKImageView interfaces use (see matrix-org/matrix-ios-kit/pull/487).

Changes in 0.7.7 (2018-10-31)
===============================================

Improvements:
* Upgrade MatrixKit version (v0.8.6).
* Upgrade MatrixKit version (v0.8.6).

Bug fix:
* Notifications: old notifications can reappear (#1985).
* Notifications: old notifications can reappear (#1985).

Changes in 0.7.6 (2018-10-05)
===============================================

Bug fix:
* Wrong version number.
* Wrong version number.

Changes in 0.7.5 (2018-10-05)
===============================================

Improvements:
* Upgrade MatrixKit version (v0.8.5).
* Server Quota Notices: Implement the blue banner (#1937).
* Upgrade MatrixKit version (v0.8.5).
* Server Quota Notices: Implement the blue banner (#1937).

Changes in 0.7.4 (2018-09-26)
===============================================

Improvements:
* Upgrade MatrixKit version (v0.8.4).
* Lazy loading: Enable it by default (if the homeserver supports it).
* i18n: Add Spanish (sp).
* Settings: Make advanced info copyable (#2023).
* Settings: Made cryptography info copyable, thanks to @daverPL (PR #1999).
* Room settings: Anyone can now set a room alias (#2033).
* Upgrade MatrixKit version (v0.8.4).
* Lazy loading: Enable it by default (if the homeserver supports it).
* i18n: Add Spanish (sp).
* Settings: Make advanced info copyable (#2023).
* Settings: Made cryptography info copyable, thanks to @daverPL (PR #1999).
* Room settings: Anyone can now set a room alias (#2033).

Bug fix:
* Fix missing read receipts when lazy-loading room members.
* Weird text color when selecting a message (#2046).
* Fix missing read receipts when lazy-loading room members.
* Weird text color when selecting a message (#2046).

Changes in 0.7.3 (2018-08-27)
===============================================

Improvements:
* Upgrade MatrixKit version (v0.8.3).
* Upgrade MatrixKit version (v0.8.3).

Bug fix:
* Fix input toolbar reset in RoomViewController on MXSession state change (#2006 and #2008).
* Fix user interaction disabled in master view of UISplitViewContoller when selecting a room (#2005).
* Fix input toolbar reset in RoomViewController on MXSession state change (#2006 and #2008).
* Fix user interaction disabled in master view of UISplitViewContoller when selecting a room (#2005).

Changes in 0.7.2 (2018-08-24)
===============================================
Expand Down
9 changes: 8 additions & 1 deletion Riot/Categories/MXGroup+Riot.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +31,13 @@ - (void)setGroupAvatarImageIn:(MXKImageView*)mxkImageView matrixSession:(MXSessi
{
mxkImageView.enableInMemoryCache = YES;

[mxkImageView setImageURL:[mxSession.matrixRestClient urlOfContentThumbnail:self.profile.avatarUrl toFitViewSize:mxkImageView.frame.size withMethod:MXThumbnailingMethodCrop] withType:nil andImageOrientation:UIImageOrientationUp previewImage:avatarImage];
[mxkImageView setImageURI:self.profile.avatarUrl
withType:nil
andImageOrientation:UIImageOrientationUp
toFitViewSize:mxkImageView.frame.size
withMethod:MXThumbnailingMethodCrop
previewImage:avatarImage
mediaManager:mxSession.mediaManager];
}
else
{
Expand Down
9 changes: 8 additions & 1 deletion Riot/Categories/MXRoomSummary+Riot.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +31,13 @@ - (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView
{
mxkImageView.enableInMemoryCache = YES;

[mxkImageView setImageURL:[self.mxSession.matrixRestClient urlOfContentThumbnail:self.avatar toFitViewSize:mxkImageView.frame.size withMethod:MXThumbnailingMethodCrop] withType:nil andImageOrientation:UIImageOrientationUp previewImage:avatarImage];
[mxkImageView setImageURI:self.avatar
withType:nil
andImageOrientation:UIImageOrientationUp
toFitViewSize:mxkImageView.frame.size
withMethod:MXThumbnailingMethodCrop
previewImage:avatarImage
mediaManager:self.mxSession.mediaManager];
}
else
{
Expand Down
21 changes: 11 additions & 10 deletions Riot/Modules/Call/CallViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -199,20 +200,17 @@ - (void)destroy

- (UIView *)createIncomingCallView
{
NSString *avatarThumbURL = [self.mainSession.matrixRestClient urlOfContentThumbnail:self.peer.avatarUrl
toFitViewSize:IncomingCallView.callerAvatarSize
withMethod:MXThumbnailingMethodCrop];

NSString *callInfo;
if (self.mxCall.isVideoCall)
callInfo = NSLocalizedStringFromTable(@"call_incoming_video", @"Vector", nil);
else
callInfo = NSLocalizedStringFromTable(@"call_incoming_voice", @"Vector", nil);

IncomingCallView *incomingCallView = [[IncomingCallView alloc] initWithCallerAvatarURL:avatarThumbURL
placeholderImage:self.picturePlaceholder
callerName:self.peer.displayname
callInfo:callInfo];
IncomingCallView *incomingCallView = [[IncomingCallView alloc] initWithCallerAvatar:self.peer.avatarUrl
mediaManager:self.mainSession.mediaManager
placeholderImage:self.picturePlaceholder
callerName:self.peer.displayname
callInfo:callInfo];

// Incoming call is retained by call vc so use weak to avoid retain cycle
__weak typeof(self) weakSelf = self;
Expand Down Expand Up @@ -396,8 +394,11 @@ - (void)updatePeerInfoDisplay
if (peerAvatarURL)
{
// Retrieve the avatar in full resolution
NSString *avatarThumbURL = [self.mainSession.matrixRestClient urlOfContent:peerAvatarURL];
[self.callerImageView setImageURL:avatarThumbURL withType:nil andImageOrientation:UIImageOrientationUp previewImage:self.picturePlaceholder];
[self.callerImageView setImageURI:peerAvatarURL
withType:nil
andImageOrientation:UIImageOrientationUp
previewImage:self.picturePlaceholder
mediaManager:self.mainSession.mediaManager];
}
else
{
Expand Down
19 changes: 15 additions & 4 deletions Riot/Modules/Call/Views/IncomingCallView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
NS_ASSUME_NONNULL_BEGIN

typedef void (^IncomingCallViewAction)();
@class MXMediaManager;

@interface IncomingCallView : UIView

Expand All @@ -37,10 +38,20 @@ typedef void (^IncomingCallViewAction)();
*/
@property (nonatomic, nullable, copy) IncomingCallViewAction onReject;

- (instancetype)initWithCallerAvatarURL:(NSString *)callerAvatarURL
placeholderImage:(UIImage *)placeholderImage
callerName:(NSString *)callerName
callInfo:(NSString *)callInfo;
/**
Contructors.

@param mxcAvatarURI the Matrix Content URI of the caller avatar.
@param mediaManager the media manager used to download this avatar if it is not cached yet.
@param placeholderImage
@param callerName
@param callInfo
*/
- (instancetype)initWithCallerAvatar:(NSString *)mxcAvatarURI
mediaManager:(MXMediaManager *)mediaManager
placeholderImage:(UIImage *)placeholderImage
callerName:(NSString *)callerName
callInfo:(NSString *)callInfo;

@end

Expand Down
14 changes: 11 additions & 3 deletions Riot/Modules/Call/Views/IncomingCallView.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +47,11 @@ + (CGSize)callerAvatarSize
return CGSizeMake(kAvatarSize, kAvatarSize);
}

- (instancetype)initWithCallerAvatarURL:(NSString *)callerAvatarURL placeholderImage:(UIImage *)placeholderImage callerName:(NSString *)callerName callInfo:(NSString *)callInfo
- (instancetype)initWithCallerAvatar:(NSString *)mxcAvatarURI
mediaManager:(MXMediaManager *)mediaManager
placeholderImage:(UIImage *)placeholderImage
callerName:(NSString *)callerName
callInfo:(NSString *)callInfo
{
self = [super initWithFrame:CGRectZero];
if (self)
Expand All @@ -59,10 +64,13 @@ - (instancetype)initWithCallerAvatarURL:(NSString *)callerAvatarURL placeholderI
self.callerImageView.clipsToBounds = YES;
self.callerImageView.mediaFolder = kMXMediaManagerAvatarThumbnailFolder;
self.callerImageView.enableInMemoryCache = YES;
[self.callerImageView setImageURL:callerAvatarURL
[self.callerImageView setImageURI:mxcAvatarURI
withType:nil
andImageOrientation:UIImageOrientationUp
previewImage:placeholderImage];
toFitViewSize:IncomingCallView.callerAvatarSize
withMethod:MXThumbnailingMethodCrop
previewImage:placeholderImage
mediaManager:mediaManager];

self.callerNameLabel = [[UILabel alloc] init];
self.callerNameLabel.backgroundColor = kRiotPrimaryBgColor;
Expand Down
88 changes: 63 additions & 25 deletions Riot/Modules/Communities/Home/GroupHomeViewController.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -497,39 +498,73 @@ - (void)refreshGroupLongDescription
];

// 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) {

manuroe marked this conversation as resolved.
Show resolved Hide resolved
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);
manuroe marked this conversation as resolved.
Show resolved Hide resolved
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:^{

[self renderGroupLongDescription];
// 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];

} 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
Expand Down Expand Up @@ -701,22 +736,25 @@ - (void)handleTapGesture:(UITapGestureRecognizer*)tapGestureRecognizer
__block MXKImageView * avatarFullScreenView = [[MXKImageView alloc] initWithFrame:CGRectZero];
avatarFullScreenView.stretchable = YES;

MXWeakify(self);
[avatarFullScreenView setRightButtonTitle:[NSBundle mxk_localizedStringForKey:@"ok"] handler:^(MXKImageView* imageView, NSString* buttonTitle) {

MXStrongifyAndReturnIfNil(self);
[avatarFullScreenView dismissSelection];
[avatarFullScreenView removeFromSuperview];

avatarFullScreenView = nil;

isStatusBarHidden = NO;
self->isStatusBarHidden = NO;
// Trigger status bar update
[self setNeedsStatusBarAppearanceUpdate];
}];

NSString *avatarURL = [self.mainSession.matrixRestClient urlOfContent:_group.summary.profile.avatarUrl];
[avatarFullScreenView setImageURL:avatarURL
[avatarFullScreenView setImageURI:_group.summary.profile.avatarUrl
withType:nil
andImageOrientation:UIImageOrientationUp
previewImage:self.groupAvatar.image];
previewImage:self.groupAvatar.image
mediaManager:_mxSession.mediaManager];

[avatarFullScreenView showFullScreen];
isStatusBarHidden = YES;
Expand Down
11 changes: 7 additions & 4 deletions Riot/Modules/Communities/Rooms/Views/GroupRoomTableViewCell.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,11 +76,13 @@ - (void)render:(MXGroupRoom *)groupRoom withMatrixSession:(MXSession*)mxSession
{
_roomAvatar.enableInMemoryCache = YES;

[_roomAvatar setImageURL:[mxSession.matrixRestClient urlOfContentThumbnail:groupRoom.avatarUrl
toFitViewSize:_roomAvatar.frame.size
withMethod:MXThumbnailingMethodCrop]
[_roomAvatar setImageURI:groupRoom.avatarUrl
withType:nil
andImageOrientation:UIImageOrientationUp previewImage:avatarImage];
andImageOrientation:UIImageOrientationUp
toFitViewSize:_roomAvatar.frame.size
withMethod:MXThumbnailingMethodCrop
previewImage:avatarImage
mediaManager:mxSession.mediaManager];
}
else
{
Expand Down
Loading