mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-06 07:57:42 +02:00
Merge pull request #6479 from vector-im/steve/6477_lls_power_level
Location sharing: Display clearer error message when the user doesn't have permission to share location in the room (PSG-619)
This commit is contained in:
@@ -2233,6 +2233,9 @@ Tap the + to start adding people.";
|
||||
|
||||
"location_sharing_invalid_authorization_settings" = "Settings";
|
||||
|
||||
"location_sharing_invalid_power_level_title" = "You don’t have permission to share live location";
|
||||
"location_sharing_invalid_power_level_message" = "You need to have the right permissions in order to share live location in this room.";
|
||||
|
||||
"location_sharing_open_apple_maps" = "Open in Apple Maps";
|
||||
|
||||
"location_sharing_open_google_maps" = "Open in Google Maps";
|
||||
|
||||
@@ -3007,6 +3007,14 @@ public class VectorL10n: NSObject {
|
||||
public static var locationSharingInvalidAuthorizationSettings: String {
|
||||
return VectorL10n.tr("Vector", "location_sharing_invalid_authorization_settings")
|
||||
}
|
||||
/// You need to have the right permissions in order to share live location in this room.
|
||||
public static var locationSharingInvalidPowerLevelMessage: String {
|
||||
return VectorL10n.tr("Vector", "location_sharing_invalid_power_level_message")
|
||||
}
|
||||
/// You don’t have permission to share live location
|
||||
public static var locationSharingInvalidPowerLevelTitle: String {
|
||||
return VectorL10n.tr("Vector", "location_sharing_invalid_power_level_title")
|
||||
}
|
||||
/// Live location error
|
||||
public static var locationSharingLiveError: String {
|
||||
return VectorL10n.tr("Vector", "location_sharing_live_error")
|
||||
|
||||
+34
-2
@@ -104,8 +104,8 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
self.shareStaticLocation(latitude: latitude, longitude: longitude, coordinateType: coordinateType)
|
||||
case .shareLiveLocation(let timeout):
|
||||
self.startLiveLocationSharing(with: timeout)
|
||||
case .showLabFlagPromotionIfNeeded(let completion):
|
||||
self.showLabFlagPromotionIfNeeded(completion: completion)
|
||||
case .checkLiveLocationCanBeStarted(let completion):
|
||||
self.checkLiveLocationCanBeStarted(completion: completion)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,38 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
}
|
||||
}
|
||||
|
||||
private func checkLiveLocationCanBeStarted(completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
|
||||
guard self.canShareLiveLocation() else {
|
||||
completion(.failure(LiveLocationStartError.powerLevelNotHighEnough))
|
||||
return
|
||||
}
|
||||
|
||||
self.showLabFlagPromotionIfNeeded { labFlagEnabled in
|
||||
|
||||
if labFlagEnabled {
|
||||
completion(.success(Void()))
|
||||
} else {
|
||||
completion(.failure(LiveLocationStartError.labFlagNotEnabled))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if user can send beacon info state event
|
||||
private func canShareLiveLocation() -> Bool {
|
||||
guard let myUserId = self.parameters.roomDataSource.mxSession.myUserId else {
|
||||
return false
|
||||
}
|
||||
|
||||
let userPowerLevelRawValue = self.parameters.roomDataSource.roomState.powerLevels.powerLevelOfUser(withUserID: myUserId)
|
||||
|
||||
guard let userPowerLevel = RoomPowerLevel(rawValue: userPowerLevelRawValue) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return userPowerLevel.rawValue >= RoomPowerLevel.moderator.rawValue
|
||||
}
|
||||
|
||||
private func showLabFlagPromotionIfNeeded(completion: @escaping ((Bool) -> Void)) {
|
||||
guard RiotSettings.shared.enableLiveLocationSharing == false else {
|
||||
// Live location sharing lab flag is already enabled, do not present lab flag promotion screen
|
||||
|
||||
@@ -47,7 +47,12 @@ enum LocationSharingViewModelResult {
|
||||
case cancel
|
||||
case share(latitude: Double, longitude: Double, coordinateType: LocationSharingCoordinateType)
|
||||
case shareLiveLocation(timeout: TimeInterval)
|
||||
case showLabFlagPromotionIfNeeded(_ completion: ((Bool) -> Void))
|
||||
case checkLiveLocationCanBeStarted(_ completion: ((Result<Void, Error>) -> Void))
|
||||
}
|
||||
|
||||
enum LiveLocationStartError: Error {
|
||||
case powerLevelNotHighEnough
|
||||
case labFlagNotEnabled
|
||||
}
|
||||
|
||||
enum LocationSharingViewError {
|
||||
@@ -105,4 +110,5 @@ enum LocationSharingAlertType {
|
||||
case authorizationError
|
||||
case locationSharingError
|
||||
case stopLocationSharingError
|
||||
case locationSharingPowerLevelError
|
||||
}
|
||||
|
||||
@@ -101,10 +101,23 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
|
||||
state.showLoadingIndicator = false
|
||||
|
||||
if let error = error {
|
||||
state.bindings.alertInfo = AlertInfo(id: error,
|
||||
title: VectorL10n.locationSharingPostFailureTitle,
|
||||
message: VectorL10n.locationSharingPostFailureSubtitle(AppInfo.current.displayName),
|
||||
primaryButton: (VectorL10n.ok, nil))
|
||||
|
||||
let alertInfo: AlertInfo<LocationSharingAlertType>
|
||||
|
||||
switch error {
|
||||
case .locationSharingPowerLevelError:
|
||||
alertInfo = AlertInfo(id: error,
|
||||
title: VectorL10n.locationSharingInvalidPowerLevelTitle,
|
||||
message: VectorL10n.locationSharingInvalidPowerLevelMessage,
|
||||
primaryButton: (VectorL10n.ok, nil))
|
||||
default:
|
||||
alertInfo = AlertInfo(id: error,
|
||||
title: VectorL10n.locationSharingPostFailureTitle,
|
||||
message: VectorL10n.locationSharingPostFailureSubtitle(AppInfo.current.displayName),
|
||||
primaryButton: (VectorL10n.ok, nil))
|
||||
}
|
||||
|
||||
state.bindings.alertInfo = alertInfo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,9 +187,15 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
|
||||
return
|
||||
}
|
||||
|
||||
completion(.showLabFlagPromotionIfNeeded({ liveLocationEnabled in
|
||||
if liveLocationEnabled {
|
||||
completion(.checkLiveLocationCanBeStarted({ result in
|
||||
|
||||
switch result {
|
||||
case .success:
|
||||
self.checkLocationAuthorizationAndPresentTimerSelector()
|
||||
case .failure(let error):
|
||||
if case LiveLocationStartError.powerLevelNotHighEnough = error {
|
||||
self.stopLoading(error: .locationSharingPowerLevelError)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class LocationSharingViewModelTests: XCTestCase {
|
||||
expectation.fulfill()
|
||||
case .shareLiveLocation:
|
||||
XCTFail()
|
||||
case .showLabFlagPromotionIfNeeded:
|
||||
case .checkLiveLocationCanBeStarted:
|
||||
XCTFail()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Location sharing: Display clearer error message when the user doesn't have permission to share location in the room.
|
||||
Reference in New Issue
Block a user