From bb22a7232e4a92e20b7201a3674e177d0f894a13 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 13 Jun 2024 11:35:30 +0200 Subject: [PATCH] Check power level before starting live sharing location Signed-off-by: Nicolas Buquet --- .../LocationSharingCoordinator.swift | 21 ++++++++++++------- changelog.d/pr-7807.change | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 changelog.d/pr-7807.change diff --git a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift index 9cd5853c74..ea50b45317 100644 --- a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift +++ b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift @@ -166,17 +166,22 @@ final class LocationSharingCoordinator: Coordinator, Presentable { // Check if user can send beacon info state event private func canShareLiveLocation() -> Bool { - guard let myUserId = parameters.roomDataSource.mxSession.myUserId else { + guard let myUserId = parameters.roomDataSource.mxSession.myUserId, + let roomPowerLevels = parameters.roomDataSource.roomState.powerLevels, + let userPowerLevel = RoomPowerLevel(rawValue: parameters.roomDataSource.roomState.powerLevels.powerLevelOfUser(withUserID: myUserId)) else { return false } - let userPowerLevelRawValue = parameters.roomDataSource.roomState.powerLevels.powerLevelOfUser(withUserID: myUserId) - - guard let userPowerLevel = RoomPowerLevel(rawValue: userPowerLevelRawValue) else { - return false - } - - return userPowerLevel.rawValue >= RoomPowerLevel.moderator.rawValue + // Should call `minimumPowerLevelForSendingStateEvent(_ eventType: MXEventType) -> Int` from `MatrixSDK:MXRoomPowerLevels.swift` + // but can't because it is inaccessible due to 'internal' protection level + // + // let liveSharingPowerLevel = parameters.roomDataSource.roomState.powerLevels.minimumPowerLevelForSendingStateEvent(.beaconInfo) + // + + // Get live sharing power level from stable value, then unstable value and fallback on default value. + let liveSharingPowerLevel = (roomPowerLevels.events[kMXEventTypeStringBeaconInfo] ?? roomPowerLevels.events[kMXEventTypeStringBeaconInfoMSC3672]) as? Int ?? roomPowerLevels.stateDefault + + return userPowerLevel.rawValue >= liveSharingPowerLevel } private func showLabFlagPromotionIfNeeded(completion: @escaping ((Bool) -> Void)) { diff --git a/changelog.d/pr-7807.change b/changelog.d/pr-7807.change new file mode 100644 index 0000000000..cc803849fb --- /dev/null +++ b/changelog.d/pr-7807.change @@ -0,0 +1 @@ +Check power level before starting live sharing location \ No newline at end of file