mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Removed unused swipe gesture (+3 squashed commits)
Squashed commits: [d64bb3bb] Stop using the ServiceLocator directly in the ScreenTrackerViewModifier [37c46ab9] Rename Analytics to AnalyticsService [8852a371] #920 - Cleanup ServiceLocator usages
This commit is contained in:
committed by
Stefan Ceriu
parent
b4cd58b209
commit
e6711a0236
@@ -22,7 +22,7 @@ protocol AnalyticsClientProtocol {
|
||||
var isRunning: Bool { get }
|
||||
|
||||
/// Starts the analytics client reporting data.
|
||||
func start()
|
||||
func start(analyticsConfiguration: AnalyticsConfiguration)
|
||||
|
||||
/// Reset all stored properties and any event queues on the client. Note that
|
||||
/// the client will remain active, but in a fresh unidentified state.
|
||||
|
||||
+16
-12
@@ -30,12 +30,16 @@ import PostHog
|
||||
/// To add a new event create a PR to that repo with the new/updated schema. Once merged
|
||||
/// into `main`, update the AnalyticsEvents Swift package in `project.yml`.
|
||||
///
|
||||
class Analytics {
|
||||
class AnalyticsService {
|
||||
/// The analytics client to send events with.
|
||||
private let client: AnalyticsClientProtocol
|
||||
private let appSettings: AppSettings
|
||||
private let bugReportService: BugReportServiceProtocol
|
||||
|
||||
init(client: AnalyticsClientProtocol) {
|
||||
init(client: AnalyticsClientProtocol, appSettings: AppSettings, bugReportService: BugReportServiceProtocol) {
|
||||
self.client = client
|
||||
self.appSettings = appSettings
|
||||
self.bugReportService = bugReportService
|
||||
}
|
||||
|
||||
/// Whether or not the object is enabled and sending events to the server.
|
||||
@@ -44,27 +48,27 @@ class Analytics {
|
||||
/// Whether to show the user the analytics opt in prompt.
|
||||
var shouldShowAnalyticsPrompt: Bool {
|
||||
// Only show the prompt once, and when analytics are enabled in BuildSettings.
|
||||
ServiceLocator.shared.settings.analyticsConsentState == .unknown && ServiceLocator.shared.settings.analyticsConfiguration.isEnabled
|
||||
appSettings.analyticsConsentState == .unknown && appSettings.analyticsConfiguration.isEnabled
|
||||
}
|
||||
|
||||
var isEnabled: Bool {
|
||||
ServiceLocator.shared.settings.analyticsConsentState == .optedIn
|
||||
appSettings.analyticsConsentState == .optedIn
|
||||
}
|
||||
|
||||
/// Opts in to analytics tracking with the supplied user session.
|
||||
func optIn() {
|
||||
ServiceLocator.shared.settings.analyticsConsentState = .optedIn
|
||||
appSettings.analyticsConsentState = .optedIn
|
||||
startIfEnabled()
|
||||
}
|
||||
|
||||
/// Stops analytics tracking and calls `reset` to clear any IDs and event queues.
|
||||
func optOut() {
|
||||
ServiceLocator.shared.settings.analyticsConsentState = .optedOut
|
||||
appSettings.analyticsConsentState = .optedOut
|
||||
|
||||
// The order is important here. PostHog ignores the reset if stopped.
|
||||
reset()
|
||||
client.stop()
|
||||
ServiceLocator.shared.bugReportService.stop()
|
||||
bugReportService.stop()
|
||||
MXLog.info("Stopped.")
|
||||
}
|
||||
|
||||
@@ -72,8 +76,8 @@ class Analytics {
|
||||
func startIfEnabled() {
|
||||
guard isEnabled, !isRunning else { return }
|
||||
|
||||
client.start()
|
||||
ServiceLocator.shared.bugReportService.start()
|
||||
client.start(analyticsConfiguration: appSettings.analyticsConfiguration)
|
||||
bugReportService.start()
|
||||
|
||||
// Sanity check in case something went wrong.
|
||||
guard client.isRunning else { return }
|
||||
@@ -87,14 +91,14 @@ class Analytics {
|
||||
/// Note: **MUST** be called before stopping PostHog or the reset is ignored.
|
||||
func reset() {
|
||||
client.reset()
|
||||
ServiceLocator.shared.bugReportService.reset()
|
||||
bugReportService.reset()
|
||||
MXLog.info("Reset.")
|
||||
}
|
||||
|
||||
/// Reset the consent state for analytics
|
||||
func resetConsentState() {
|
||||
MXLog.warning("Resetting consent state for analytics.")
|
||||
ServiceLocator.shared.settings.analyticsConsentState = .unknown
|
||||
appSettings.analyticsConsentState = .unknown
|
||||
}
|
||||
|
||||
/// Flushes the event queue in the analytics client, uploading all pending events.
|
||||
@@ -116,7 +120,7 @@ class Analytics {
|
||||
|
||||
// MARK: - Public tracking methods
|
||||
|
||||
extension Analytics {
|
||||
extension AnalyticsService {
|
||||
/// Track the presentation of a screen
|
||||
/// - Parameter screen: The screen that was shown
|
||||
/// - Parameter duration: An optional value representing how long the screen was shown for in milliseconds.
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Copyright 2023 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 SwiftUI
|
||||
|
||||
private struct AnalyticsServiceKey: EnvironmentKey {
|
||||
static let defaultValue: AnalyticsService = ServiceLocator.shared.analytics
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
var analyticsService: AnalyticsService {
|
||||
get { self[AnalyticsServiceKey.self] }
|
||||
set { self[AnalyticsServiceKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,7 @@
|
||||
import PostHog
|
||||
|
||||
extension PHGPostHogConfiguration {
|
||||
static var standard: PHGPostHogConfiguration? {
|
||||
let analyticsConfiguration = ServiceLocator.shared.settings.analyticsConfiguration
|
||||
static func standard(analyticsConfiguration: AnalyticsConfiguration) -> PHGPostHogConfiguration? {
|
||||
guard analyticsConfiguration.isEnabled else { return nil }
|
||||
|
||||
let postHogConfiguration = PHGPostHogConfiguration(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
|
||||
|
||||
@@ -27,9 +27,9 @@ class PostHogAnalyticsClient: AnalyticsClientProtocol {
|
||||
|
||||
var isRunning: Bool { postHog?.enabled ?? false }
|
||||
|
||||
func start() {
|
||||
func start(analyticsConfiguration: AnalyticsConfiguration) {
|
||||
// Only start if analytics have been configured in BuildSettings
|
||||
guard let configuration = PHGPostHogConfiguration.standard else { return }
|
||||
guard let configuration = PHGPostHogConfiguration.standard(analyticsConfiguration: analyticsConfiguration) else { return }
|
||||
|
||||
if postHog == nil {
|
||||
postHog = PHGPostHog(configuration: configuration)
|
||||
|
||||
@@ -22,26 +22,27 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
|
||||
private let authenticationService: AuthenticationService
|
||||
private let userSessionStore: UserSessionStoreProtocol
|
||||
|
||||
private let homeserverSubject: CurrentValueSubject<LoginHomeserver, Never> = .init(LoginHomeserver(address: ServiceLocator.shared.settings.defaultHomeserverAddress,
|
||||
loginMode: .unknown))
|
||||
private let homeserverSubject: CurrentValueSubject<LoginHomeserver, Never>
|
||||
var homeserver: CurrentValuePublisher<LoginHomeserver, Never> { homeserverSubject.asCurrentValuePublisher() }
|
||||
|
||||
init(userSessionStore: UserSessionStoreProtocol) {
|
||||
init(userSessionStore: UserSessionStoreProtocol, appSettings: AppSettings) {
|
||||
self.userSessionStore = userSessionStore
|
||||
|
||||
// guard let settings = ServiceLocator.shared.settings else { fatalError("The settings must be set.") }
|
||||
homeserverSubject = .init(LoginHomeserver(address: appSettings.defaultHomeserverAddress,
|
||||
loginMode: .unknown))
|
||||
|
||||
// let oidcConfiguration = OidcConfiguration(clientName: InfoPlistReader.main.bundleDisplayName,
|
||||
// redirectUri: settings.oidcRedirectURL.absoluteString,
|
||||
// clientUri: settings.oidcClientURL.absoluteString,
|
||||
// tosUri: settings.oidcTermsURL.absoluteString,
|
||||
// policyUri: settings.oidcPolicyURL.absoluteString,
|
||||
// staticRegistrations: settings.oidcStaticRegistrations.mapKeys { $0.absoluteString })
|
||||
// clientUri: appSettings.oidcClientURL.absoluteString,
|
||||
// tosUri: appSettings.oidcTermsURL.absoluteString,
|
||||
// policyUri: appSettings.oidcPolicyURL.absoluteString,
|
||||
// staticRegistrations: appSettings.oidcStaticRegistrations.mapKeys { $0.absoluteString })
|
||||
|
||||
authenticationService = AuthenticationService(basePath: userSessionStore.baseDirectory.path,
|
||||
passphrase: nil,
|
||||
userAgent: UserAgentBuilder.makeASCIIUserAgent(),
|
||||
// oidcConfiguration: oidcConfiguration,
|
||||
customSlidingSyncProxy: ServiceLocator.shared.settings.slidingSyncProxyURL?.absoluteString)
|
||||
customSlidingSyncProxy: appSettings.slidingSyncProxyURL?.absoluteString)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
@@ -32,8 +32,8 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
|
||||
init(withBaseURL baseURL: URL,
|
||||
sentryURL: URL,
|
||||
applicationId: String = ServiceLocator.shared.settings.bugReportApplicationId,
|
||||
maxUploadSize: Int = ServiceLocator.shared.settings.bugReportMaxUploadSize,
|
||||
applicationId: String,
|
||||
maxUploadSize: Int,
|
||||
session: URLSession = .shared) {
|
||||
self.baseURL = baseURL
|
||||
self.sentryURL = sentryURL
|
||||
|
||||
@@ -22,6 +22,8 @@ import UIKit
|
||||
class ClientProxy: ClientProxyProtocol {
|
||||
private let client: ClientProtocol
|
||||
private let backgroundTaskService: BackgroundTaskServiceProtocol
|
||||
private let appSettings: AppSettings
|
||||
|
||||
private var sessionVerificationControllerProxy: SessionVerificationControllerProxy?
|
||||
private let mediaLoader: MediaLoaderProtocol
|
||||
private let clientQueue: DispatchQueue
|
||||
@@ -56,9 +58,11 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
|
||||
|
||||
init(client: ClientProtocol, backgroundTaskService: BackgroundTaskServiceProtocol) async {
|
||||
init(client: ClientProtocol, backgroundTaskService: BackgroundTaskServiceProtocol, appSettings: AppSettings) async {
|
||||
self.client = client
|
||||
self.backgroundTaskService = backgroundTaskService
|
||||
self.appSettings = appSettings
|
||||
|
||||
clientQueue = .init(label: "ClientProxyQueue", attributes: .concurrent)
|
||||
|
||||
mediaLoader = MediaLoader(client: client, clientQueue: clientQueue)
|
||||
@@ -382,7 +386,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
|
||||
private func startEncryptionSyncService() {
|
||||
guard ServiceLocator.shared.settings.isEncryptionSyncEnabled else {
|
||||
guard appSettings.isEncryptionSyncEnabled else {
|
||||
return
|
||||
}
|
||||
configureEncryptionSyncService()
|
||||
@@ -420,7 +424,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
|
||||
do {
|
||||
let roomListService = try ServiceLocator.shared.settings.isEncryptionSyncEnabled ? client.roomListService() : client.roomListServiceWithEncryption()
|
||||
let roomListService = try appSettings.isEncryptionSyncEnabled ? client.roomListService() : client.roomListServiceWithEncryption()
|
||||
roomListStateUpdateTaskHandle = roomListService.state(listener: RoomListStateListenerProxy { [weak self] state in
|
||||
guard let self else { return }
|
||||
MXLog.info("Received room list update: \(state)")
|
||||
|
||||
@@ -21,11 +21,14 @@ import UserNotifications
|
||||
|
||||
class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
private let notificationCenter: UserNotificationCenterProtocol
|
||||
private let appSettings: AppSettings
|
||||
|
||||
private var userSession: UserSessionProtocol?
|
||||
|
||||
init(notificationCenter: UserNotificationCenterProtocol = UNUserNotificationCenter.current()) {
|
||||
init(notificationCenter: UserNotificationCenterProtocol,
|
||||
appSettings: AppSettings) {
|
||||
self.notificationCenter = notificationCenter
|
||||
super.init()
|
||||
self.appSettings = appSettings
|
||||
}
|
||||
|
||||
// MARK: NotificationManagerProtocol
|
||||
@@ -103,8 +106,8 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
pusherNotificationClientIdentifier: clientProxy.restorationToken?.pusherNotificationClientIdentifier)
|
||||
|
||||
let configuration = try await PusherConfiguration(identifiers: .init(pushkey: deviceToken.base64EncodedString(),
|
||||
appId: ServiceLocator.shared.settings.pusherAppId),
|
||||
kind: .http(data: .init(url: ServiceLocator.shared.settings.pushGatewayBaseURL.absoluteString,
|
||||
appId: appSettings.pusherAppId),
|
||||
kind: .http(data: .init(url: appSettings.pushGatewayBaseURL.absoluteString,
|
||||
format: .eventIdOnly,
|
||||
defaultPayload: defaultPayload.toJsonString())),
|
||||
appDisplayName: "\(InfoPlistReader.main.bundleDisplayName) (iOS)",
|
||||
@@ -121,7 +124,7 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
}
|
||||
|
||||
private func pusherProfileTag() -> String {
|
||||
if let currentTag = ServiceLocator.shared.settings.pusherProfileTag {
|
||||
if let currentTag = appSettings.pusherProfileTag {
|
||||
return currentTag
|
||||
}
|
||||
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
@@ -130,7 +133,7 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
return String(chars[chars.index(chars.startIndex, offsetBy: offset)])
|
||||
}.joined()
|
||||
|
||||
ServiceLocator.shared.settings.pusherProfileTag = newTag
|
||||
appSettings.pusherProfileTag = newTag
|
||||
return newTag
|
||||
}
|
||||
}
|
||||
@@ -140,7 +143,7 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
extension NotificationManager: UNUserNotificationCenterDelegate {
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter,
|
||||
willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
|
||||
guard ServiceLocator.shared.settings.enableInAppNotifications else {
|
||||
guard appSettings.enableInAppNotifications else {
|
||||
return []
|
||||
}
|
||||
guard let delegate else {
|
||||
|
||||
@@ -42,6 +42,7 @@ protocol RoomMemberProxyProtocol: AnyObject {
|
||||
|
||||
extension RoomMemberProxyProtocol {
|
||||
var permalink: URL? {
|
||||
try? PermalinkBuilder.permalinkTo(userIdentifier: userID)
|
||||
try? PermalinkBuilder.permalinkTo(userIdentifier: userID,
|
||||
baseURL: ServiceLocator.shared.settings.permalinkBaseURL)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,7 +528,6 @@ class RoomProxy: RoomProxyProtocol {
|
||||
await Task.dispatch(on: .global()) {
|
||||
do {
|
||||
try self.room.acceptInvitation()
|
||||
ServiceLocator.shared.analytics.trackJoinedRoom(isDM: self.room.isDirect(), isSpace: self.room.isSpace(), activeMemberCount: UInt(self.room.activeMembersCount()))
|
||||
return .success(())
|
||||
} catch {
|
||||
return .failure(.failedAcceptingInvite)
|
||||
|
||||
@@ -147,9 +147,11 @@ protocol RoomProxyProtocol {
|
||||
|
||||
extension RoomProxyProtocol {
|
||||
var permalink: URL? {
|
||||
if let canonicalAlias, let link = try? PermalinkBuilder.permalinkTo(roomAlias: canonicalAlias) {
|
||||
if let canonicalAlias, let link = try? PermalinkBuilder.permalinkTo(roomAlias: canonicalAlias,
|
||||
baseURL: ServiceLocator.shared.settings.permalinkBaseURL) {
|
||||
return link
|
||||
} else if let link = try? PermalinkBuilder.permalinkTo(roomIdentifier: id) {
|
||||
} else if let link = try? PermalinkBuilder.permalinkTo(roomIdentifier: id,
|
||||
baseURL: ServiceLocator.shared.settings.permalinkBaseURL) {
|
||||
return link
|
||||
} else {
|
||||
MXLog.error("Failed to build permalink for Room: \(id)")
|
||||
|
||||
@@ -80,7 +80,7 @@ enum RoomTimelineItemFixtures {
|
||||
isEditable: false,
|
||||
sender: .init(id: "", displayName: "Helena"),
|
||||
content: .init(body: "",
|
||||
formattedBody: AttributedStringBuilder().fromHTML("Hol' up <blockquote>New home office set up!</blockquote>That's amazing! Congrats 🥳")))
|
||||
formattedBody: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL).fromHTML("Hol' up <blockquote>New home office set up!</blockquote>That's amazing! Congrats 🥳")))
|
||||
]
|
||||
|
||||
/// A small chunk of events, containing 2 text items.
|
||||
|
||||
@@ -24,6 +24,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
private let timelineProvider: RoomTimelineProviderProtocol
|
||||
private let timelineItemFactory: RoomTimelineItemFactoryProtocol
|
||||
private let mediaProvider: MediaProviderProtocol
|
||||
private let appSettings: AppSettings
|
||||
private let serialDispatchQueue: DispatchQueue
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
@@ -44,12 +45,14 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
init(userId: String,
|
||||
roomProxy: RoomProxyProtocol,
|
||||
timelineItemFactory: RoomTimelineItemFactoryProtocol,
|
||||
mediaProvider: MediaProviderProtocol) {
|
||||
mediaProvider: MediaProviderProtocol,
|
||||
appSettings: AppSettings) {
|
||||
self.userId = userId
|
||||
self.roomProxy = roomProxy
|
||||
timelineProvider = roomProxy.timelineProvider
|
||||
self.timelineItemFactory = timelineItemFactory
|
||||
self.mediaProvider = mediaProvider
|
||||
self.appSettings = appSettings
|
||||
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomtimelineprovider", qos: .utility)
|
||||
|
||||
timelineProvider
|
||||
@@ -304,7 +307,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
|
||||
private func isItemCollapsible(_ item: TimelineItemProxy) -> Bool {
|
||||
if !ServiceLocator.shared.settings.shouldCollapseRoomStateEvents {
|
||||
if !appSettings.shouldCollapseRoomStateEvents {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ struct RoomTimelineControllerFactory: RoomTimelineControllerFactoryProtocol {
|
||||
RoomTimelineController(userId: userId,
|
||||
roomProxy: roomProxy,
|
||||
timelineItemFactory: timelineItemFactory,
|
||||
mediaProvider: mediaProvider)
|
||||
mediaProvider: mediaProvider,
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,9 @@ class UserSessionStore: UserSessionStoreProtocol {
|
||||
return .failure(.failedSettingUpSession)
|
||||
}
|
||||
|
||||
let clientProxy = await ClientProxy(client: client, backgroundTaskService: backgroundTaskService)
|
||||
let clientProxy = await ClientProxy(client: client,
|
||||
backgroundTaskService: backgroundTaskService,
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
|
||||
return .success(clientProxy)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user