diff --git a/Classes/Swift/Chat/ViewModels/ChatConversationTableViewModel.swift b/Classes/Swift/Chat/ViewModels/ChatConversationTableViewModel.swift index 82938c739..3a40ca438 100644 --- a/Classes/Swift/Chat/ViewModels/ChatConversationTableViewModel.swift +++ b/Classes/Swift/Chat/ViewModels/ChatConversationTableViewModel.swift @@ -18,7 +18,7 @@ class ChatConversationTableViewModel: ControlsViewModel { var chatRoom: ChatRoom? = nil - var nbEventDisplayed = MutableLiveData(20) + var refreshIndexPath = MutableLiveData(0) override init() { super.init() @@ -68,4 +68,8 @@ class ChatConversationTableViewModel: ControlsViewModel { func eventTypeIsOfInterestForOne(toOneRoom type: EventLogType) -> Bool { return type.rawValue == LinphoneEventLogTypeConferenceChatMessage.rawValue || type.rawValue == LinphoneEventLogTypeConferenceEphemeralMessageEnabled.rawValue || type.rawValue == LinphoneEventLogTypeConferenceEphemeralMessageDisabled.rawValue || type.rawValue == LinphoneEventLogTypeConferenceEphemeralMessageLifetimeChanged.rawValue } + + func reloadCollectionViewCell(){ + refreshIndexPath.value! += 1 + } } diff --git a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift index 46e17f423..381e84b86 100644 --- a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift @@ -44,10 +44,10 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour } NotificationCenter.default.addObserver(self, selector: #selector(self.rotated), name: UIDevice.orientationDidChangeNotification, object: nil) - - ChatConversationTableViewModel.sharedModel.nbEventDisplayed.observe { index in - self.collectionView.reloadData() - } + + ChatConversationTableViewModel.sharedModel.refreshIndexPath.observe { index in + self.collectionView.reloadData() + } collectionView.isUserInteractionEnabled = true @@ -155,7 +155,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour } if let event = ChatConversationTableViewModel.sharedModel.getMessage(index: indexPath.row){ - cell.configure(event: event) + cell.configure(event: event, selfIndexPathConfigure: indexPath) if (event.chatMessage != nil){ cell.onLongClickOneClick { @@ -377,4 +377,8 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour message.chatRoom?.deleteMessage(message: message) collectionView.reloadData() } + + public func reloadCollectionViewCell(indexPath: IndexPath){ + collectionView.reloadItems(at: [indexPath]) + } } diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index 1df5797fc..a262fc0cd 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -528,7 +528,7 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI super.prepareForReuse() } - func configure(event: EventLog) { + func configure(event: EventLog, selfIndexPathConfigure: IndexPath) { chatMessage = event.chatMessage addMessageDelegate() if event.chatMessage != nil { @@ -1221,6 +1221,21 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI imagesGridContentCollection[indexTransferProgress] = content imagesGridURLCollection[indexTransferProgress] = (URL(string: content.filePath)!) imagesGridCollectionView[indexTransferProgress] = getImageFrom(content.getCobject, filePath: content.filePath, forReplyBubble: true)! + + + if (imagesGridCollectionView.count <= 1){ + if let imageMessage = createThumbnailOfVideoFromFileURL(videoURL: content.filePath){ + imageVideoViewBubble.image = resizeImage(image: imageMessage, targetSize: CGSizeMake(UIScreen.main.bounds.size.width*3/4, 300.0)) + if (imageVideoViewBubble.image != nil && imagesGridCollectionView.count <= 1){ + ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() + } + } else if let imageMessage = UIImage(named: content.filePath){ + imageViewBubble.image = resizeImage(image: imageMessage, targetSize: CGSizeMake(UIScreen.main.bounds.size.width*3/4, 300.0)) + if (imageViewBubble.image != nil && imagesGridCollectionView.count <= 1){ + ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() + } + } + } collectionViewImagesGrid.reloadItems(at: [IndexPath(row: indexTransferProgress, section: 0)]) indexTransferProgress = -1