PR Suggestions

This commit is contained in:
Mauro Romito
2026-03-31 12:09:50 +02:00
committed by Mauro
parent f31c256037
commit a1029132c5
5 changed files with 40 additions and 43 deletions
@@ -48,7 +48,7 @@ final class AppSettings {
case analyticsConsentState
case hasRunNotificationPermissionsOnboarding
case hasRunIdentityConfirmationOnboarding
case hasRequestedAlwaysLocationAuthorization
case hasRequestedLocationAlwaysLocationAuthorization
case frequentlyUsedSystemEmojis
@@ -344,8 +344,8 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.hasRunIdentityConfirmationOnboarding, defaultValue: false, storageType: .userDefaults(store))
var hasRunIdentityConfirmationOnboarding
@UserPreference(key: UserDefaultsKeys.hasRequestedAlwaysLocationAuthorization, defaultValue: false, storageType: .userDefaults(store))
var hasRequestedAlwaysLocationAuthorization
@UserPreference(key: UserDefaultsKeys.hasRequestedLocationAlwaysLocationAuthorization, defaultValue: false, storageType: .userDefaults(store))
var hasRequestedLocationAlwaysLocationAuthorization
@UserPreference(key: UserDefaultsKeys.frequentlyUsedSystemEmojis, defaultValue: [FrequentlyUsedEmoji](), storageType: .userDefaults(store))
var frequentlyUsedSystemEmojis
@@ -8,7 +8,7 @@
import Combine
import Foundation
import UIKit
import SwiftUI
typealias LocationSharingScreenViewModelType = StateStoreViewModelV2<LocationSharingScreenViewState, LocationSharingScreenViewAction>
@@ -114,8 +114,8 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati
private func startLiveLocationSharing() {
authorizationStatusSubscription = nil
let authStatus = liveLocationManager.authorizationStatus.value
switch authStatus {
let authorizationStatus = liveLocationManager.authorizationStatus.value
switch authorizationStatus {
case .authorizedAlways:
// TODO: Start sending live location updates to the room
break
@@ -123,7 +123,7 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati
// This is to solve a race condition with map libre which always tries first
// to request the when in use permission, we wait for it and then try again
authorizationStatusSubscription = liveLocationManager.authorizationStatus
.filter { $0 != authStatus } // skip current status
.filter { $0 != authorizationStatus } // skip current status
.first() // this publisher only fires when there is an actual change, and if the user is done with permissions
.sink { [weak self] newValue in
guard newValue == .authorizedWhenInUse else { return }
@@ -137,7 +137,7 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati
}
authorizationStatusSubscription = liveLocationManager.authorizationStatus
.filter { $0 != authStatus } // skip current status
.filter { $0 != authorizationStatus } // skip current status
.first() // this publisher only fires when there is an actual change, and if the user is done with permissions
.sink { newValue in
guard newValue == .authorizedAlways else { return }
@@ -149,10 +149,9 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati
}
private func showMissingAlwaysAuthorizedAlert() {
let action: () -> Void = { [weak self] in self?.actionsSubject.send(.openSystemSettings) }
state.bindings.alertInfo = .init(locationSharingViewError: .missingAlwaysAuthorization,
primaryButton: .init(title: L10n.actionNotNow, role: .cancel, action: nil),
secondaryButton: .init(title: L10n.commonSettings, action: action))
secondaryButton: .init(title: L10n.commonSettings) { [weak self] in self?.actionsSubject.send(.openSystemSettings) })
}
private func sendLocation(_ geoURI: GeoURI, isUserLocation: Bool) async {
@@ -39,8 +39,8 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
@discardableResult
func requestAlwaysAuthorizationIfPossible() -> Bool {
guard !appSettings.hasRequestedAlwaysLocationAuthorization else { return false }
appSettings.hasRequestedAlwaysLocationAuthorization = true
guard !appSettings.hasRequestedLocationAlwaysLocationAuthorization else { return false }
appSettings.hasRequestedLocationAlwaysLocationAuthorization = true
locationManager.requestAlwaysAuthorization()
return true
}
@@ -51,14 +51,8 @@ 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 {
appSettings.hasRequestedAlwaysLocationAuthorization = false
appSettings.hasRequestedLocationAlwaysLocationAuthorization = false
}
authorizationStatusSubject.send(manager.authorizationStatus)
}
// MARK: - Private
// TODO: Add CLLocationManager location update handling to forward updates to rooms
// TODO: Track which rooms are currently sharing live location
// TODO: Send location updates to all active rooms via clientProxy
}
@@ -11,7 +11,7 @@ import Foundation
// sourcery: AutoMockable
protocol LiveLocationManagerProtocol: AnyObject {
/// Publishes the current "Always" location authorization status.
/// Publishes the current location authorization status.
var authorizationStatus: CurrentValuePublisher<CLAuthorizationStatus, Never> { get }
/// Requests "Always" location authorization from the user if the system allows it.