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 all commits
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
42 changes: 20 additions & 22 deletions Riot/Modules/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ 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(_ failure: DecryptionFailure)
}


@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(_ failure: DecryptionFailure) {
let event = failure.toAnalyticsEvent()
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 +285,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
44 changes: 44 additions & 0 deletions Riot/Modules/Analytics/DecryptionFailure+Analytics.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import AnalyticsEvents

extension DecryptionFailure {

public func toAnalyticsEvent() -> AnalyticsEvent.Error {

let timeToDecryptMillis: Int = if self.timeToDecrypt != nil {
Int(self.timeToDecrypt! * 1000)
} else {
-1
}
return AnalyticsEvent.Error(
context: self.context,
cryptoModule: .Rust,
cryptoSDK: .Rust,
domain: .E2EE,

eventLocalAgeMillis: nil,
isFederated: nil,
isMatrixDotOrg: nil,
name: self.reason.errorName,
timeToDecryptMillis: timeToDecryptMillis,
userTrustsOwnIdentity: nil,
wasVisibleToUser: nil
)
}
}
8 changes: 6 additions & 2 deletions Riot/Modules/Analytics/DecryptionFailure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ 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) {
/// UTDs can be permanent or temporary. If temporary, this field will contain the time it took to decrypt the message in milliseconds. If permanent should be nil
var timeToDecrypt: TimeInterval?

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