From f17b02b174893f495d22204279187affc91b87cb Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 27 Mar 2025 11:44:30 +1100 Subject: [PATCH] fix an issue where call duration won't show --- Session/Calls/CallVC.swift | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift index 761c06279..75e706aa9 100644 --- a/Session/Calls/CallVC.swift +++ b/Session/Calls/CallVC.swift @@ -18,7 +18,6 @@ final class CallVC: UIViewController, VideoPreviewDelegate, AVRoutePickerViewDel let call: SessionCall var latestKnownAudioOutputDeviceName: String? var durationTimer: Timer? - var duration: Int = 0 var shouldRestartCamera = true weak var conversationVC: ConversationVC? = nil @@ -479,18 +478,28 @@ final class CallVC: UIViewController, VideoPreviewDelegate, AVRoutePickerViewDel _ = call.videoCapturer // Force the lazy var to instantiate titleLabel.text = self.call.contactName - dependencies[singleton: .callManager].startCall(call) { [weak self] error in - DispatchQueue.main.async { - if let _ = error { - self?.callInfoLabel.text = "callsErrorStart".localized() - self?.endCall() - } - else { - self?.callInfoLabel.text = "callsRinging".localized() - self?.answerButton.isHidden = true + if self.call.hasConnected { + callDurationLabel.isHidden = false + durationTimer?.invalidate() + durationTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in + self?.updateDuration() + } + } else { + callDurationLabel.isHidden = true + dependencies[singleton: .callManager].startCall(call) { [weak self] error in + DispatchQueue.main.async { + if let _ = error { + self?.callInfoLabel.text = "callsErrorStart".localized() + self?.endCall() + } + else { + self?.callInfoLabel.text = "callsRinging".localized() + self?.answerButton.isHidden = true + } } } } + setUpOrientationMonitoring() NotificationCenter.default.addObserver(self, selector: #selector(audioRouteDidChange), name: AVAudioSession.routeChangeNotification, object: nil) } @@ -714,8 +723,9 @@ final class CallVC: UIViewController, VideoPreviewDelegate, AVRoutePickerViewDel // stringlint:ignore_contents @objc private func updateDuration() { + guard let connectedDate = call.connectedDate else { return } + let duration = Int(Date().timeIntervalSince1970 - connectedDate.timeIntervalSince1970) callDurationLabel.text = String(format: "%.2d:%.2d", duration/60, duration%60) - duration += 1 } // MARK: - Minimize to a floating view