From 47a20d1cc9500d211119ad5bded6406a43312ae7 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 29 Jul 2021 16:03:21 +1000 Subject: [PATCH] Resolve more errors --- .../Individual/IndividualCallService.swift | 49 ++++--------------- Session/Notifications/AppNotifications.swift | 6 +++ .../Utilities/UIViewController+Permissions.h | 1 + .../Utilities/UIViewController+Permissions.m | 5 ++ 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/Session/Calls/Individual/IndividualCallService.swift b/Session/Calls/Individual/IndividualCallService.swift index e2e7a3595..12205463f 100644 --- a/Session/Calls/Individual/IndividualCallService.swift +++ b/Session/Calls/Individual/IndividualCallService.swift @@ -219,11 +219,10 @@ import WebRTC sentAtTimestamp: UInt64, serverReceivedTimestamp: UInt64, serverDeliveryTimestamp: UInt64, - callType: SSKProtoCallMessageOfferType, + callType: SNProtoCallMessageOfferType, supportsMultiRing: Bool ) { AssertIsOnMainThread() - Logger.info("callId: \(callId), thread: \(thread.contactAddress)") // opaque is required. sdp is obsolete, but it might still come with opaque. guard let opaque = opaque else { @@ -240,26 +239,6 @@ import WebRTC BenchEventStart(title: "Incoming Call Connection", eventId: "call-\(newCall.individualCall.localId)") - guard tsAccountManager.isOnboarded() else { - Logger.warn("user is not onboarded, skipping call.") - let callRecord = TSCall( - callType: .incomingMissed, - offerType: newCall.individualCall.offerMediaType, - thread: thread, - sentAtTimestamp: sentAtTimestamp - ) - assert(newCall.individualCall.callRecord == nil) - newCall.individualCall.callRecord = callRecord - databaseStorage.asyncWrite { transaction in - callRecord.anyInsert(transaction: transaction) - } - - newCall.individualCall.state = .localFailure - callService.terminate(call: newCall) - - return - } - if let untrustedIdentity = self.identityManager.untrustedIdentityForSending(to: thread.contactAddress) { Logger.warn("missed a call due to untrusted identity: \(newCall)") @@ -323,7 +302,7 @@ import WebRTC call: newCall, destinationDeviceId: sourceDevice, hangupType: .needPermission, - deviceId: tsAccountManager.storedDeviceId(), + deviceId: 1, useLegacyHangupMessage: true ) @@ -373,12 +352,8 @@ import WebRTC messageAgeSec = (serverDeliveryTimestamp - serverReceivedTimestamp) / 1000 } - // Get the current local device Id, must be valid for lifetime of the call. - let localDeviceId = tsAccountManager.storedDeviceId() - let isPrimaryDevice = tsAccountManager.isPrimaryDevice - do { - try callManager.receivedOffer(call: newCall, sourceDevice: sourceDevice, callId: callId, opaque: opaque, messageAgeSec: messageAgeSec, callMediaType: newCall.individualCall.offerMediaType.asCallMediaType, localDevice: localDeviceId, remoteSupportsMultiRing: supportsMultiRing, isLocalDevicePrimary: isPrimaryDevice, senderIdentityKey: identityKeys.contactIdentityKey, receiverIdentityKey: identityKeys.localIdentityKey) + try callManager.receivedOffer(call: newCall, sourceDevice: sourceDevice, callId: callId, opaque: opaque, messageAgeSec: messageAgeSec, callMediaType: newCall.individualCall.offerMediaType.asCallMediaType, localDevice: 1, remoteSupportsMultiRing: supportsMultiRing, isLocalDevicePrimary: true, senderIdentityKey: identityKeys.contactIdentityKey, receiverIdentityKey: identityKeys.localIdentityKey) } catch { handleFailedCall(failedCall: newCall, error: error) } @@ -389,7 +364,6 @@ import WebRTC */ public func handleReceivedAnswer(thread: TSContactThread, callId: UInt64, sourceDevice: UInt32, sdp: String?, opaque: Data?, supportsMultiRing: Bool) { AssertIsOnMainThread() - Logger.info("callId: \(callId), thread: \(thread.contactAddress)") // opaque is required. sdp is obsolete, but it might still come with opaque. guard let opaque = opaque else { @@ -420,7 +394,6 @@ import WebRTC */ public func handleReceivedIceCandidates(thread: TSContactThread, callId: UInt64, sourceDevice: UInt32, candidates: [SSKProtoCallMessageIceUpdate]) { AssertIsOnMainThread() - Logger.info("callId: \(callId), thread: \(thread.contactAddress)") let iceCandidates = candidates.filter { $0.id == callId && $0.opaque != nil }.map { $0.opaque! } @@ -443,7 +416,6 @@ import WebRTC */ public func handleReceivedHangup(thread: TSContactThread, callId: UInt64, sourceDevice: UInt32, type: SSKProtoCallMessageHangupType, deviceId: UInt32) { AssertIsOnMainThread() - Logger.info("callId: \(callId), thread: \(thread.contactAddress)") let hangupType: HangupType switch type { @@ -469,7 +441,6 @@ import WebRTC */ public func handleReceivedBusy(thread: TSContactThread, callId: UInt64, sourceDevice: UInt32) { AssertIsOnMainThread() - Logger.info("callId: \(callId), thread: \(thread.contactAddress)") do { try callManager.receivedBusy(sourceDevice: sourceDevice, callId: callId) @@ -827,7 +798,7 @@ import WebRTC Logger.info("shouldSendOffer") firstly { () throws -> Promise in - let offerBuilder = SSKProtoCallMessageOffer.builder(id: callId) + let offerBuilder = SNProtoCallMessageOffer.builder(id: callId) offerBuilder.setOpaque(opaque) switch callMediaType { case .audioCall: offerBuilder.setType(.offerAudioCall) @@ -850,7 +821,7 @@ import WebRTC Logger.info("shouldSendAnswer") firstly { () throws -> Promise in - let answerBuilder = SSKProtoCallMessageAnswer.builder(id: callId) + let answerBuilder = SNProtoCallMessageAnswer.builder(id: callId) answerBuilder.setOpaque(opaque) let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, answerMessage: try answerBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId)) return messageSender.sendMessage(.promise, callMessage.asPreparer) @@ -869,11 +840,11 @@ import WebRTC Logger.info("shouldSendIceCandidates") firstly { () throws -> Promise in - var iceUpdateProtos = [SSKProtoCallMessageIceUpdate]() + var iceUpdateProtos = [SNProtoCallMessageIceUpdate]() for iceCandidate in candidates { - let iceUpdateProto: SSKProtoCallMessageIceUpdate - let iceUpdateBuilder = SSKProtoCallMessageIceUpdate.builder(id: callId) + let iceUpdateProto: SNProtoCallMessageIceUpdate + let iceUpdateBuilder = SNProtoCallMessageIceUpdate.builder(id: callId) iceUpdateBuilder.setOpaque(iceCandidate) iceUpdateProto = try iceUpdateBuilder.build() @@ -901,7 +872,7 @@ import WebRTC Logger.info("shouldSendHangup") firstly { () throws -> Promise in - let hangupBuilder = SSKProtoCallMessageHangup.builder(id: callId) + let hangupBuilder = SNProtoCallMessageHangup.builder(id: callId) switch hangupType { case .normal: hangupBuilder.setType(.hangupNormal) @@ -939,7 +910,7 @@ import WebRTC Logger.info("shouldSendBusy") firstly { () throws -> Promise in - let busyBuilder = SSKProtoCallMessageBusy.builder(id: callId) + let busyBuilder = SNProtoCallMessageBusy.builder(id: callId) let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, busyMessage: try busyBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId)) return messageSender.sendMessage(.promise, callMessage.asPreparer) }.done { diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index 594430aeb..2ab06e1fc 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -439,3 +439,9 @@ extension TruncatedList: Collection { return contents.index(after: i) } } + +public protocol IndividualCallNotificationInfo { + var remoteAddress: SignalServiceAddress { get } + var localId: UUID { get } + var offerMediaType: TSRecentCallOfferType { get } +} diff --git a/Session/Utilities/UIViewController+Permissions.h b/Session/Utilities/UIViewController+Permissions.h index 9e109d468..4531af2ff 100644 --- a/Session/Utilities/UIViewController+Permissions.h +++ b/Session/Utilities/UIViewController+Permissions.h @@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)ows_askForCameraPermissions:(void (^)(BOOL granted))callback; - (void)ows_askForMediaLibraryPermissions:(void (^)(BOOL granted))callbackParam; - (void)ows_askForMicrophonePermissions:(void (^)(BOOL granted))callback; +- (void)ows_showNoMicrophonePermissionActionSheet; @end diff --git a/Session/Utilities/UIViewController+Permissions.m b/Session/Utilities/UIViewController+Permissions.m index bed8a8800..e378e05e8 100644 --- a/Session/Utilities/UIViewController+Permissions.m +++ b/Session/Utilities/UIViewController+Permissions.m @@ -171,6 +171,11 @@ NS_ASSUME_NONNULL_BEGIN [[AVAudioSession sharedInstance] requestRecordPermission:callback]; } +- (void)ows_showNoMicrophonePermissionActionSheet +{ + // TODO: Implement this. Ideally we'd subclass the Sheet class to keep things consistent in terms of style. +} + @end NS_ASSUME_NONNULL_END