From 85147e713977e4f8420573c7c56403b08d6b7e3c Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Wed, 3 Apr 2024 16:57:38 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Autoriser=20le=20partage=20de=20localisatio?= =?UTF-8?q?n=20de=20la=20part=20d'un=20invit=C3=A9=20dans=20un=20Message?= =?UTF-8?q?=20Direct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Coordinator/LocationSharingCoordinator.swift | 4 +++- changelog.d/984.change | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog.d/984.change diff --git a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift index 9cd5853c7..4eb6810e2 100644 --- a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift +++ b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift @@ -176,7 +176,9 @@ final class LocationSharingCoordinator: Coordinator, Presentable { return false } - return userPowerLevel.rawValue >= RoomPowerLevel.moderator.rawValue + // 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 } private func showLabFlagPromotionIfNeeded(completion: @escaping ((Bool) -> Void)) { diff --git a/changelog.d/984.change b/changelog.d/984.change new file mode 100644 index 000000000..37f1d578e --- /dev/null +++ b/changelog.d/984.change @@ -0,0 +1 @@ +Autoriser le partage de localisation de la part d'un invité dans un Message Direct \ No newline at end of file From db5beb57c2940270c860df9c34a2ebcc23e0fa39 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 16 May 2024 17:56:15 +0200 Subject: [PATCH 2/3] Use Room power levels to check if user can post live sharing location event --- .../LocationSharingCoordinator.swift | 35 +++++++++++++------ changelog.d/984.change | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift index 4eb6810e2..929027c37 100644 --- a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift +++ b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift @@ -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)) { diff --git a/changelog.d/984.change b/changelog.d/984.change index 37f1d578e..2180dfbcc 100644 --- a/changelog.d/984.change +++ b/changelog.d/984.change @@ -1 +1 @@ -Autoriser le partage de localisation de la part d'un invité dans un Message Direct \ No newline at end of file +Autoriser le partage de localisation dans un salon en se basant sur les niveaux d'autorisation du salon \ No newline at end of file From e1e073cb464411c1622a2d36214906229d3b21b0 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 16 May 2024 18:32:52 +0200 Subject: [PATCH 3/3] Check with Stable then Unstable event keys --- .../Coordinator/LocationSharingCoordinator.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift index 929027c37..99cbddb91 100644 --- a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift +++ b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/Coordinator/LocationSharingCoordinator.swift @@ -191,7 +191,9 @@ final class LocationSharingCoordinator: Coordinator, Presentable { // // let liveSharingPowerLevel = parameters.roomDataSource.roomState.powerLevels.minimumPowerLevelForSendingStateEvent(.beaconInfo) // - let liveSharingPowerLevel = roomPowerLevels.events[kMXEventTypeStringBeaconInfoMSC3672] as? Int ?? roomPowerLevels.stateDefault + + // 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 }