mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
simplify the code about local file in chat cell
This commit is contained in:
parent
445b620be5
commit
25ff201116
5 changed files with 22 additions and 29 deletions
|
|
@ -90,6 +90,6 @@
|
|||
|
||||
- (void)autoDownload:(LinphoneChatMessage *)message view:(ChatConversationView *)view inChat:(BOOL)inChat;
|
||||
- (NSURL *)getICloudFileUrl:(NSString *)name;
|
||||
- (void)writeFileInICloud:(NSData *)data fileURL:(NSURL *)fileURL;
|
||||
- (BOOL)writeFileInICloud:(NSData *)data fileURL:(NSURL *)fileURL;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -1033,17 +1033,17 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
|
|||
return nil;
|
||||
}
|
||||
|
||||
- (void)writeFileInICloud:(NSData *)data fileURL:(NSURL *)fileURL {
|
||||
- (BOOL)writeFileInICloud:(NSData *)data fileURL:(NSURL *)fileURL {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if (![[fileManager URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:@"Documents"]) {
|
||||
//notify : set configuration to use icloud
|
||||
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Info", nil) message:NSLocalizedString(@"ICloud Drive is unavailable.", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:nil, nil] show];
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ([fileManager isUbiquitousItemAtURL:fileURL]) {
|
||||
// if it exists, replace the file
|
||||
[data writeToURL:fileURL atomically:TRUE];
|
||||
return [data writeToURL:fileURL atomically:TRUE];
|
||||
} else {
|
||||
// get the url of localfile
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileURL.lastPathComponent];
|
||||
|
|
@ -1053,9 +1053,7 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
|
|||
}
|
||||
|
||||
NSError *error;
|
||||
if (![[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localURL destinationURL:fileURL error:&error]) {
|
||||
LOGE(@"ICloud file error : %@", error);
|
||||
}
|
||||
return [[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localURL destinationURL:fileURL error:&error];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,8 +193,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
}
|
||||
else if (localFile) {
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) {
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]];
|
||||
NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
[self loadImageAsset:nil image:image];
|
||||
} else {
|
||||
|
|
@ -316,8 +315,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
if (!asset) {
|
||||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) {
|
||||
ChatConversationView *chatView = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[chatView getICloudFileUrl:localFile]];
|
||||
NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
if (image)
|
||||
[view setImage:image];
|
||||
|
|
|
|||
|
|
@ -349,8 +349,7 @@
|
|||
}];
|
||||
|
||||
} else if (localFile) {
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]];
|
||||
NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
[_chatRoomDelegate startFileUpload:data withName:localFile];
|
||||
}
|
||||
} else {
|
||||
|
|
@ -467,8 +466,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
|
||||
if(localFile) {
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) {
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]];
|
||||
NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
size = [self getMediaMessageSizefromOriginalSize:image.size withWidth:width];
|
||||
|
||||
|
|
|
|||
|
|
@ -178,17 +178,17 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con
|
|||
|
||||
//write file to path
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[view writeFileInICloud:thiz.data fileURL:[view getICloudFileUrl:name]];
|
||||
[LinphoneManager setValueInMessageAppData:name forKey:key inMessage:message];
|
||||
|
||||
[NSNotificationCenter.defaultCenter
|
||||
postNotificationName:kLinphoneFileTransferRecvUpdate
|
||||
object:thiz
|
||||
userInfo:@{
|
||||
@"state" : @(LinphoneChatMessageStateDelivered), // we dont want to trigger
|
||||
@"progress" : @(1.f), // FileTransferDone here
|
||||
}];
|
||||
|
||||
if([view writeFileInICloud:thiz.data fileURL:[view getICloudFileUrl:name]]) {
|
||||
[LinphoneManager setValueInMessageAppData:name forKey:key inMessage:message];
|
||||
|
||||
[NSNotificationCenter.defaultCenter
|
||||
postNotificationName:kLinphoneFileTransferRecvUpdate
|
||||
object:thiz
|
||||
userInfo:@{
|
||||
@"state" : @(LinphoneChatMessageStateDelivered), // we dont want to trigger
|
||||
@"progress" : @(1.f), // FileTransferDone here
|
||||
}];
|
||||
}
|
||||
[thiz stopAndDestroy];
|
||||
});
|
||||
}
|
||||
|
|
@ -296,9 +296,8 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
|
|||
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withName:(NSString *)name {
|
||||
// we will write local files into ours folder of icloud
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
[view writeFileInICloud:data fileURL:[view getICloudFileUrl:name]];
|
||||
|
||||
[self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil];
|
||||
if ([view writeFileInICloud:data fileURL:[view getICloudFileUrl:name]])
|
||||
[self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue