Resolve more errors

This commit is contained in:
Niels Andriesse 2021-07-30 14:23:17 +10:00
parent f0c89b976f
commit b22f66bab3
4 changed files with 76 additions and 88 deletions

View File

@ -52,19 +52,11 @@ public class IndividualCall: NSObject, IndividualCallNotificationInfo {
// Mark - // Mark -
var backgroundTask: OWSBackgroundTask? { var backgroundTask: OWSBackgroundTask? {
didSet { didSet { AssertIsOnMainThread() }
AssertIsOnMainThread()
Logger.info("")
}
} }
var callId: UInt64? { var callId: UInt64? {
didSet { didSet { AssertIsOnMainThread() }
AssertIsOnMainThread()
Logger.info("")
}
} }
let callAdapterType: CallAdapterType let callAdapterType: CallAdapterType
@ -72,8 +64,6 @@ public class IndividualCall: NSObject, IndividualCallNotificationInfo {
weak var remoteVideoTrack: RTCVideoTrack? { weak var remoteVideoTrack: RTCVideoTrack? {
didSet { didSet {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.info("")
delegate?.individualCallRemoteVideoMuteDidChange(self, isVideoMuted: !isRemoteVideoEnabled) delegate?.individualCallRemoteVideoMuteDidChange(self, isVideoMuted: !isRemoteVideoEnabled)
} }
} }
@ -81,8 +71,6 @@ public class IndividualCall: NSObject, IndividualCallNotificationInfo {
var isRemoteVideoEnabled = false { var isRemoteVideoEnabled = false {
didSet { didSet {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.info("\(isRemoteVideoEnabled)")
delegate?.individualCallRemoteVideoMuteDidChange(self, isVideoMuted: !isRemoteVideoEnabled) delegate?.individualCallRemoteVideoMuteDidChange(self, isVideoMuted: !isRemoteVideoEnabled)
} }
} }
@ -90,8 +78,6 @@ public class IndividualCall: NSObject, IndividualCallNotificationInfo {
var isRemoteSharingScreen = false { var isRemoteSharingScreen = false {
didSet { didSet {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.info("\(isRemoteSharingScreen)")
delegate?.individualCallRemoteSharingScreenDidChange(self, isRemoteSharingScreen: isRemoteSharingScreen) delegate?.individualCallRemoteSharingScreenDidChange(self, isRemoteSharingScreen: isRemoteSharingScreen)
} }
} }
@ -191,7 +177,6 @@ public class IndividualCall: NSObject, IndividualCallNotificationInfo {
} }
deinit { deinit {
Logger.debug("")
if !isEnded { if !isEnded {
owsFailDebug("isEnded was unexpectedly false") owsFailDebug("isEnded was unexpectedly false")
} }

View File

@ -69,8 +69,8 @@ import WebRTC
thread: call.individualCall.thread, thread: call.individualCall.thread,
sentAtTimestamp: call.individualCall.sentAtTimestamp sentAtTimestamp: call.individualCall.sentAtTimestamp
) )
databaseStorage.asyncWrite { transaction in Storage.write { transaction in
callRecord.anyInsert(transaction: transaction) callRecord.save(with: transaction)
} }
call.individualCall.callRecord = callRecord call.individualCall.callRecord = callRecord
@ -105,8 +105,8 @@ import WebRTC
thread: call.individualCall.thread, thread: call.individualCall.thread,
sentAtTimestamp: call.individualCall.sentAtTimestamp sentAtTimestamp: call.individualCall.sentAtTimestamp
) )
databaseStorage.asyncWrite { transaction in Storage.write { transaction in
callRecord.anyInsert(transaction: transaction) callRecord.save(with: transaction)
} }
call.individualCall.callRecord = callRecord call.individualCall.callRecord = callRecord
@ -177,15 +177,9 @@ import WebRTC
// MARK: - Signaling Functions // MARK: - Signaling Functions
private func allowsInboundCallsInThread(_ thread: TSContactThread) -> Bool { private func allowsInboundCallsInThread(_ thread: TSContactThread) -> Bool {
return databaseStorage.read { transaction in // TODO: We might want to add some conditions here, like whether people have messaged
// IFF one of the following things is true, we can handle inbound call offers // eachother, whether the contact is blocked, etc.
// * The thread is in our profile whitelist return true
// * The thread belongs to someone in our system contacts
// * The thread existed before messages requests
return self.profileManager.isThread(inProfileWhitelist: thread, transaction: transaction)
|| self.contactsManager.isSystemContact(address: thread.contactAddress)
|| GRDBThreadFinder.isPreMessageRequestsThread(thread, transaction: transaction.unwrapGrdbRead)
}
} }
private struct CallIdentityKeys { private struct CallIdentityKeys {
@ -194,17 +188,16 @@ import WebRTC
} }
private func getIdentityKeys(thread: TSContactThread) -> CallIdentityKeys? { private func getIdentityKeys(thread: TSContactThread) -> CallIdentityKeys? {
return databaseStorage.read { transaction -> CallIdentityKeys? in let identityManager = OWSIdentityManager.shared()
guard let localIdentityKey = self.identityManager.identityKeyPair(with: transaction)?.publicKey else { guard let localIdentityKey = identityManager.identityKeyPair()?.publicKey else {
owsFailDebug("missing localIdentityKey") owsFailDebug("missing localIdentityKey")
return nil return nil
}
guard let contactIdentityKey = self.identityManager.identityKey(for: thread.contactAddress, transaction: transaction) else {
owsFailDebug("missing contactIdentityKey")
return nil
}
return CallIdentityKeys(localIdentityKey: localIdentityKey, contactIdentityKey: contactIdentityKey)
} }
guard let contactIdentityKey = identityManager.recipientIdentity(forRecipientId: thread.contactSessionID())?.identityKey else {
owsFailDebug("Looks like we're not actually maintaining the identity key for contacts. How will we fix that given that CallIdentityKeys wants this?")
return nil
}
return CallIdentityKeys(localIdentityKey: localIdentityKey, contactIdentityKey: contactIdentityKey)
} }
/** /**
@ -239,6 +232,8 @@ import WebRTC
BenchEventStart(title: "Incoming Call Connection", eventId: "call-\(newCall.individualCall.localId)") BenchEventStart(title: "Incoming Call Connection", eventId: "call-\(newCall.individualCall.localId)")
/*
* We might not need the below code, since we don't have the concept of untrusted identities
if let untrustedIdentity = self.identityManager.untrustedIdentityForSending(to: thread.contactAddress) { if let untrustedIdentity = self.identityManager.untrustedIdentityForSending(to: thread.contactAddress) {
Logger.warn("missed a call due to untrusted identity: \(newCall)") Logger.warn("missed a call due to untrusted identity: \(newCall)")
@ -272,6 +267,7 @@ import WebRTC
return return
} }
*/
guard let identityKeys = getIdentityKeys(thread: thread) else { guard let identityKeys = getIdentityKeys(thread: thread) else {
owsFailDebug("missing identity keys, skipping call.") owsFailDebug("missing identity keys, skipping call.")
@ -283,8 +279,8 @@ import WebRTC
) )
assert(newCall.individualCall.callRecord == nil) assert(newCall.individualCall.callRecord == nil)
newCall.individualCall.callRecord = callRecord newCall.individualCall.callRecord = callRecord
databaseStorage.write { transaction in Storage.write { transaction in
callRecord.anyInsert(transaction: transaction) callRecord.save(with: transaction)
} }
newCall.individualCall.state = .localFailure newCall.individualCall.state = .localFailure
@ -294,7 +290,7 @@ import WebRTC
} }
guard allowsInboundCallsInThread(thread) else { guard allowsInboundCallsInThread(thread) else {
Logger.info("Ignoring call offer from \(thread.contactAddress) due to insufficient permissions.") Logger.info("Ignoring call offer from \(thread.contactSessionID()) due to insufficient permissions.")
// Send the need permission message to the caller, so they know why we rejected their call. // Send the need permission message to the caller, so they know why we rejected their call.
callManager( callManager(
@ -318,8 +314,8 @@ import WebRTC
) )
assert(newCall.individualCall.callRecord == nil) assert(newCall.individualCall.callRecord == nil)
newCall.individualCall.callRecord = callRecord newCall.individualCall.callRecord = callRecord
databaseStorage.asyncWrite { transaction in Storage.write { transaction in
callRecord.anyInsert(transaction: transaction) callRecord.save(with: transaction)
} }
newCall.individualCall.state = .localFailure newCall.individualCall.state = .localFailure
@ -469,13 +465,13 @@ import WebRTC
var isUnknownCaller = false var isUnknownCaller = false
if call.individualCall.direction == .incoming { if call.individualCall.direction == .incoming {
isUnknownCaller = !self.contactsManagerImpl.isSystemContactWithSignalAccount(call.individualCall.thread.contactAddress) isUnknownCaller = !Storage.shared.getAllContacts().contains { $0.sessionID == call.individualCall.thread.contactSessionID() }
if isUnknownCaller { if isUnknownCaller {
Logger.warn("Using relay server because remote user is an unknown caller") Logger.warn("Using relay server because remote user is an unknown caller")
} }
} }
let useTurnOnly = isUnknownCaller || Self.preferences.doCallsHideIPAddress() let useTurnOnly = isUnknownCaller
let useLowBandwidth = CallService.useLowBandwidthWithSneakyTransaction() let useLowBandwidth = CallService.useLowBandwidthWithSneakyTransaction()
Logger.info("Configuring call for \(useLowBandwidth ? "low" : "standard") bandwidth") Logger.info("Configuring call for \(useLowBandwidth ? "low" : "standard") bandwidth")
@ -668,7 +664,9 @@ import WebRTC
thread: call.individualCall.thread, thread: call.individualCall.thread,
sentAtTimestamp: call.individualCall.sentAtTimestamp sentAtTimestamp: call.individualCall.sentAtTimestamp
) )
databaseStorage.asyncWrite { callRecord.anyInsert(transaction: $0) } Storage.write { transaction in
callRecord.save(with: transaction)
}
call.individualCall.callRecord = callRecord call.individualCall.callRecord = callRecord
callUIAdapter.reportMissedCall(call) callUIAdapter.reportMissedCall(call)
} }
@ -808,10 +806,10 @@ import WebRTC
let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, offerMessage: try offerBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId)) let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, offerMessage: try offerBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId))
return messageSender.sendMessage(.promise, callMessage.asPreparer) return messageSender.sendMessage(.promise, callMessage.asPreparer)
}.done { }.done {
Logger.info("sent offer message to \(call.individualCall.thread.contactAddress) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")") Logger.info("sent offer message to \(call.individualCall.thread.contactSessionID()) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")")
try self.callManager.signalingMessageDidSend(callId: callId) try self.callManager.signalingMessageDidSend(callId: callId)
}.catch { error in }.catch { error in
Logger.error("failed to send offer message to \(call.individualCall.thread.contactAddress) with error: \(error)") Logger.error("failed to send offer message to \(call.individualCall.thread.contactSessionID()) with error: \(error)")
self.callManager.signalingMessageDidFail(callId: callId) self.callManager.signalingMessageDidFail(callId: callId)
} }
} }
@ -827,10 +825,10 @@ import WebRTC
let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, answerMessage: try answerBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId)) let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, answerMessage: try answerBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId))
return messageSender.sendMessage(.promise, callMessage.asPreparer) return messageSender.sendMessage(.promise, callMessage.asPreparer)
}.done { }.done {
Logger.debug("sent answer message to \(call.individualCall.thread.contactAddress) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")") Logger.debug("sent answer message to \(call.individualCall.thread.contactSessionID()) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")")
try self.callManager.signalingMessageDidSend(callId: callId) try self.callManager.signalingMessageDidSend(callId: callId)
}.catch { error in }.catch { error in
Logger.error("failed to send answer message to \(call.individualCall.thread.contactAddress) with error: \(error)") Logger.error("failed to send answer message to \(call.individualCall.thread.contactSessionID()) with error: \(error)")
self.callManager.signalingMessageDidFail(callId: callId) self.callManager.signalingMessageDidFail(callId: callId)
} }
} }
@ -859,10 +857,10 @@ import WebRTC
let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, iceUpdateMessages: iceUpdateProtos, destinationDeviceId: NSNumber(value: destinationDeviceId)) let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, iceUpdateMessages: iceUpdateProtos, destinationDeviceId: NSNumber(value: destinationDeviceId))
return messageSender.sendMessage(.promise, callMessage.asPreparer) return messageSender.sendMessage(.promise, callMessage.asPreparer)
}.done { }.done {
Logger.debug("sent ice update message to \(call.individualCall.thread.contactAddress) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")") Logger.debug("sent ice update message to \(call.individualCall.thread.contactSessionID()) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")")
try self.callManager.signalingMessageDidSend(callId: callId) try self.callManager.signalingMessageDidSend(callId: callId)
}.catch { error in }.catch { error in
Logger.error("failed to send ice update message to \(call.individualCall.thread.contactAddress) with error: \(error)") Logger.error("failed to send ice update message to \(call.individualCall.thread.contactSessionID()) with error: \(error)")
callManager.signalingMessageDidFail(callId: callId) callManager.signalingMessageDidFail(callId: callId)
} }
} }
@ -897,10 +895,10 @@ import WebRTC
} }
return messageSender.sendMessage(.promise, callMessage.asPreparer) return messageSender.sendMessage(.promise, callMessage.asPreparer)
}.done { }.done {
Logger.debug("sent hangup message to \(call.individualCall.thread.contactAddress) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")") Logger.debug("sent hangup message to \(call.individualCall.thread.contactSessionID()) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")")
try self.callManager.signalingMessageDidSend(callId: callId) try self.callManager.signalingMessageDidSend(callId: callId)
}.catch { error in }.catch { error in
Logger.error("failed to send hangup message to \(call.individualCall.thread.contactAddress) with error: \(error)") Logger.error("failed to send hangup message to \(call.individualCall.thread.contactSessionID()) with error: \(error)")
self.callManager.signalingMessageDidFail(callId: callId) self.callManager.signalingMessageDidFail(callId: callId)
} }
} }
@ -915,10 +913,10 @@ import WebRTC
let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, busyMessage: try busyBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId)) let callMessage = OWSOutgoingCallMessage(thread: call.individualCall.thread, busyMessage: try busyBuilder.build(), destinationDeviceId: NSNumber(value: destinationDeviceId))
return messageSender.sendMessage(.promise, callMessage.asPreparer) return messageSender.sendMessage(.promise, callMessage.asPreparer)
}.done { }.done {
Logger.debug("sent busy message to \(call.individualCall.thread.contactAddress) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")") Logger.debug("sent busy message to \(call.individualCall.thread.contactSessionID()) device: \((destinationDeviceId != nil) ? String(destinationDeviceId!) : "nil")")
try self.callManager.signalingMessageDidSend(callId: callId) try self.callManager.signalingMessageDidSend(callId: callId)
}.catch { error in }.catch { error in
Logger.error("failed to send busy message to \(call.individualCall.thread.contactAddress) with error: \(error)") Logger.error("failed to send busy message to \(call.individualCall.thread.contactSessionID()) with error: \(error)")
self.callManager.signalingMessageDidFail(callId: callId) self.callManager.signalingMessageDidFail(callId: callId)
} }
} }
@ -947,8 +945,8 @@ import WebRTC
switch callRecord.callType { switch callRecord.callType {
case .incomingMissed: case .incomingMissed:
databaseStorage.asyncWrite { transaction in Storage.write { transaction in
callRecord.anyUpsert(transaction: transaction) callRecord.save(with: transaction)
} }
callUIAdapter.reportMissedCall(call) callUIAdapter.reportMissedCall(call)
case .incomingIncomplete, .incoming: case .incomingIncomplete, .incoming:
@ -958,12 +956,12 @@ import WebRTC
callRecord.updateCallType(.outgoingMissed) callRecord.updateCallType(.outgoingMissed)
case .incomingMissedBecauseOfChangedIdentity, .incomingDeclined, .outgoingMissed, .outgoing, .incomingAnsweredElsewhere, .incomingDeclinedElsewhere, .incomingBusyElsewhere: case .incomingMissedBecauseOfChangedIdentity, .incomingDeclined, .outgoingMissed, .outgoing, .incomingAnsweredElsewhere, .incomingDeclinedElsewhere, .incomingBusyElsewhere:
owsFailDebug("unexpected RPRecentCallType: \(callRecord.callType)") owsFailDebug("unexpected RPRecentCallType: \(callRecord.callType)")
databaseStorage.asyncWrite { transaction in Storage.write { transaction in
callRecord.anyUpsert(transaction: transaction) callRecord.save(with: transaction)
} }
@unknown default: @unknown default:
databaseStorage.asyncWrite { transaction in Storage.write { transaction in
callRecord.anyUpsert(transaction: transaction) callRecord.save(with: transaction)
} }
owsFailDebug("unknown RPRecentCallType: \(callRecord.callType)") owsFailDebug("unknown RPRecentCallType: \(callRecord.callType)")
} }
@ -983,7 +981,9 @@ import WebRTC
sentAtTimestamp: call.individualCall.sentAtTimestamp sentAtTimestamp: call.individualCall.sentAtTimestamp
) )
call.individualCall.callRecord = callRecord call.individualCall.callRecord = callRecord
databaseStorage.asyncWrite { callRecord.anyInsert(transaction: $0) } Storage.write { transaction in
callRecord.save(with: transaction)
}
} }
call.individualCall.state = .answeredElsewhere call.individualCall.state = .answeredElsewhere
@ -1008,7 +1008,9 @@ import WebRTC
sentAtTimestamp: call.individualCall.sentAtTimestamp sentAtTimestamp: call.individualCall.sentAtTimestamp
) )
call.individualCall.callRecord = callRecord call.individualCall.callRecord = callRecord
databaseStorage.asyncWrite { callRecord.anyInsert(transaction: $0) } Storage.write { transaction in
callRecord.save(with: transaction)
}
} }
call.individualCall.state = .declinedElsewhere call.individualCall.state = .declinedElsewhere
@ -1033,7 +1035,9 @@ import WebRTC
sentAtTimestamp: call.individualCall.sentAtTimestamp sentAtTimestamp: call.individualCall.sentAtTimestamp
) )
call.individualCall.callRecord = callRecord call.individualCall.callRecord = callRecord
databaseStorage.asyncWrite { callRecord.anyInsert(transaction: $0) } Storage.write { transaction in
callRecord.save(with: transaction)
}
} }
call.individualCall.state = .busyElsewhere call.individualCall.state = .busyElsewhere

View File

@ -20,7 +20,7 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedOffer( public func receivedOffer(
_ offer: SNProtoCallMessageOffer, _ offer: SNProtoCallMessageOffer,
from caller: SignalServiceAddress, from caller: String,
sourceDevice: UInt32, sourceDevice: UInt32,
sentAtTimestamp: UInt64, sentAtTimestamp: UInt64,
serverReceivedTimestamp: UInt64, serverReceivedTimestamp: UInt64,
@ -31,13 +31,13 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
let callType: SNProtoCallMessageOfferType let callType: SNProtoCallMessageOfferType
if offer.hasType { if offer.hasType {
callType = offer.unwrappedType callType = SNProtoCallMessageOfferType(rawValue: offer.type.rawValue)!
} else { } else {
// The type is not defined so assume the default, audio. // The type is not defined so assume the default, audio.
callType = .offerAudioCall callType = .offerAudioCall
} }
let thread = TSContactThread.getOrCreateThread(contactAddress: caller) let thread = TSContactThread.getOrCreateThread(contactSessionID: caller)
self.callService.individualCallService.handleReceivedOffer( self.callService.individualCallService.handleReceivedOffer(
thread: thread, thread: thread,
callId: offer.id, callId: offer.id,
@ -52,10 +52,10 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
) )
} }
public func receivedAnswer(_ answer: SNProtoCallMessageAnswer, from caller: SignalServiceAddress, sourceDevice: UInt32, supportsMultiRing: Bool) { public func receivedAnswer(_ answer: SNProtoCallMessageAnswer, from caller: String, sourceDevice: UInt32, supportsMultiRing: Bool) {
AssertIsOnMainThread() AssertIsOnMainThread()
let thread = TSContactThread.getOrCreateThread(contactAddress: caller) let thread = TSContactThread.getOrCreateThread(contactSessionID: caller)
self.callService.individualCallService.handleReceivedAnswer( self.callService.individualCallService.handleReceivedAnswer(
thread: thread, thread: thread,
callId: answer.id, callId: answer.id,
@ -66,10 +66,10 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
) )
} }
public func receivedIceUpdate(_ iceUpdate: [SNProtoCallMessageIceUpdate], from caller: SignalServiceAddress, sourceDevice: UInt32) { public func receivedIceUpdate(_ iceUpdate: [SNProtoCallMessageIceUpdate], from caller: String, sourceDevice: UInt32) {
AssertIsOnMainThread() AssertIsOnMainThread()
let thread = TSContactThread.getOrCreateThread(contactAddress: caller) let thread = TSContactThread.getOrCreateThread(contactSessionID: caller)
self.callService.individualCallService.handleReceivedIceCandidates( self.callService.individualCallService.handleReceivedIceCandidates(
thread: thread, thread: thread,
callId: iceUpdate[0].id, callId: iceUpdate[0].id,
@ -78,7 +78,7 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
) )
} }
public func receivedHangup(_ hangup: SNProtoCallMessageHangup, from caller: SignalServiceAddress, sourceDevice: UInt32) { public func receivedHangup(_ hangup: SNProtoCallMessageHangup, from caller: String, sourceDevice: UInt32) {
AssertIsOnMainThread() AssertIsOnMainThread()
// deviceId is optional and defaults to 0. // deviceId is optional and defaults to 0.
@ -86,7 +86,7 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
let type: SNProtoCallMessageHangupType let type: SNProtoCallMessageHangupType
if hangup.hasType { if hangup.hasType {
type = hangup.unwrappedType type = SNProtoCallMessageHangupType(rawValue: hangup.type.rawValue)!
if hangup.hasDeviceID { if hangup.hasDeviceID {
deviceId = hangup.deviceID deviceId = hangup.deviceID
@ -96,7 +96,7 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
type = .hangupNormal type = .hangupNormal
} }
let thread = TSContactThread.getOrCreateThread(contactAddress: caller) let thread = TSContactThread.getOrCreateThread(contactSessionID: caller)
self.callService.individualCallService.handleReceivedHangup( self.callService.individualCallService.handleReceivedHangup(
thread: thread, thread: thread,
callId: hangup.id, callId: hangup.id,
@ -106,10 +106,10 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
) )
} }
public func receivedBusy(_ busy: SNProtoCallMessageBusy, from caller: SignalServiceAddress, sourceDevice: UInt32) { public func receivedBusy(_ busy: SNProtoCallMessageBusy, from caller: String, sourceDevice: UInt32) {
AssertIsOnMainThread() AssertIsOnMainThread()
let thread = TSContactThread.getOrCreateThread(contactAddress: caller) let thread = TSContactThread.getOrCreateThread(contactSessionID: caller)
self.callService.individualCallService.handleReceivedBusy( self.callService.individualCallService.handleReceivedBusy(
thread: thread, thread: thread,
callId: busy.id, callId: busy.id,
@ -119,7 +119,7 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedOpaque( public func receivedOpaque(
_ opaque: SNProtoCallMessageOpaque, _ opaque: SNProtoCallMessageOpaque,
from caller: SignalServiceAddress, from caller: String,
sourceDevice: UInt32, sourceDevice: UInt32,
serverReceivedTimestamp: UInt64, serverReceivedTimestamp: UInt64,
serverDeliveryTimestamp: UInt64 serverDeliveryTimestamp: UInt64
@ -131,19 +131,15 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
return owsFailDebug("Received opaque call message without data") return owsFailDebug("Received opaque call message without data")
} }
guard let senderUuid = caller.uuid else {
return owsFailDebug("Received opaque call message from sender without UUID")
}
var messageAgeSec: UInt64 = 0 var messageAgeSec: UInt64 = 0
if serverReceivedTimestamp > 0 && serverDeliveryTimestamp >= serverReceivedTimestamp { if serverReceivedTimestamp > 0 && serverDeliveryTimestamp >= serverReceivedTimestamp {
messageAgeSec = (serverDeliveryTimestamp - serverReceivedTimestamp) / 1000 messageAgeSec = (serverDeliveryTimestamp - serverReceivedTimestamp) / 1000
} }
self.callService.callManager.receivedCallMessage( self.callService.callManager.receivedCallMessage(
senderUuid: senderUuid, senderUuid: caller,
senderDeviceId: sourceDevice, senderDeviceId: sourceDevice,
localDeviceId: TSAccountManager.shared.storedDeviceId(), localDeviceId: 1,
message: message, message: message,
messageAgeSec: messageAgeSec messageAgeSec: messageAgeSec
) )
@ -154,11 +150,11 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
for groupThread: TSGroupThread, for groupThread: TSGroupThread,
serverReceivedTimestamp: UInt64) { serverReceivedTimestamp: UInt64) {
Logger.info("Received group call update for thread \(groupThread.uniqueId)") Logger.info("Received group call update for thread \(groupThread.uniqueId!)")
callService.groupCallMessageHandler.handleUpdateMessage(update, for: groupThread, serverReceivedTimestamp: serverReceivedTimestamp) callService.groupCallMessageHandler.handleUpdateMessage(update, for: groupThread, serverReceivedTimestamp: serverReceivedTimestamp)
} }
public func externallyHandleCallMessage(envelope: SNProtoEnvelope, plaintextData: Data, wasReceivedByUD: Bool, serverDeliveryTimestamp: UInt64, transaction: SDSAnyWriteTransaction) -> Bool { public func externallyHandleCallMessage(envelope: SNProtoEnvelope, plaintextData: Data, wasReceivedByUD: Bool, serverDeliveryTimestamp: UInt64, transaction: YapDatabaseReadWriteTransaction) -> Bool {
return false return false
} }
} }

View File

@ -59,6 +59,9 @@ import SignalUtilitiesKit
public var backupLazyRestore: BackupLazyRestore public var backupLazyRestore: BackupLazyRestore
private override init() { private override init() {
self.callMessageHandlerRef = WebRTCCallMessageHandler()
self.callServiceRef = CallService()
self.outboundIndividualCallInitiatorRef = OutboundIndividualCallInitiator()
self.accountManager = AccountManager() self.accountManager = AccountManager()
self.notificationPresenter = NotificationPresenter() self.notificationPresenter = NotificationPresenter()
self.pushRegistrationManager = PushRegistrationManager() self.pushRegistrationManager = PushRegistrationManager()