Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

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

Merged
merged 5 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 30 additions & 16 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
Changes in MatrixKit in 0.8.x (2018-xx-xx)
==========================================

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

Deprecated API:
* MXKAttachment: the properties "actualURL" and "thumbnailURL" are deprecated because only Matrix Content URI should be considered now.
* MXKAttachment: the property "cacheThumbnailPath" is deprecated, use "thumbnailCachePath" instead.
* MXKAttachment: [initWithEvent:andMatrixSession:] is deprecated, use [initWithEvent:andMediaManager:] instead.
* MXKImageView: [setImageURL:withType:andImageOrientation:previewImage:] is deprecated, use [setImageURI:withType:andImageOrientation:previewImage:mediaManager] or [setImageURI:withType:andImageOrientation:toFitViewSize:withMethod:previewImage:mediaManager] instead.
* MXKReceiptSendersContainer: the property "restClient" is deprecated.
* MXKReceiptSendersContainer: [initWithFrame:andRestClient:] is deprecated, use [initWithFrame:andMediaManager:] instead.

Changes in MatrixKit in 0.8.6 (2018-10-31)
==========================================

Improvements:
* Upgrade MatrixSDK version (v0.11.6).
* Upgrade MatrixSDK version (v0.11.6).

Bug fix:
* MXKCallViewController: Fix crash in callRoomStateDidChange (vector-im/riot-ios#2079).
* MXKEventFormatter: Be robust on malformatted m.relates_to data content (vector-im/riot-ios/issues/2080).
* MXKCallViewController: Fix crash in callRoomStateDidChange (vector-im/riot-ios#2079).
* MXKEventFormatter: Be robust on malformatted m.relates_to data content (vector-im/riot-ios/issues/2080).

Changes in MatrixKit in 0.8.5 (2018-10-05)
==========================================

Improvements:
* Upgrade MatrixSDK version (v0.11.5).
* Sync Filter: Refine limit value. Use 15 messages for iPhone 6 & similar screen size.
* Upgrade MatrixSDK version (v0.11.5).
* Sync Filter: Refine limit value. Use 15 messages for iPhone 6 & similar screen size.

Bug fix:
* MXKRoomDataSource: roomState was not updated (vector-im/riot-ios/issues/2058).
* MXKRoomDataSource: roomState was not updated (vector-im/riot-ios/issues/2058).

Changes in MatrixKit in 0.8.4 (2018-09-26)
==========================================

Improvements:
* Upgrade MatrixSDK version (v0.11.4).
* Lazy loading: Enable it by default (if the homeserver supports it).
* Sync Filter: Get enough messages from /sync requests to display a full page without additional homeserver request.
* MXKRoomViewController: Improve the display of the reason when the user is kicked.
* MXKEventFormatter: Internationalise the room name computation for rooms with no name.
* Upgrade MatrixSDK version (v0.11.4).
* Lazy loading: Enable it by default (if the homeserver supports it).
* Sync Filter: Get enough messages from /sync requests to display a full page without additional homeserver request.
* MXKRoomViewController: Improve the display of the reason when the user is kicked.
* MXKEventFormatter: Internationalise the room name computation for rooms with no name.

Bug fix:
* No automatic scroll down when posting a new message (vector-im/riot-ios/issues/2040).
* Fix crash in [MXKCallViewController callRoomStateDidChange:] (vector-im/riot-ios/issues/2031).
* Fix crash in [MXKContactManager refreshLocalContacts] (vector-im/riot-ios/issues/2032).
* Fix crash when opening a room with unsent message (vector-im/riot-ios/issues/2041).
* No automatic scroll down when posting a new message (vector-im/riot-ios/issues/2040).
* Fix crash in [MXKCallViewController callRoomStateDidChange:] (vector-im/riot-ios/issues/2031).
* Fix crash in [MXKContactManager refreshLocalContacts] (vector-im/riot-ios/issues/2032).
* Fix crash when opening a room with unsent message (vector-im/riot-ios/issues/2041).

Changes in MatrixKit in 0.8.3 (2018-08-27)
==========================================

Improvements:
* Upgrade MatrixSDK version (v0.11.3).
* Upgrade MatrixSDK version (v0.11.3).

Changes in MatrixKit in 0.8.2 (2018-08-24)
==========================================
Expand Down
113 changes: 61 additions & 52 deletions MatrixKit/Controllers/MXKAccountDetailsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ @interface MXKAccountDetailsViewController ()
MXMediaLoader *imageLoader;
NSString *currentDisplayName;
NSString *currentPictureURL;
NSString *currentPictureThumbURL;
NSString *currentDownloadId;
NSString *uploadedPictureURL;
// Local changes
BOOL isAvatarUpdated;
Expand Down Expand Up @@ -353,7 +353,7 @@ - (void)reset
}

currentPictureURL = nil;
currentPictureThumbURL = nil;
currentDownloadId = nil;
uploadedPictureURL = nil;
isAvatarUpdated = NO;
[self updateUserPictureButton:self.picturePlaceholder];
Expand Down Expand Up @@ -583,23 +583,36 @@ - (void)updateUserPicture:(NSString *)avatar_url force:(BOOL)force
uploadedPictureURL = nil;

currentPictureURL = [avatar_url isEqual:[NSNull null]] ? nil : avatar_url;
if (currentPictureURL)

// Check whether this url is valid
currentDownloadId = [MXMediaManager thumbnailDownloadIdForMatrixContentURI:currentPictureURL
inFolder:kMXMediaManagerAvatarThumbnailFolder
toFitViewSize:self.userPictureButton.frame.size
withMethod:MXThumbnailingMethodCrop];
if (!currentDownloadId)
{
// Set the placeholder in case of invalid Matrix Content URI.
[self updateUserPictureButton:self.picturePlaceholder];
}
else
{
// Suppose this url is a matrix content uri, we use SDK to get the well adapted thumbnail from server
currentPictureThumbURL = [self.mainSession.matrixRestClient urlOfContentThumbnail:currentPictureURL toFitViewSize:self.userPictureButton.frame.size withMethod:MXThumbnailingMethodCrop];

NSString *cacheFilePath = [MXMediaManager cachePathForMediaWithURL:currentPictureThumbURL andType:nil inFolder:kMXMediaManagerAvatarThumbnailFolder];

// Check whether the image download is in progress
id loader = [MXMediaManager existingDownloaderWithOutputFilePath:cacheFilePath];
id loader = [MXMediaManager existingDownloaderWithIdentifier:currentDownloadId];
if (loader)
{
// Add observers
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaDownloadEnd:) name:kMXMediaDownloadDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaDownloadEnd:) name:kMXMediaDownloadDidFailNotification object:nil];
// Observe this loader
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMediaLoaderStateChange:)
name:kMXMediaLoaderStateDidChangeNotification
object:loader];
}
else
{
NSString *cacheFilePath = [MXMediaManager thumbnailCachePathForMatrixContentURI:currentPictureURL
andType:nil
inFolder:kMXMediaManagerAvatarThumbnailFolder
toFitViewSize:self.userPictureButton.frame.size
withMethod:MXThumbnailingMethodCrop];
// Retrieve the image from cache
UIImage* image = [MXMediaManager loadPictureFromFilePath:cacheFilePath];
if (image)
Expand All @@ -608,23 +621,21 @@ - (void)updateUserPicture:(NSString *)avatar_url force:(BOOL)force
}
else
{
// Cancel potential download in progress
if (imageLoader)
{
[imageLoader cancel];
}
// Add observers
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaDownloadEnd:) name:kMXMediaDownloadDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaDownloadEnd:) name:kMXMediaDownloadDidFailNotification object:nil];
imageLoader = [MXMediaManager downloadMediaFromURL:currentPictureThumbURL andSaveAtFilePath:cacheFilePath];
// Download the image, by adding download observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMediaLoaderStateChange:)
name:kMXMediaLoaderStateDidChangeNotification
object:nil];
imageLoader = [self.mainSession.mediaManager downloadThumbnailFromMatrixContentURI:currentPictureURL
withType:nil
inFolder:kMXMediaManagerAvatarThumbnailFolder
toFitViewSize:self.userPictureButton.frame.size
withMethod:MXThumbnailingMethodCrop
success:nil
failure:nil];
}
}
}
else
{
// Set placeholder
[self updateUserPictureButton:self.picturePlaceholder];
}
}
}

Expand All @@ -644,38 +655,36 @@ - (void)updateSaveUserInfoButtonStatus
saveUserInfoButton.enabled = (isDisplayNameUpdated || isAvatarUpdated) && !isSavingInProgress;
}

- (void)onMediaDownloadEnd:(NSNotification *)notif
- (void)onMediaLoaderStateChange:(NSNotification *)notif
{
// sanity check
if ([notif.object isKindOfClass:[NSString class]])
MXMediaLoader *loader = (MXMediaLoader*)notif.object;
if ([loader.downloadId isEqualToString:currentDownloadId])
{
NSString* url = notif.object;
NSString* cacheFilePath = notif.userInfo[kMXMediaLoaderFilePathKey];

if ([url isEqualToString:currentPictureThumbURL])
{
// update the image
UIImage* image = nil;

if (cacheFilePath.length)
{
image = [MXMediaManager loadPictureFromFilePath:cacheFilePath];
}
if (image == nil)
// update the image
switch (loader.state) {
case MXMediaLoaderStateDownloadCompleted:
{
image = self.picturePlaceholder;
UIImage *image = [MXMediaManager loadPictureFromFilePath:loader.downloadOutputFilePath];
if (image == nil)
{
image = self.picturePlaceholder;
}
[self updateUserPictureButton:image];
// remove the observers
[[NSNotificationCenter defaultCenter] removeObserver:self];
imageLoader = nil;
break;
}
[self updateUserPictureButton:image];

// remove the observers
[[NSNotificationCenter defaultCenter] removeObserver:self];
imageLoader = nil;

if ([notif.name isEqualToString:kMXMediaDownloadDidFailNotification])
{
case MXMediaLoaderStateDownloadFailed:
[self updateUserPictureButton:self.picturePlaceholder];
// remove the observers
[[NSNotificationCenter defaultCenter] removeObserver:self];
imageLoader = nil;
// Reset picture URL in order to try next time
currentPictureURL = nil;
}
break;
default:
break;
}
}
}
Expand Down
Loading