diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 6c3f8e468..35c550aad 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -261,8 +261,14 @@ static UICompositeViewDescription *compositeDescription = nil; NSString *key = [[fileName componentsSeparatedByString:@"."] firstObject]; NSMutableDictionary * assetDict = [LinphoneUtils photoAssetsDictionary]; if ([fileName hasSuffix:@"JPG"] || [fileName hasSuffix:@"PNG"]) { - UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]]; - [self chooseImageQuality:image assetId:[[assetDict objectForKey:key] localIdentifier]]; + PHAsset *phasset = [assetDict objectForKey:key]; + if (!phasset) { + // for the images not really in the photo album + [self confirmShare:dict[@"nsData"] url:nil fileName:fileName assetId:nil]; + } else { + UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]]; + [self chooseImageQuality:image assetId:[phasset localIdentifier]]; + } } else if ([fileName hasSuffix:@"MOV"]) { [self confirmShare:dict[@"nsData"] url:nil fileName:nil assetId:[[assetDict objectForKey:key] localIdentifier]]; } else { diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index 9600fa1c4..d72cd6724 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -107,6 +107,7 @@ _messageImageView.hidden = YES; _imageGestureRecognizer.enabled = YES; _finalImage.hidden = NO; + _fileView.hidden = YES; [self layoutSubviews]; }); } @@ -189,9 +190,16 @@ } } else if (localFile) { - NSString *text = [NSString stringWithFormat:@"📎 %@",localFile]; - _fileName.text = text; - [self loadFileAsset]; + if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) { + ChatConversationView *view = VIEW(ChatConversationView); + NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]]; + UIImage *image = [[UIImage alloc] initWithData:data]; + [self loadImageAsset:nil image:image]; + } else { + NSString *text = [NSString stringWithFormat:@"📎 %@",localFile]; + _fileName.text = text; + [self loadFileAsset]; + } } // we are uploading the image @@ -303,6 +311,19 @@ ImageView *view = VIEW(ImageView); [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; PHAsset *asset = [_messageImageView asset]; + 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]]; + UIImage *image = [[UIImage alloc] initWithData:data]; + if (image) + [view setImage:image]; + else + LOGE(@"Can't read image"); + } + return; + } PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = TRUE; [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index b99c63a9d..3d7dae515 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -456,18 +456,29 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 44; // 44; NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:chat]; NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:chat]; + CGSize textSize = CGSizeMake(0, 0); + if (![messageText isEqualToString:@"🗻"]) { + textSize = [self computeBoundingBox:messageText + size:CGSizeMake(width - CELL_MESSAGE_X_MARGIN - 4, CGFLOAT_MAX) + font:messageFont]; + size.height += textSize.height; + } + if(localFile) { - CGSize fileSize = CGSizeMake(230, 50); - size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width]; - } else { - CGSize textSize = CGSizeMake(0, 0); - if (![messageText isEqualToString:@"🗻"]) { - textSize = [self computeBoundingBox:messageText - size:CGSizeMake(width - CELL_MESSAGE_X_MARGIN - 4, CGFLOAT_MAX) - font:messageFont]; + if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) { + ChatConversationView *view = VIEW(ChatConversationView); + NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]]; + UIImage *image = [[UIImage alloc] initWithData:data]; + size = [self getMediaMessageSizefromOriginalSize:image.size withWidth:width]; + + // add size for message text size.height += textSize.height; + size.width = MAX(textSize.width, size.width); + } else { + CGSize fileSize = CGSizeMake(230, 50); + size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width]; } - + } else { if (!localImage && !localVideo) { //We are loading the image return CGSizeMake(CELL_MIN_WIDTH + CELL_MESSAGE_X_MARGIN, CELL_MIN_HEIGHT + CELL_MESSAGE_Y_MARGIN + textSize.height + 20); diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index b7beb0d49..97d678319 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -73,23 +73,6 @@ return assetDict; } -/*+ (NSMutableDictionary *)videoAssetsDictionary { - NSMutableDictionary *assetDict = [NSMutableDictionary dictionary]; - - PHFetchOptions *options = [[PHFetchOptions alloc] init]; - [options setIncludeHiddenAssets:YES]; - [options setIncludeAllBurstAssets:YES]; - - PHFetchResult *fetchRes = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:options]; - - for (PHAsset *asset in fetchRes) { - NSString *key = [asset valueForKey:@"filename"]; - [assetDict setObject:asset forKey:[[key componentsSeparatedByString:@"."] firstObject]]; - } - - return assetDict; -}*/ - + (NSString *)timeToString:(time_t)time withFormat:(LinphoneDateFormat)format { NSString *formatstr; NSDate *todayDate = [[NSDate alloc] init]; diff --git a/linphoneExtension/ShareViewController.m b/linphoneExtension/ShareViewController.m index cdd142d75..ce80ad74b 100644 --- a/linphoneExtension/ShareViewController.m +++ b/linphoneExtension/ShareViewController.m @@ -42,7 +42,9 @@ [self loadItem:provider typeIdentifier:@"com.adobe.pdf" defaults:defaults]; } else if ([provider hasItemConformingToTypeIdentifier:@"public.png"]) { [self loadItem:provider typeIdentifier:@"public.png" defaults:defaults]; - } else{ + } else if ([provider hasItemConformingToTypeIdentifier:@"public.image"]) { + [self loadItem:provider typeIdentifier:@"public.image" defaults:defaults]; + }else{ NSLog(@"Unkown itemprovider = %@", provider); support = false; } @@ -96,22 +98,35 @@ [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; } - UIResponder *responder = self; - while (responder != nil) { - if ([responder respondsToSelector:@selector(openURL:)]) { - [responder performSelector:@selector(openURL:) - withObject:[NSURL URLWithString:@"message-linphone://" ]]; - [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; - break; - } - responder = [responder nextResponder]; - } - [defaults synchronize]; + [self respondUrl:defaults]; + } else if ([(NSObject*)item isKindOfClass:[UIImage class]]) { + UIImage *image = (UIImage*)item; + NSDictionary *dict = @{@"nsData" : UIImagePNGRepresentation(image), + @"url" : [NSString stringWithFormat:@"IMAGE_%f.PNG", [[NSDate date] timeIntervalSince1970]], + @"message" : self.contentText}; + [defaults setObject:dict forKey:@"photoData"]; + + [self respondUrl:defaults]; } else { //share text NSLog(@"Unsupported provider = %@", provider); + [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; } }]; } +- (void)respondUrl:(NSUserDefaults *)defaults { + UIResponder *responder = self; + while (responder != nil) { + if ([responder respondsToSelector:@selector(openURL:)]) { + [responder performSelector:@selector(openURL:) + withObject:[NSURL URLWithString:@"message-linphone://" ]]; + [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; + break; + } + responder = [responder nextResponder]; + } + [defaults synchronize]; +} + @end