From 61a7b7a562acc768ef51060d1edacc92c92ef6fb Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 27 Mar 2023 17:27:09 +0200 Subject: [PATCH] Add image player when click on bubble view --- .../Chat/Views/MultilineMessageCell.swift | 64 ++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index 857b6fcf7..8e7bb654e 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -1381,7 +1381,7 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI var previousEvent : EventLog? = nil let indexOfPreviousEvent = indexPath.row + 1 previousEvent = ChatConversationTableViewModel.sharedModel.getMessage(index: indexPath.row+1) - if (indexOfPreviousEvent > -1) { + if (indexOfPreviousEvent > -1 && indexOfPreviousEvent < ChatConversationTableViewModel.sharedModel.getNBMessages()) { if ((previousEvent?.type.rawValue)! != LinphoneEventLogTypeConferenceChatMessage.rawValue) { return true } @@ -1442,10 +1442,70 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI self.ephemeralTimer!.invalidate() ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() } - print("MultilineMessageCell updateEphemeralTimes \(duration)") } } } + + /* + func onImageClick() { + /* + if (_finalImage.tag == FILE_ICON_TAG) { + [self onFileClick:nil]; + return; + } + */ + let state = chatMessage?.state + if (state!.rawValue == LinphoneChatMessageStateNotDelivered.rawValue) { + return; + } else { + //if (![_messageImageView isLoading]) { + let view: ImageView = VIEW(ImageView.compositeViewDescription()) + PhoneMainView.instance().changeCurrentView(view.compositeViewDescription()) + let filePath = LinphoneManager.getMessageAppData(forKey: "encryptedfile", in: chatMessage?.getCobject) + if ((filePath) != nil) { + let image = UIImage(contentsOfFile: filePath as! String) + view.image = image + } + + let localImage: String? = LinphoneManager.getMessageAppData(forKey: "localimage", in: chatMessage?.getCobject) as? String + let localFile: String? = LinphoneManager.getMessageAppData(forKey: "localfile", in: chatMessage?.getCobject) as? String + var imageName : String? = nil + + if ((localImage != nil) && FileManager.default.fileExists(atPath: LinphoneManager.validFilePath(localImage))) { + imageName = localImage + } else if ((localFile != nil) && FileManager.default.fileExists(atPath: LinphoneManager.validFilePath(localFile))) { + if (localFile!.hasSuffix("JPG") || localFile!.hasSuffix("PNG") || localFile!.hasSuffix("jpg") || localFile!.hasSuffix("png")) { + imageName = localFile + } + } + + if ((imageName) != nil) { + let image = UIImage(contentsOfFile: LinphoneManager.validFilePath(imageName)) + if ((image) != nil){ + view.image = image + }else{ + print("Can't read image") + } + } + + let options = PHImageRequestOptions() + options.isSynchronous = true + [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options + resultHandler:^(UIImage *image, NSDictionary * info) { + if (image) { + [view setImage:image]; + } + else { + LOGE(@"Can't read image"); + } + }]; + + PHImageManager.default.requestImage(for: <#T##PHAsset#>, targetSize: <#T##CGSize#>, contentMode: <#T##PHImageContentMode#>, options: <#T##PHImageRequestOptions?#>, resultHandler: <#T##(UIImage?, [AnyHashable : Any]?) -> Void#>) + //} + } + } + */ + } class DynamicHeightCollectionView: UICollectionView {