From dea37b422b198829b7a9210ba769b8c1ad413c9a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 8 Feb 2017 16:39:32 -0500 Subject: [PATCH] Respond to CR. // FREEBIE --- Signal/src/AppDelegate.m | 1 - Signal/src/call/CallAudioService.swift | 6 --- Signal/src/call/CallService.swift | 37 +++---------------- Signal/src/call/SignalCall.swift | 25 +++++++++++-- .../view controllers/CallViewController.swift | 6 --- 5 files changed, 27 insertions(+), 48 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 7bb92aa96..78958343e 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -25,7 +25,6 @@ #import #import #import -#import #import #import #import diff --git a/Signal/src/call/CallAudioService.swift b/Signal/src/call/CallAudioService.swift index d044b9755..69f5ec0fe 100644 --- a/Signal/src/call/CallAudioService.swift +++ b/Signal/src/call/CallAudioService.swift @@ -52,12 +52,6 @@ import Foundation ensureIsEnabled(call: call) } - internal func callRecordDidChange(call: SignalCall, callRecord: TSCall?) { - AssertIsOnMainThread() - - // Do nothing. - } - private func ensureIsEnabled(call: SignalCall) { // Auto-enable speakerphone when local video is enabled. if call.hasLocalVideo { diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index 4217cf2b5..9cf4ba085 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -388,14 +388,17 @@ protocol CallServiceObserver: class { */ public func handleMissedCall(_ call: SignalCall, thread: TSContactThread) { AssertIsOnMainThread() + // Insert missed call record - if call.callRecord == nil { + if let callRecord = call.callRecord { + if (callRecord.callType == RPRecentCallTypeIncoming) { + callRecord.updateCallType(RPRecentCallTypeMissed) + } + } else { call.callRecord = TSCall(timestamp: NSDate.ows_millisecondTimeStamp(), withCallNumber: thread.contactIdentifier(), callType: RPRecentCallTypeMissed, in: thread) - } else if (call.callRecord!.callType == RPRecentCallTypeIncoming) { - call.callRecord!.updateCallType(RPRecentCallTypeMissed) } assert(call.callRecord != nil) @@ -1150,7 +1153,6 @@ protocol CallServiceObserver: class { AssertIsOnMainThread() Logger.info("\(self.TAG) \(#function): \(state)") updateIsVideoEnabled() - updateCallRecordType(call: call) } internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) { @@ -1169,33 +1171,6 @@ protocol CallServiceObserver: class { // Do nothing } - internal func callRecordDidChange(call: SignalCall, callRecord: TSCall?) { - AssertIsOnMainThread() - - updateCallRecordType(call: call) - } - - internal func updateCallRecordType(call: SignalCall?) { - AssertIsOnMainThread() - - guard call != nil else { - return - } - guard call!.callRecord != nil else { - return - } - - // Mark incomplete calls as completed if call has connected. - if call!.state == .connected && - call!.callRecord!.callType == RPRecentCallTypeOutgoingIncomplete { - call!.callRecord!.updateCallType(RPRecentCallTypeOutgoing) - } - if call!.state == .connected && - call!.callRecord!.callType == RPRecentCallTypeIncomingIncomplete { - call!.callRecord!.updateCallType(RPRecentCallTypeIncoming) - } - } - // MARK: - Video private func shouldHaveLocalVideoTrack() -> Bool { diff --git a/Signal/src/call/SignalCall.swift b/Signal/src/call/SignalCall.swift index 974d0477a..0d74aff98 100644 --- a/Signal/src/call/SignalCall.swift +++ b/Signal/src/call/SignalCall.swift @@ -27,7 +27,6 @@ protocol CallObserver: class { func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) func muteDidChange(call: SignalCall, isMuted: Bool) func speakerphoneDidChange(call: SignalCall, isEnabled: Bool) - func callRecordDidChange(call: SignalCall, callRecord: TSCall?) } /** @@ -55,9 +54,7 @@ protocol CallObserver: class { AssertIsOnMainThread() assert(oldValue == nil) - for observer in observers { - observer.value?.callRecordDidChange(call: self, callRecord: callRecord) - } + updateCallRecordType() } } @@ -85,6 +82,8 @@ protocol CallObserver: class { connectedDate = nil } + updateCallRecordType() + for observer in observers { observer.value?.stateDidChange(call: self, state: state) } @@ -164,6 +163,24 @@ protocol CallObserver: class { observers = [] } + private func updateCallRecordType() { + AssertIsOnMainThread() + + guard let callRecord = self.callRecord else { + return + } + + // Mark incomplete calls as completed if call has connected. + if state == .connected && + callRecord.callType == RPRecentCallTypeOutgoingIncomplete { + callRecord.updateCallType(RPRecentCallTypeOutgoing) + } + if state == .connected && + callRecord.callType == RPRecentCallTypeIncomingIncomplete { + callRecord.updateCallType(RPRecentCallTypeIncoming) + } + } + // MARK: Equatable static func == (lhs: SignalCall, rhs: SignalCall) -> Bool { diff --git a/Signal/src/view controllers/CallViewController.swift b/Signal/src/view controllers/CallViewController.swift index 527394878..06a4a049b 100644 --- a/Signal/src/view controllers/CallViewController.swift +++ b/Signal/src/view controllers/CallViewController.swift @@ -733,12 +733,6 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R self.updateCallUI(callState: call.state) } - internal func callRecordDidChange(call: SignalCall, callRecord: TSCall?) { - AssertIsOnMainThread() - - // Do nothing. - } - // MARK: - Video internal func updateLocalVideoTrack(localVideoTrack: RTCVideoTrack?) {