From 909452ccbaa6f2ac8e6c47ac562211c52b504882 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 26 Jul 2022 10:56:37 +0200 Subject: [PATCH 1/5] LocationSharingViewModel: Handle power level error display. --- .../LocationSharingModels.swift | 8 ++++- .../LocationSharingViewModel.swift | 31 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingModels.swift b/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingModels.swift index 46d694fcf..660dd79a7 100644 --- a/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingModels.swift +++ b/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingModels.swift @@ -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)) +} + +enum LiveLocationStartError: Error { + case powerLevelNotHighEnough + case labFlagNotEnabled } enum LocationSharingViewError { @@ -105,4 +110,5 @@ enum LocationSharingAlertType { case authorizationError case locationSharingError case stopLocationSharingError + case locationSharingPowerLevelError } diff --git a/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingViewModel.swift b/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingViewModel.swift index 1fc7242c3..a51f04e84 100644 --- a/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingViewModel.swift +++ b/RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingViewModel.swift @@ -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 + + 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) + } } })) } From 272bb7e36cee5a9cd91097321356373226d6e21c Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 26 Jul 2022 10:57:07 +0200 Subject: [PATCH 2/5] LocationSharingCoordinator: Handle room power level check for live location sharing. --- .../LocationSharingCoordinator.swift | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/RiotSwiftUI/Modules/Room/LocationSharing/Coordinator/LocationSharingCoordinator.swift b/RiotSwiftUI/Modules/Room/LocationSharing/Coordinator/LocationSharingCoordinator.swift index 434bf1324..e1946a180 100644 --- a/RiotSwiftUI/Modules/Room/LocationSharing/Coordinator/LocationSharingCoordinator.swift +++ b/RiotSwiftUI/Modules/Room/LocationSharing/Coordinator/LocationSharingCoordinator.swift @@ -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)) { + + 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 From cc4b8b84c447e5329084fb9a8be3ce5d66142dbd Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 26 Jul 2022 10:58:20 +0200 Subject: [PATCH 3/5] Update changes --- changelog.d/6477.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6477.change diff --git a/changelog.d/6477.change b/changelog.d/6477.change new file mode 100644 index 000000000..66c827421 --- /dev/null +++ b/changelog.d/6477.change @@ -0,0 +1 @@ +Location sharing: Display clearer error message when the user doesn't have permission to share location in the room. From eac2599b860fc19d10e577994c6c792003513ed6 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 26 Jul 2022 10:58:41 +0200 Subject: [PATCH 4/5] LLS: Add power level error strings. --- Riot/Assets/en.lproj/Vector.strings | 3 +++ Riot/Generated/Strings.swift | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index b10403ef4..f58e68824 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -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"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index d1de90bd7..a098114a0 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -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") From 02eac5f4eb03acb9c8b44aa3ebc8da89b377cb96 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 26 Jul 2022 11:40:21 +0200 Subject: [PATCH 5/5] Fix LocationSharingViewModelTests. --- .../Test/Unit/LocationSharingViewModelTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RiotSwiftUI/Modules/Room/LocationSharing/Test/Unit/LocationSharingViewModelTests.swift b/RiotSwiftUI/Modules/Room/LocationSharing/Test/Unit/LocationSharingViewModelTests.swift index a7871fa93..1eacdee00 100644 --- a/RiotSwiftUI/Modules/Room/LocationSharing/Test/Unit/LocationSharingViewModelTests.swift +++ b/RiotSwiftUI/Modules/Room/LocationSharing/Test/Unit/LocationSharingViewModelTests.swift @@ -50,7 +50,7 @@ class LocationSharingViewModelTests: XCTestCase { expectation.fulfill() case .shareLiveLocation: XCTFail() - case .showLabFlagPromotionIfNeeded: + case .checkLiveLocationCanBeStarted: XCTFail() } }