RoomVC: Handle external file upload.

This commit is contained in:
SBiOSoftWhare 2019-07-11 19:17:55 +02:00
parent 20458bca20
commit 6d63d704f7
2 changed files with 62 additions and 2 deletions

View file

@ -901,4 +901,6 @@
"device_verification_emoji_folder" = "Folder";
"device_verification_emoji_pin" = "Pin";
// MARK: File upload
"file_upload_error_title" = "File upload";
"file_upload_error_unsupported_file_type_message" = "File type not supported.";

View file

@ -124,7 +124,7 @@
#import "Riot-Swift.h"
@interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelegate, RoomTitleViewTapGestureDelegate, RoomParticipantsViewControllerDelegate, MXKRoomMemberDetailsViewControllerDelegate, ContactsTableViewControllerDelegate, MXServerNoticesDelegate, RoomContextualMenuViewControllerDelegate,
ReactionsMenuViewModelCoordinatorDelegate, EditHistoryCoordinatorBridgePresenterDelegate>
ReactionsMenuViewModelCoordinatorDelegate, EditHistoryCoordinatorBridgePresenterDelegate, MXKDocumentPickerPresenterDelegate>
{
// The expanded header
ExpandedRoomTitleView *expandedHeader;
@ -222,6 +222,7 @@
@property (nonatomic, strong) MXKErrorAlertPresentation *errorPresenter;
@property (nonatomic, strong) NSString *textMessageBeforeEditing;
@property (nonatomic, strong) EditHistoryCoordinatorBridgePresenter *editHistoryPresenter;
@property (nonatomic, strong) MXKDocumentPickerPresenter *documentPickerPresenter;
@end
@ -3356,6 +3357,17 @@
}
}
- (void)roomInputToolbarViewDidTapFileUpload:(MXKRoomInputToolbarView *)toolbarView
{
MXKDocumentPickerPresenter *documentPickerPresenter = [MXKDocumentPickerPresenter new];
documentPickerPresenter.delegate = self;
NSArray<MXKUTI*> *allowedUTIs = @[MXKUTI.data];
[documentPickerPresenter presentDocumentPickerWith:allowedUTIs from:self animated:YES completion:nil];
self.documentPickerPresenter = documentPickerPresenter;
}
#pragma mark - RoomParticipantsViewControllerDelegate
- (void)roomParticipantsViewController:(RoomParticipantsViewController *)roomParticipantsViewController mention:(MXRoomMember*)member
@ -5343,5 +5355,51 @@
self.editHistoryPresenter = nil;
}
#pragma mark - DocumentPickerPresenterDelegate
- (void)documentPickerPresenterWasCancelled:(MXKDocumentPickerPresenter *)presenter
{
self.documentPickerPresenter = nil;
}
- (void)documentPickerPresenter:(MXKDocumentPickerPresenter *)presenter didPickDocumentsAt:(NSURL *)url
{
self.documentPickerPresenter = nil;
MXKUTI *fileUTI = [[MXKUTI alloc] initWithLocalFileURL:url];
NSString *mimeType = fileUTI.mimeType;
if (fileUTI.isImage)
{
NSData *imageData = [[NSData alloc] initWithContentsOfURL:url];
[self.roomDataSource sendImage:imageData mimeType:mimeType success:nil failure:^(NSError *error) {
// Nothing to do. The image is marked as unsent in the room history by the datasource
NSLog(@"[MXKRoomViewController] sendImage failed.");
}];
}
else if (fileUTI.isVideo)
{
[(RoomDataSource*)self.roomDataSource sendVideo:url success:nil failure:^(NSError *error) {
// Nothing to do. The video is marked as unsent in the room history by the datasource
NSLog(@"[MXKRoomViewController] sendVideo failed.");
}];
}
else if (fileUTI.isFile)
{
[self.roomDataSource sendFile:url mimeType:mimeType success:nil failure:^(NSError *error) {
// Nothing to do. The file is marked as unsent in the room history by the datasource
NSLog(@"[MXKRoomViewController] sendFile failed.");
}];
}
else
{
NSLog(@"[MXKRoomViewController] File upload using MIME type %@ is not supported.", mimeType);
[[AppDelegate theDelegate] showAlertWithTitle:NSLocalizedStringFromTable(@"file_upload_error_title", @"Vector", nil)
message:NSLocalizedStringFromTable(@"file_upload_error_unsupported_file_type_message", @"Vector", nil)];
}
}
@end