diff --git a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift index fd68a4b9a..cb63f396c 100644 --- a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift @@ -206,6 +206,9 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour if cell.isPlayingVoiceRecording { AudioPlayer.stopSharedPlayer() } + if cell.ephemeralTimer != nil { + cell.ephemeralTimer?.invalidate() + } } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index e9668ebb7..0d36e2e8c 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -121,6 +121,11 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI let recordingView = UIView() + let ephemeralIcon = UIImageView(image: UIImage(named: "ephemeral_messages_color_A.png")) + let ephemeralTimerLabel = StyledLabel(VoipTheme.chat_conversation_ephemeral_timer) + var ephemeralTimer : Timer? = nil + + var isPlayingVoiceRecording = false var chatMessage: ChatMessage? @@ -431,6 +436,20 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI UIDeviceBridge.displayModeSwitched.readCurrentAndObserve { _ in self.replyContent.backgroundColor = VoipTheme.backgroundWhiteBlack.get() } + + //Ephemeral + contentViewBubble.addSubview(ephemeralTimerLabel) + ephemeralTimerLabel.bottomAnchor.constraint(equalTo: contentViewBubble.bottomAnchor, constant: -2).isActive = true + ephemeralTimerLabel.trailingAnchor.constraint(equalTo: contentViewBubble.trailingAnchor, constant: -14).isActive = true + ephemeralTimerLabel.text = "00:00" + ephemeralTimerLabel.height(10).done() + ephemeralTimerLabel.isHidden = true + + contentViewBubble.addSubview(ephemeralIcon) + ephemeralIcon.bottomAnchor.constraint(equalTo: contentViewBubble.bottomAnchor, constant: -3).isActive = true + ephemeralIcon.trailingAnchor.constraint(equalTo: contentViewBubble.trailingAnchor, constant: -6).isActive = true + ephemeralIcon.size(w: 7, h: 8).done() + ephemeralIcon.isHidden = true } func initPlayerAudio(message: ChatMessage){ @@ -590,6 +609,16 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI displayImdnStatus(message: event.chatMessage!, state: event.chatMessage!.state) } + if event.chatMessage!.isEphemeral { + ephemeralTimerLabel.isHidden = false + ephemeralIcon.isHidden = false + contentViewBubble.minWidth(44).done() + updateEphemeralTimes() + }else{ + ephemeralTimerLabel.isHidden = true + ephemeralIcon.isHidden = true + } + if event.chatMessage!.isForward { NSLayoutConstraint.activate(preContentViewBubbleConstraints) NSLayoutConstraint.activate(forwardConstraints) @@ -1375,6 +1404,48 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI return false; } + + func updateEphemeralTimes() { + let f = DateComponentsFormatter() + f.unitsStyle = .positional + f.zeroFormattingBehavior = [.pad] + + if ((chatMessage != nil) && chatMessage!.isEphemeral) { + let duration = self.chatMessage?.ephemeralExpireTime == 0 ? self.chatMessage?.chatRoom?.ephemeralLifetime : self.chatMessage!.ephemeralExpireTime - Int(Date().timeIntervalSince1970) + if(duration! > 86400){ + f.allowedUnits = [.day] + }else if(duration! > 3600){ + f.allowedUnits = [.hour] + }else{ + f.allowedUnits = [.minute, .second] + } + + let textDuration = f.string(for: DateComponents(second: duration))?.capitalized ?? "" + self.ephemeralTimerLabel.text = textDuration + self.ephemeralTimerLabel.isHidden = false + self.ephemeralIcon.isHidden = false + ephemeralTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in + let duration = self.chatMessage?.ephemeralExpireTime == 0 ? self.chatMessage?.ephemeralLifetime : self.chatMessage!.ephemeralExpireTime - Int(Date().timeIntervalSince1970) + if(duration! > 86400){ + f.allowedUnits = [.day] + }else if(duration! > 3600){ + f.allowedUnits = [.hour] + }else{ + f.allowedUnits = [.minute, .second] + } + + let textDuration = f.string(for: DateComponents(second: duration))?.capitalized ?? "" + self.ephemeralTimerLabel.text = textDuration + self.ephemeralTimerLabel.isHidden = false + self.ephemeralIcon.isHidden = false + if(duration! <= 0){ + self.ephemeralTimer!.invalidate() + ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() + } + print("MultilineMessageCell updateEphemeralTimes \(duration)") + } + } + } } class DynamicHeightCollectionView: UICollectionView { diff --git a/Classes/Swift/Voip/Theme/VoipTheme.swift b/Classes/Swift/Voip/Theme/VoipTheme.swift index 0803d5d01..30fbc2d75 100644 --- a/Classes/Swift/Voip/Theme/VoipTheme.swift +++ b/Classes/Swift/Voip/Theme/VoipTheme.swift @@ -157,6 +157,7 @@ import UIKit static let chat_conversation_download_progress_text = TextStyle(fgColor: LightDarkColor(voip_dark_gray,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .center, font: fontName+"-Regular", size: 12.0) static let chat_conversation_avatar_small = TextStyle(fgColor: LightDarkColor(.white,voip_dark_gray), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .center, font: fontName+"-Bold", size: 14.0) static let chat_conversation_contact_date = TextStyle(fgColor: LightDarkColor(voip_dark_gray,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .left, font: fontName+"-Bold", size: 12.0) + static let chat_conversation_ephemeral_timer = TextStyle(fgColor: LightDarkColor(.orange,.orange), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .left, font: fontName+"-Bold", size: 8.0) // Buttons Background (State colors)