complete resend function

This commit is contained in:
Danmei Chen 2018-08-22 11:59:22 +02:00
parent f3aa7b4555
commit dae0d9a093
6 changed files with 78 additions and 41 deletions

View file

@ -28,6 +28,8 @@
@protocol ChatConversationDelegate <NSObject>
- (BOOL)startImageUpload:(UIImage *)image assetId:(NSString *)phAssetId withQuality:(float)quality;
- (BOOL)startFileUpload:(NSData *)data assetId:(NSString *)phAssetId;
- (BOOL)startFileUpload:(NSData *)data withName:(NSString *)name;
- (void)resendChat:(NSString *)message withExternalUrl:(NSString *)url;
- (void)tableViewIsScrolling;

View file

@ -32,7 +32,7 @@
#include "linphone/linphonecore.h"
@interface ChatConversationView
: TPMultiLayoutViewController <HPGrowingTextViewDelegate, UICompositeViewDelegate, ImagePickerDelegate, ChatConversationDelegate, UIDocumentPickerDelegate,
: TPMultiLayoutViewController <HPGrowingTextViewDelegate, UICompositeViewDelegate, ImagePickerDelegate, ChatConversationDelegate,
UIDocumentInteractionControllerDelegate, UISearchBarDelegate, UIImageViewDeletableDelegate, UICollectionViewDataSource> {
OrderedDictionary *imageQualities;
BOOL scrollOnGrowingEnabled;
@ -61,7 +61,6 @@
@property (weak, nonatomic) IBOutlet UIIconButton *infoButton;
@property (weak, nonatomic) IBOutlet UILabel *particpantsLabel;
@property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController;
@property (nonatomic, strong) UIDocumentPickerViewController *documentPicker;
@property NSMutableArray <UIImage *> *imagesArray;
@property NSMutableArray <NSString *> *assetIdsArray;
@property NSMutableArray <NSNumber *> *qualitySettingsArray;
@ -81,7 +80,6 @@
- (IBAction)onDeleteClick:(id)sender;
- (IBAction)onEditionChangeClick:(id)sender;
- (void)update;
- (void)getIcloudFiles;
- (void)openFile:(NSString *) filePath;
- (void)clearMessageView;

View file

@ -626,7 +626,7 @@ static UICompositeViewDescription *compositeDescription = nil;
return TRUE;
}
- (BOOL)startFileUpload:(NSData *)data assetId:phAssetId {
- (BOOL)startFileUpload:(NSData *)data assetId:(NSString *)phAssetId {
FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init];
[fileTransfer uploadVideo:data withassetId:phAssetId forChatRoom:_chatRoom];
[_tableController scrollToBottom:true];
@ -907,16 +907,6 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
[view.tableController scrollToBottom:true];
}
- (void)getIcloudFiles
{
_documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"]
inMode:UIDocumentPickerModeImport];
_documentPicker.delegate = self;
_documentPicker.modalPresentationStyle = UIModalPresentationOverCurrentContext ;
[self presentViewController:_documentPicker animated:YES completion:nil];
}
- (void)openFile:(NSString *) filePath
{
// Open the controller.
@ -931,21 +921,6 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
}
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingWithoutChanges error:nil byAccessor:^(NSURL * _Nonnull newURL) {
NSString *fileName = [newURL lastPathComponent];
NSData *data = [NSData dataWithContentsOfURL:newURL];
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil];
[self openFile:filePath];
}];
}
- (void)deleteImageWithAssetId:(NSString *)assetId {
NSUInteger key = [_assetIdsArray indexOfObject:assetId];
[_imagesArray removeObjectAtIndex:key];

View file

@ -279,8 +279,10 @@
} else {
[self fileErrorBlock];
}
} else
[view getIcloudFiles];
} else {
[LinphoneManager setValueInMessageAppData:@"onFileClick" forKey:@"icloudFileOption" inMessage:self.message];
[super getIcloudFiles];
}
}

View file

@ -23,7 +23,7 @@
#import "ChatConversationTableView.h"
#import "UIRoundedImageView.h"
@interface UIChatBubbleTextCell : UITableViewCell
@interface UIChatBubbleTextCell : UITableViewCell <UIDocumentPickerDelegate>
@property(readonly, nonatomic) LinphoneEventLog *event;
@property(readonly, nonatomic) LinphoneChatMessage *message;
@ -40,11 +40,14 @@
@property(weak, nonatomic) IBOutlet UIImageView *imdmIcon;
@property(weak, nonatomic) IBOutlet UILabel *imdmLabel;
@property (nonatomic, strong) UIDocumentPickerViewController *documentPicker;
+ (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width;
+ (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize withWidth:(int)width;
- (void)setEvent:(LinphoneEventLog *)event;
- (void)setChatMessage:(LinphoneChatMessage *)message;
- (void)getIcloudFiles;
- (void)onDelete;
- (void)onResend;

View file

@ -128,7 +128,7 @@
_statusInProgressSpinner.accessibilityLabel = @"Delivery in progress";
if (_messageText) {
if (_messageText && ![LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message]) {
LOGD(_messageText.text);
[_messageText setHidden:FALSE];
/* We need to use an attributed string here so that data detector don't mess
@ -207,6 +207,36 @@
[PhoneMainView.instance presentViewController:errView animated:YES completion:nil];
}
- (void)getIcloudFiles {
_documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"]
inMode:UIDocumentPickerModeImport];
_documentPicker.delegate = self;
_documentPicker.modalPresentationStyle = UIModalPresentationOverCurrentContext ;
ChatConversationView *view = VIEW(ChatConversationView);
[view presentViewController:_documentPicker animated:YES completion:nil];
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingWithoutChanges error:nil byAccessor:^(NSURL * _Nonnull newURL) {
NSString *fileName = [newURL lastPathComponent];
NSData *data = [NSData dataWithContentsOfURL:newURL];
NSString *option = [LinphoneManager getMessageAppDataForKey:@"icloudFileOption" inMessage:self.message];
if ([option isEqualToString:@"onResend"])
[_chatRoomDelegate startFileUpload:data withName:fileName];
else if ([option isEqualToString:@"onFileClick"]) {
ChatConversationView *view = VIEW(ChatConversationView);
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil];
[view openFile:filePath];
}
}];
}
#pragma mark - Action Functions
- (void)onDelete {
@ -235,10 +265,8 @@
if (linphone_chat_message_get_file_transfer_information(_message) != NULL) {
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:_message];
NSNumber *uploadQuality =[LinphoneManager getMessageAppDataForKey:@"uploadQuality" inMessage:_message];
// TODO: do resend for video and files
/*NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message];*/
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message];
[self onDelete];
if(localImage){
@ -254,6 +282,9 @@
if (![assets firstObject])
return;
PHAsset *asset = [assets firstObject];
if (asset.mediaType != PHAssetMediaTypeImage)
return;
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.synchronous = TRUE;
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options
@ -268,10 +299,36 @@
}
}];
}
} /*else if(fileName) {
NSString *filePath = [LinphoneManager documentFile:fileName];
[_chatRoomDelegate startFileUpload:[NSData dataWithContentsOfFile:filePath] withUrl:[NSURL URLWithString:filePath]];
}*/
} else if (localVideo) {
PHFetchResult<PHAsset *> *assets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObject:localVideo] options:nil];
if (![assets firstObject])
return;
PHAsset *asset = [assets firstObject];
if (asset.mediaType != PHAssetMediaTypeVideo)
return;
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
AVURLAsset *urlAsset = (AVURLAsset *)asset;
NSURL *url = urlAsset.URL;
NSData *data = [NSData dataWithContentsOfURL:url];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL),
^(void) {
[_chatRoomDelegate startFileUpload:data assetId:localVideo];
});
}];
} else if (localFile) {
[LinphoneManager setValueInMessageAppData:@"onResend" forKey:@"icloudFileOption" inMessage:_message];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL),
^(void) {
[self getIcloudFiles];
});
}
} else {
[self onDelete];
double delayInSeconds = 0.4;