convert DecryptionFailureTracker to swift + tests

This commit is contained in:
Valere
2024-03-29 11:03:28 +01:00
parent 3253271949
commit d045a32b74
9 changed files with 479 additions and 255 deletions
+33 -22
View File
@@ -213,6 +213,38 @@ import AnalyticsEvents
}
}
@objc
protocol E2EAnalytics {
func trackE2EEError(_ reason: DecryptionFailureReason, context: String)
}
@objc extension Analytics: E2EAnalytics {
/// Track an E2EE error that occurred
/// - Parameters:
/// - reason: The error that occurred.
/// - context: Additional context of the error that occured
func trackE2EEError(_ reason: DecryptionFailureReason, context: String) {
let event = AnalyticsEvent.Error(
context: context,
cryptoModule: .Rust,
cryptoSDK: AnalyticsEvent.Error.CryptoSDK.Rust,
domain: .E2EE,
// XXX not yet supported.
eventLocalAgeMillis: nil,
isFederated: nil,
isMatrixDotOrg: nil,
name: reason.errorName,
timeToDecryptMillis: nil,
userTrustsOwnIdentity: nil,
wasVisibleToUser: nil
)
capture(event: event)
}
}
// MARK: - Public tracking methods
// The following methods are exposed for compatibility with Objective-C as
// the `capture` method and the generated events cannot be bridged from Swift.
@@ -266,28 +298,7 @@ extension Analytics {
func trackInteraction(_ uiElement: AnalyticsUIElement) {
trackInteraction(uiElement, interactionType: .Touch, index: nil)
}
/// Track an E2EE error that occurred
/// - Parameters:
/// - reason: The error that occurred.
/// - context: Additional context of the error that occured
func trackE2EEError(_ reason: DecryptionFailureReason, context: String) {
let event = AnalyticsEvent.Error(
context: context,
cryptoModule: .Rust,
cryptoSDK: .Rust,
domain: .E2EE,
// XXX not yet supported.
eventLocalAgeMillis: nil,
isFederated: nil,
isMatrixDotOrg: nil,
name: reason.errorName,
timeToDecryptMillis: nil,
userTrustsOwnIdentity: nil,
wasVisibleToUser: nil
)
capture(event: event)
}
/// Track when a user becomes unauthenticated without pressing the `sign out` button.
/// - Parameters: