Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert DecryptionFailureTracker to swift + tests #7769

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions Riot/Modules/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,38 @@ import AnalyticsEvents
}
}

@objc
protocol E2EAnalytics {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just extracted that protocol to make testing of decryption failure tracker easier

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.
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions Riot/Modules/Analytics/DecryptionFailure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ import AnalyticsEvents
/// The id of the event that was unabled to decrypt.
let failedEventId: String
/// The time the failure has been reported.
let ts: TimeInterval = Date().timeIntervalSince1970
let ts: TimeInterval
/// Decryption failure reason.
let reason: DecryptionFailureReason
/// Additional context of failure
let context: String

init(failedEventId: String, reason: DecryptionFailureReason, context: String) {
init(failedEventId: String, reason: DecryptionFailureReason, context: String, ts: TimeInterval) {
self.failedEventId = failedEventId
self.reason = reason
self.context = context
self.ts = ts
}
}
55 changes: 0 additions & 55 deletions Riot/Modules/Analytics/DecryptionFailureTracker.h

This file was deleted.

174 changes: 0 additions & 174 deletions Riot/Modules/Analytics/DecryptionFailureTracker.m

This file was deleted.

Loading
Loading