From 2850266d0b0ba329d3ec0dfbdd1cc87a466c30ee Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 2 Mar 2019 15:49:12 -0700 Subject: [PATCH] Only show "missed call" notification for incoming calls Show outgoing missed and busy calls as "incomplete outgoing call - [call back]" --- Signal/src/call/CallService.swift | 59 ++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index 197561c7c..d2eead0ab 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -609,12 +609,7 @@ private class SignalCallData: NSObject { public func handleMissedCall(_ call: SignalCall) { AssertIsOnMainThread() - // Insert missed call record - if let callRecord = call.callRecord { - if callRecord.callType == RPRecentCallTypeIncoming { - callRecord.updateCallType(RPRecentCallTypeIncomingMissed) - } - } else { + if call.callRecord == nil { // MJK TODO remove this timestamp param call.callRecord = TSCall(timestamp: NSDate.ows_millisecondTimeStamp(), withCallNumber: call.thread.contactIdentifier(), @@ -622,10 +617,27 @@ private class SignalCallData: NSObject { in: call.thread) } - assert(call.callRecord != nil) - call.callRecord?.save() + guard let callRecord = call.callRecord else { + handleFailedCall(failedCall: call, error: .assertionError(description: "callRecord was unexpectedly nil")) + return + } - self.callUIAdapter.reportMissedCall(call) + switch callRecord.callType { + case RPRecentCallTypeIncomingMissed: + callRecord.save() + callUIAdapter.reportMissedCall(call) + case RPRecentCallTypeIncomingIncomplete, RPRecentCallTypeIncoming: + callRecord.updateCallType(RPRecentCallTypeIncomingMissed) + callUIAdapter.reportMissedCall(call) + case RPRecentCallTypeOutgoingIncomplete: + callRecord.updateCallType(RPRecentCallTypeOutgoingMissed) + case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity, RPRecentCallTypeIncomingDeclined, RPRecentCallTypeOutgoingMissed, RPRecentCallTypeOutgoing: + owsFailDebug("unexpected RPRecentCallType: \(callRecord.callType)") + callRecord.save() + default: + callRecord.save() + owsFailDebug("unknown RPRecentCallType: \(callRecord.callType)") + } } /** @@ -670,6 +682,9 @@ private class SignalCallData: NSObject { } call.state = .remoteBusy + assert(call.callRecord != nil) + call.callRecord?.updateCallType(RPRecentCallTypeOutgoingMissed) + callUIAdapter.remoteBusy(call) terminateCall() } @@ -1921,3 +1936,29 @@ private class SignalCallData: NSObject { handleFailedCall(failedCall: call, error: CallError.messageSendFailure(underlyingError: error)) } } + +extension RPRecentCallType: CustomStringConvertible { + public var description: String { + switch self { + case RPRecentCallTypeIncoming: + return "RPRecentCallTypeIncoming" + case RPRecentCallTypeOutgoing: + return "RPRecentCallTypeOutgoing" + case RPRecentCallTypeIncomingMissed: + return "RPRecentCallTypeIncomingMissed" + case RPRecentCallTypeOutgoingIncomplete: + return "RPRecentCallTypeOutgoingIncomplete" + case RPRecentCallTypeIncomingIncomplete: + return "RPRecentCallTypeIncomingIncomplete" + case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity: + return "RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity" + case RPRecentCallTypeIncomingDeclined: + return "RPRecentCallTypeIncomingDeclined" + case RPRecentCallTypeOutgoingMissed: + return "RPRecentCallTypeOutgoingMissed" + default: + owsFailDebug("unexpected RPRecentCallType: \(self)") + return "RPRecentCallTypeUnknown" + } + } +}