mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Adopt room info power levels (#4245)
* Use the newly RoomInfo published PowerLevels; update permissions at the same time as the room info and avoid unnecessary async calls. * Introduce a RoomInfoProxyProtocol and associated mock and move away from mocked SDK RoomInfos * Bump the SDK to v25.06.23 * Expose new non-throwing methods for checking one's own user permissions * Fix the unit and preview tests (except the TimelineMediaPreviewDetails for which simplified snapshots were generated) * Converge on one single implementation for computing a room's avatar. * Fix more unit tests * Fix the TimelineMediaPreviewDetailsView snapshot tests This reverts commit 9b6c819e611ad2fa3de2c34a4a7aa556fc9faadd. --------- Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
+5
-12
@@ -27,9 +27,6 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn
|
||||
super.init(initialViewState: KnockRequestsListScreenViewState(), mediaProvider: mediaProvider)
|
||||
|
||||
updateRoomInfo(roomInfo: roomProxy.infoPublisher.value)
|
||||
Task {
|
||||
await updatePermissions()
|
||||
}
|
||||
|
||||
setupSubscriptions()
|
||||
}
|
||||
@@ -189,7 +186,6 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] roomInfo in
|
||||
self?.updateRoomInfo(roomInfo: roomInfo)
|
||||
Task { await self?.updatePermissions() }
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -214,20 +210,17 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func updateRoomInfo(roomInfo: RoomInfoProxy) {
|
||||
private func updateRoomInfo(roomInfo: RoomInfoProxyProtocol) {
|
||||
switch roomInfo.joinRule {
|
||||
case .knock, .knockRestricted:
|
||||
state.isKnockableRoom = true
|
||||
default:
|
||||
state.isKnockableRoom = false
|
||||
}
|
||||
}
|
||||
|
||||
private func updatePermissions() async {
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
state.canAccept = (try? powerLevels?.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canDecline = (try? powerLevels?.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBan = (try? powerLevels?.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
|
||||
state.canAccept = (try? roomInfo.powerLevels.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canDecline = (try? roomInfo.powerLevels.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBan = (try? roomInfo.powerLevels.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(KnockRequestsListScreenViewModel.self)-Loading"
|
||||
|
||||
Reference in New Issue
Block a user