Skip to content

Commit

Permalink
Merge pull request #7769 from element-hq/valere/swiftify_decryption_t…
Browse files Browse the repository at this point in the history
…racker
  • Loading branch information
Velin92 authored Apr 2, 2024
2 parents 0b8fb85 + 56e6653 commit 421e861
Show file tree
Hide file tree
Showing 10 changed files with 694 additions and 255 deletions.
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 {
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

0 comments on commit 421e861

Please sign in to comment.