MSC4075 Use expirationTS to define the call ringing window (#4652)

* Listen to call decline to stop ringing when declined from other device

* MSC4075 Use expirationTS to define the call ringing window

* Implement ElementCallService tests.

* Update acknowledgements.
This commit is contained in:
Valere Fedronic
2025-11-12 13:59:09 +01:00
committed by GitHub
parent 91dabf96eb
commit cd411b57e0
15 changed files with 485 additions and 19 deletions
@@ -0,0 +1,17 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
extension CXProviderMock {
struct Configuration { }
convenience init(_ configuration: Configuration) {
self.init()
reportNewIncomingCallWithUpdateCompletionClosure = { _, _, completion in
completion(nil)
}
}
}
@@ -9,6 +9,7 @@
import AnalyticsEvents
import AVFoundation
import CallKit
import Foundation
import LocalAuthentication
import Photos
@@ -2066,6 +2067,132 @@ class BugReportServiceMock: BugReportServiceProtocol, @unchecked Sendable {
}
}
}
class CXProviderMock: CXProviderProtocol, @unchecked Sendable {
//MARK: - setDelegate
var setDelegateQueueUnderlyingCallsCount = 0
var setDelegateQueueCallsCount: Int {
get {
if Thread.isMainThread {
return setDelegateQueueUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = setDelegateQueueUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
setDelegateQueueUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
setDelegateQueueUnderlyingCallsCount = newValue
}
}
}
}
var setDelegateQueueCalled: Bool {
return setDelegateQueueCallsCount > 0
}
var setDelegateQueueReceivedArguments: (delegate: CXProviderDelegate?, queue: DispatchQueue?)?
var setDelegateQueueReceivedInvocations: [(delegate: CXProviderDelegate?, queue: DispatchQueue?)] = []
var setDelegateQueueClosure: ((CXProviderDelegate?, DispatchQueue?) -> Void)?
func setDelegate(_ delegate: CXProviderDelegate?, queue: DispatchQueue?) {
setDelegateQueueCallsCount += 1
setDelegateQueueReceivedArguments = (delegate: delegate, queue: queue)
DispatchQueue.main.async {
self.setDelegateQueueReceivedInvocations.append((delegate: delegate, queue: queue))
}
setDelegateQueueClosure?(delegate, queue)
}
//MARK: - reportNewIncomingCall
var reportNewIncomingCallWithUpdateCompletionUnderlyingCallsCount = 0
var reportNewIncomingCallWithUpdateCompletionCallsCount: Int {
get {
if Thread.isMainThread {
return reportNewIncomingCallWithUpdateCompletionUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = reportNewIncomingCallWithUpdateCompletionUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
reportNewIncomingCallWithUpdateCompletionUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
reportNewIncomingCallWithUpdateCompletionUnderlyingCallsCount = newValue
}
}
}
}
var reportNewIncomingCallWithUpdateCompletionCalled: Bool {
return reportNewIncomingCallWithUpdateCompletionCallsCount > 0
}
var reportNewIncomingCallWithUpdateCompletionReceivedArguments: (uuid: UUID, update: CXCallUpdate, completion: (Error?) -> Void)?
var reportNewIncomingCallWithUpdateCompletionReceivedInvocations: [(uuid: UUID, update: CXCallUpdate, completion: (Error?) -> Void)] = []
var reportNewIncomingCallWithUpdateCompletionClosure: ((UUID, CXCallUpdate, @escaping (Error?) -> Void) -> Void)?
func reportNewIncomingCall(with uuid: UUID, update: CXCallUpdate, completion: @escaping (Error?) -> Void) {
reportNewIncomingCallWithUpdateCompletionCallsCount += 1
reportNewIncomingCallWithUpdateCompletionReceivedArguments = (uuid: uuid, update: update, completion: completion)
DispatchQueue.main.async {
self.reportNewIncomingCallWithUpdateCompletionReceivedInvocations.append((uuid: uuid, update: update, completion: completion))
}
reportNewIncomingCallWithUpdateCompletionClosure?(uuid, update, completion)
}
//MARK: - reportCall
var reportCallWithEndedAtReasonUnderlyingCallsCount = 0
var reportCallWithEndedAtReasonCallsCount: Int {
get {
if Thread.isMainThread {
return reportCallWithEndedAtReasonUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = reportCallWithEndedAtReasonUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
reportCallWithEndedAtReasonUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
reportCallWithEndedAtReasonUnderlyingCallsCount = newValue
}
}
}
}
var reportCallWithEndedAtReasonCalled: Bool {
return reportCallWithEndedAtReasonCallsCount > 0
}
var reportCallWithEndedAtReasonReceivedArguments: (uuid: UUID, endedAt: Date?, reason: CXCallEndedReason)?
var reportCallWithEndedAtReasonReceivedInvocations: [(uuid: UUID, endedAt: Date?, reason: CXCallEndedReason)] = []
var reportCallWithEndedAtReasonClosure: ((UUID, Date?, CXCallEndedReason) -> Void)?
func reportCall(with uuid: UUID, endedAt: Date?, reason: CXCallEndedReason) {
reportCallWithEndedAtReasonCallsCount += 1
reportCallWithEndedAtReasonReceivedArguments = (uuid: uuid, endedAt: endedAt, reason: reason)
DispatchQueue.main.async {
self.reportCallWithEndedAtReasonReceivedInvocations.append((uuid: uuid, endedAt: endedAt, reason: reason))
}
reportCallWithEndedAtReasonClosure?(uuid, endedAt, reason)
}
}
class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
var actionsPublisher: AnyPublisher<ClientProxyAction, Never> {
get { return underlyingActionsPublisher }