mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Remove the dynamic member lookup from UserSettings in favour of nested access. (#6294)
* Remove the dynamic member lookup from UserSettings in favour of nested access. * Remove forwarding methods from UserSettings. * Update the Enterprise submodule.
This commit is contained in:
@@ -67,12 +67,12 @@ nonisolated struct NotificationToneManager: NotificationToneManagerProtocol {
|
||||
try? FileManager.default.removeItem(at: Self.selectedToneLocation)
|
||||
let toneLocation = Self.toneLocation(for: alertTone)
|
||||
try FileManager.default.copyItem(at: toneLocation, to: Self.selectedToneLocation)
|
||||
userSettings.selectedNotificationTone = alertTone
|
||||
userSettings.app.selectedNotificationTone = alertTone
|
||||
return Self.selectedToneLocation
|
||||
} catch {
|
||||
if (try? Self.selectedToneLocation.checkResourceIsReachable()) != true {
|
||||
// make sure the selected tone is reset if there's no custom tone present
|
||||
userSettings.selectedNotificationTone = nil
|
||||
userSettings.app.selectedNotificationTone = nil
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
|
||||
switch await userSession(for: client) {
|
||||
case .success(let userSession):
|
||||
// Since the QR code login flow includes verification.
|
||||
userSession.userSettings.hasRunIdentityConfirmationOnboarding = true
|
||||
userSession.userSettings.account.hasRunIdentityConfirmationOnboarding = true
|
||||
progressSubject.send(.signedIn(userSession))
|
||||
case .failure(let error):
|
||||
progressSubject.send(completion: .failure(error))
|
||||
@@ -366,7 +366,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
|
||||
MXLog.info("Classic app account secrets imported.")
|
||||
|
||||
// Importing the secrets automatically verifies the session.
|
||||
appSettings.userSettings(for: classicAppAccount.userID).hasRunIdentityConfirmationOnboarding = true
|
||||
appSettings.userSettings(for: classicAppAccount.userID).account.hasRunIdentityConfirmationOnboarding = true
|
||||
} catch {
|
||||
MXLog.error("Failed to import secrets for Classic app account: \(error)")
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
// Route media downloads through a content scanner when one has been configured for the server,
|
||||
// and expose a proxy for the active scanning of content in the timeline.
|
||||
if let contentScannerURL = userSettings.contentScannerURL.publisher.value, let client = client as? Client {
|
||||
if let contentScannerURL = userSettings.app.contentScannerURL.publisher.value, let client = client as? Client {
|
||||
let scanner = ContentScanner(scannerUrl: contentScannerURL.absoluteString)
|
||||
await client.setContentScanner(contentScanner: scanner)
|
||||
contentScanner = ContentScannerProxy(contentScanner: scanner, client: client)
|
||||
@@ -516,7 +516,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
do {
|
||||
let parameters = CreateRoomParameters(name: nil,
|
||||
topic: nil,
|
||||
isEncrypted: !userSettings.forceDisableE2EE.publisher.value,
|
||||
isEncrypted: !userSettings.app.forceDisableE2EE.publisher.value,
|
||||
isDirect: true,
|
||||
visibility: .private,
|
||||
preset: .trustedPrivateChat,
|
||||
@@ -559,7 +559,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
let parameters = CreateRoomParameters(name: name,
|
||||
topic: topic,
|
||||
isEncrypted: !userSettings.forceDisableE2EE.publisher.value && accessType.isEncrypted,
|
||||
isEncrypted: !userSettings.app.forceDisableE2EE.publisher.value && accessType.isEncrypted,
|
||||
isDirect: false,
|
||||
visibility: accessType.visibility,
|
||||
preset: accessType.preset,
|
||||
@@ -1179,7 +1179,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
private func reconcileServiceState() async {
|
||||
switch desiredServiceState {
|
||||
case .running(let offline):
|
||||
if userSettings.clientPausingAndResumingEnabled {
|
||||
if userSettings.app.clientPausingAndResumingEnabled {
|
||||
do {
|
||||
MXLog.info("Resuming client")
|
||||
try await client.resume()
|
||||
@@ -1215,7 +1215,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
await syncService.stop()
|
||||
MXLog.info("Sync stopped")
|
||||
|
||||
if userSettings.clientPausingAndResumingEnabled {
|
||||
if userSettings.app.clientPausingAndResumingEnabled {
|
||||
do {
|
||||
MXLog.info("Pausing client")
|
||||
try await client.pause()
|
||||
|
||||
@@ -61,7 +61,7 @@ class EmojiProvider: EmojiProviderProtocol {
|
||||
return []
|
||||
}
|
||||
|
||||
return userSettings.frequentlyUsedSystemEmojis.map(\.key)
|
||||
return userSettings.app.frequentlyUsedSystemEmojis.map(\.key)
|
||||
}
|
||||
|
||||
func markEmojiAsFrequentlyUsed(_ emoji: String) {
|
||||
@@ -70,9 +70,9 @@ class EmojiProvider: EmojiProviderProtocol {
|
||||
}
|
||||
|
||||
let frequentlyUsed = if !frequentlyUsedSystemEmojis().contains(emoji) {
|
||||
userSettings.frequentlyUsedSystemEmojis + [.init(count: 0, key: emoji)]
|
||||
userSettings.app.frequentlyUsedSystemEmojis + [.init(count: 0, key: emoji)]
|
||||
} else {
|
||||
userSettings.frequentlyUsedSystemEmojis.map { frequentlyUsedEmoji in
|
||||
userSettings.app.frequentlyUsedSystemEmojis.map { frequentlyUsedEmoji in
|
||||
if frequentlyUsedEmoji.key == emoji {
|
||||
return FrequentlyUsedEmoji(count: frequentlyUsedEmoji.count + 1, key: emoji)
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class EmojiProvider: EmojiProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
userSettings.frequentlyUsedSystemEmojis = frequentlyUsed.sorted { $0.count > $1.count }
|
||||
userSettings.app.frequentlyUsedSystemEmojis = frequentlyUsed.sorted { $0.count > $1.count }
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -64,7 +64,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
// https://developer.apple.com/documentation/corelocation/cllocationmanager/pauseslocationupdatesautomatically
|
||||
self.locationManager.pausesLocationUpdatesAutomatically = false
|
||||
|
||||
setupMinimumDistanceUpdatesAndAccuracy(minimumDistance: userSettings.liveLocationMinimumDistanceUpdate)
|
||||
setupMinimumDistanceUpdatesAndAccuracy(minimumDistance: userSettings.app.liveLocationMinimumDistanceUpdate)
|
||||
setupSubscriptions()
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
|
||||
@discardableResult
|
||||
func requestAlwaysAuthorizationIfPossible() -> Bool {
|
||||
guard !userSettings.hasRequestedLocationAlwaysLocationAuthorization else { return false }
|
||||
userSettings.hasRequestedLocationAlwaysLocationAuthorization = true
|
||||
guard !userSettings.app.hasRequestedLocationAlwaysLocationAuthorization else { return false }
|
||||
userSettings.app.hasRequestedLocationAlwaysLocationAuthorization = true
|
||||
locationManager.requestAlwaysAuthorization()
|
||||
return true
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
func startLiveLocation(roomID: String, duration: Duration) async -> Result<Void, LiveLocationManagerError> {
|
||||
// Stop any existing session for this room first
|
||||
var didAlreadyStopLocalSession = false
|
||||
if userSettings.liveLocationSharingSessionsByRoomID[roomID] != nil
|
||||
if userSettings.app.liveLocationSharingSessionsByRoomID[roomID] != nil
|
||||
|| startingLiveLocationSharingSessionsByRoomID[roomID] != nil {
|
||||
await stopLiveLocation(roomID: roomID)
|
||||
didAlreadyStopLocalSession = true
|
||||
@@ -114,7 +114,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
var roomProxy: JoinedRoomProxyProtocol?
|
||||
let cachedRoomProxy = activeRoomProxies[roomID]
|
||||
startingLiveLocationSharingSessionsByRoomID.removeValue(forKey: roomID)
|
||||
userSettings.liveLocationSharingSessionsByRoomID.removeValue(forKey: roomID)
|
||||
userSettings.app.liveLocationSharingSessionsByRoomID.removeValue(forKey: roomID)
|
||||
|
||||
if let cachedRoomProxy {
|
||||
roomProxy = cachedRoomProxy
|
||||
@@ -137,7 +137,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
// If the system resets authorization to notDetermined (e.g. after app reinstall or
|
||||
// settings reset), clear the flag so we can request again.
|
||||
if manager.authorizationStatus == .notDetermined {
|
||||
userSettings.hasRequestedLocationAlwaysLocationAuthorization = false
|
||||
userSettings.app.hasRequestedLocationAlwaysLocationAuthorization = false
|
||||
}
|
||||
|
||||
// If authorization was revoked, stop all active sessions.
|
||||
@@ -146,7 +146,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
}
|
||||
|
||||
// Accuracy authorization may have changed, reapply new accuracy settings.
|
||||
setupMinimumDistanceUpdatesAndAccuracy(minimumDistance: userSettings.liveLocationMinimumDistanceUpdate)
|
||||
setupMinimumDistanceUpdatesAndAccuracy(minimumDistance: userSettings.app.liveLocationMinimumDistanceUpdate)
|
||||
|
||||
authorizationStatusSubject.send(manager.authorizationStatus)
|
||||
}
|
||||
@@ -183,7 +183,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSettings.liveLocationSharingSessionsByRoomIDPublisher
|
||||
userSettings.app.liveLocationSharingSessionsByRoomIDPublisher
|
||||
.removeDuplicates()
|
||||
.sink { [weak self] sessions in
|
||||
guard let self else { return }
|
||||
@@ -197,7 +197,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSettings.liveLocationMinimumDistanceUpdatePublisher
|
||||
userSettings.app.liveLocationMinimumDistanceUpdatePublisher
|
||||
.removeDuplicates()
|
||||
.debounce(for: .seconds(1), scheduler: DispatchQueue.main)
|
||||
.sink { [weak self] newValue in
|
||||
@@ -210,7 +210,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
// A new beaconInfo has been received in a room with existing active session.
|
||||
// This is either a new start or a new stop from a different device, so we
|
||||
// should remove the session from the current local one.
|
||||
userSettings.liveLocationSharingSessionsByRoomID.removeValue(forKey: update.roomID)
|
||||
userSettings.app.liveLocationSharingSessionsByRoomID.removeValue(forKey: update.roomID)
|
||||
|
||||
// Instead if we receive a new isLiveUpdate
|
||||
guard update.isLive else { return }
|
||||
@@ -224,7 +224,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
// This means the server has echoed the start of the session and we can safely promote it
|
||||
// to a started session and start sending live locations.
|
||||
startingLiveLocationSharingSessionsByRoomID.removeValue(forKey: update.roomID)
|
||||
userSettings.liveLocationSharingSessionsByRoomID[update.roomID] = session
|
||||
userSettings.app.liveLocationSharingSessionsByRoomID[update.roomID] = session
|
||||
|
||||
if isUpdatingLocation, let lastLocation {
|
||||
locationUpdateSubject.send(lastLocation)
|
||||
@@ -281,7 +281,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
/// discarding any intermediate updates while always keeping the last one.
|
||||
private func processLocationUpdateIfNeeded() {
|
||||
guard !isProcessingLocationUpdate, let location = latestPendingLocation else { return }
|
||||
guard !userSettings.liveLocationSharingSessionsByRoomID.isEmpty else { return }
|
||||
guard !userSettings.app.liveLocationSharingSessionsByRoomID.isEmpty else { return }
|
||||
|
||||
latestPendingLocation = nil
|
||||
isProcessingLocationUpdate = true
|
||||
@@ -306,7 +306,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
}
|
||||
|
||||
private func sendLocationToActiveRooms(_ coordinate: CLLocationCoordinate2D) async {
|
||||
let sessions = userSettings.liveLocationSharingSessionsByRoomID
|
||||
let sessions = userSettings.app.liveLocationSharingSessionsByRoomID
|
||||
let geoURI = GeoURI(coordinate: coordinate, uncertainty: nil)
|
||||
|
||||
for (roomID, session) in sessions {
|
||||
@@ -351,7 +351,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
||||
}
|
||||
|
||||
private func stopAllSessions() {
|
||||
let roomIDs = Array(Set(userSettings.liveLocationSharingSessionsByRoomID.keys)
|
||||
let roomIDs = Array(Set(userSettings.app.liveLocationSharingSessionsByRoomID.keys)
|
||||
.union(startingLiveLocationSharingSessionsByRoomID.keys))
|
||||
Task { [weak self] in
|
||||
guard let self else { return }
|
||||
|
||||
@@ -171,7 +171,7 @@ struct MediaUploadingPreprocessor {
|
||||
try stripLocationFromImage(at: url, type: type)
|
||||
|
||||
var mimeType = mimeType
|
||||
if userSettings.optimizeMediaUploads, !type.conforms(to: .gif) {
|
||||
if userSettings.app.optimizeMediaUploads, !type.conforms(to: .gif) {
|
||||
let outputType = type.conforms(to: .png) ? UTType.png : .jpeg
|
||||
mimeType = outputType.preferredMIMEType ?? "application/octet-stream"
|
||||
try resizeImage(at: url, maxPixelSize: Constants.optimizedMaxPixelSize, destination: url, type: outputType)
|
||||
@@ -439,7 +439,7 @@ struct MediaUploadingPreprocessor {
|
||||
/// - Returns: the URL for the resulting video and its media info as a `VideoProcessingResult`
|
||||
private func convertVideoToMP4(_ url: URL, targetFileSize: UInt) async throws(MediaUploadingPreprocessorError) -> VideoProcessingInfo {
|
||||
let asset = AVURLAsset(url: url)
|
||||
let presetName = userSettings.optimizeMediaUploads ? AVAssetExportPreset1280x720 : AVAssetExportPreset1920x1080
|
||||
let presetName = userSettings.app.optimizeMediaUploads ? AVAssetExportPreset1280x720 : AVAssetExportPreset1920x1080
|
||||
|
||||
guard let exportSession = AVAssetExportSession(asset: asset, presetName: presetName) else {
|
||||
throw .failedConvertingVideo
|
||||
|
||||
@@ -41,7 +41,7 @@ final class PresenceService {
|
||||
}
|
||||
|
||||
private var desiredPresence: ClientProxyPresence {
|
||||
switch (isForegroundActive, userSettings.sharePresence) {
|
||||
switch (isForegroundActive, userSettings.app.sharePresence) {
|
||||
case (true, true):
|
||||
.online
|
||||
case (true, false):
|
||||
@@ -68,7 +68,7 @@ final class PresenceService {
|
||||
}
|
||||
|
||||
private func observeSharePresence() {
|
||||
userSettings.sharePresencePublisher
|
||||
userSettings.app.sharePresencePublisher
|
||||
.removeDuplicates()
|
||||
.sink { [weak self] _ in
|
||||
self?.reportCurrentState()
|
||||
|
||||
@@ -83,7 +83,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
infoSubject = try await .init(RoomInfoProxy(roomInfo: room.roomInfo()))
|
||||
|
||||
let openRoomSpan = analyticsService.signpost.addSpan(.timelineLoad, toTransaction: .openRoom)
|
||||
timeline = try await TimelineProxy(timeline: room.timelineWithConfiguration(configuration: .init(focus: .live(hideThreadedEvents: userSettings.threadsEnabled),
|
||||
timeline = try await TimelineProxy(timeline: room.timelineWithConfiguration(configuration: .init(focus: .live(hideThreadedEvents: userSettings.app.threadsEnabled),
|
||||
filter: .eventFilter(filter: Self.excludedEventsFilter),
|
||||
internalIdPrefix: nil,
|
||||
dateDividerMode: .daily,
|
||||
@@ -150,7 +150,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
let openRoomSpan = analyticsService.signpost.addSpan(.timelineLoad, toTransaction: .notificationToMessage)
|
||||
let sdkTimeline = try await room.timelineWithConfiguration(configuration: .init(focus: .event(eventId: eventID,
|
||||
numContextEvents: numberOfEvents,
|
||||
threadMode: .automatic(hideThreadedEvents: userSettings.threadsEnabled)),
|
||||
threadMode: .automatic(hideThreadedEvents: userSettings.app.threadsEnabled)),
|
||||
filter: .all,
|
||||
internalIdPrefix: UUID().uuidString,
|
||||
dateDividerMode: .daily,
|
||||
|
||||
@@ -165,7 +165,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
rustFilters.append(.identifiers(identifiers: Array(roomIDs)))
|
||||
|
||||
if !filters.contains(.lowPriority), userSettings.lowPriorityFilterEnabled {
|
||||
if !filters.contains(.lowPriority), userSettings.app.lowPriorityFilterEnabled {
|
||||
rustFilters.append(.nonLowPriority)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
case let .all(filters):
|
||||
var rustFilters = filters.map(\.rustFilter) + baseFilter
|
||||
|
||||
if !filters.contains(.lowPriority), userSettings.lowPriorityFilterEnabled {
|
||||
if !filters.contains(.lowPriority), userSettings.app.lowPriorityFilterEnabled {
|
||||
rustFilters.append(.nonLowPriority)
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func nameFilter(for query: String) -> [RoomListEntriesDynamicFilterKind] {
|
||||
userSettings.fuzzyRoomListSearchEnabled ? [.fuzzyMatchRoomName(pattern: query)] : [.normalizedMatchRoomName(pattern: query)]
|
||||
userSettings.app.fuzzyRoomListSearchEnabled ? [.fuzzyMatchRoomName(pattern: query)] : [.normalizedMatchRoomName(pattern: query)]
|
||||
}
|
||||
|
||||
private func setupVisibleRangeObservers() {
|
||||
|
||||
@@ -128,7 +128,7 @@ class TimelineController: TimelineControllerProtocol {
|
||||
}
|
||||
|
||||
func sendReadReceipt(for itemID: TimelineItemIdentifier) async {
|
||||
let receiptType: MatrixRustSDK.ReceiptType = userSettings.sharePresence ? .read : .readPrivate
|
||||
let receiptType: MatrixRustSDK.ReceiptType = userSettings.app.sharePresence ? .read : .readPrivate
|
||||
|
||||
guard let eventID = itemID.eventID else {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user