Skip to content

Commit

Permalink
Use Room power levels to check if user can post live sharing location…
Browse files Browse the repository at this point in the history
… event
  • Loading branch information
NicolasBuquet committed May 16, 2024
1 parent 85147e7 commit db5beb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,34 @@ 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 {
return false
}

let userPowerLevelRawValue = parameters.roomDataSource.roomState.powerLevels.powerLevelOfUser(withUserID: myUserId)

guard let userPowerLevel = RoomPowerLevel(rawValue: userPowerLevelRawValue) else {
// Tchap: allow live sharing geolocation based on room power levels
//
// guard let myUserId = parameters.roomDataSource.mxSession.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

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
}

// Tchap: allow user to live share its location even if its user power level is below moderator.
// return userPowerLevel.rawValue >= RoomPowerLevel.moderator.rawValue
return true
// Tchap: 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)
//
let liveSharingPowerLevel = roomPowerLevels.events[kMXEventTypeStringBeaconInfoMSC3672] as? Int ?? roomPowerLevels.stateDefault

return userPowerLevel.rawValue >= liveSharingPowerLevel
}

private func showLabFlagPromotionIfNeeded(completion: @escaping ((Bool) -> Void)) {
Expand Down
2 changes: 1 addition & 1 deletion changelog.d/984.change
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Autoriser le partage de localisation de la part d'un invité dans un Message Direct
Autoriser le partage de localisation dans un salon en se basant sur les niveaux d'autorisation du salon

0 comments on commit db5beb5

Please sign in to comment.