Skip to content

Commit

Permalink
Check power level before starting live sharing location
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Buquet committed Jun 13, 2024
1 parent 90f1122 commit 7e2af90
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 7e2af90

Please sign in to comment.