mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Make the room power levels optional as they can be missing depending on what state events are requested
This commit is contained in:
committed by
Stefan Ceriu
parent
c7ff6c019d
commit
de723853e3
@@ -552,7 +552,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
|
||||
// MARK: - Power Levels
|
||||
|
||||
func powerLevels() async -> Result<RoomPowerLevelsProxyProtocol, RoomProxyError> {
|
||||
func powerLevels() async -> Result<RoomPowerLevelsProxyProtocol?, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(RoomPowerLevelsProxy(room.getPowerLevels()))
|
||||
} catch {
|
||||
|
||||
@@ -53,7 +53,7 @@ struct RoomInfoProxy: RoomInfoProxyProtocol {
|
||||
var joinRule: JoinRule? { roomInfo.joinRule }
|
||||
var historyVisibility: RoomHistoryVisibility { roomInfo.historyVisibility }
|
||||
|
||||
var powerLevels: RoomPowerLevelsProxyProtocol { RoomPowerLevelsProxy(roomInfo.powerLevels) }
|
||||
var powerLevels: RoomPowerLevelsProxyProtocol? { RoomPowerLevelsProxy(roomInfo.powerLevels) }
|
||||
}
|
||||
|
||||
struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
|
||||
@@ -63,7 +63,7 @@ protocol RoomInfoProxyProtocol: BaseRoomInfoProxyProtocol {
|
||||
var joinRule: JoinRule? { get }
|
||||
var historyVisibility: RoomHistoryVisibility { get }
|
||||
|
||||
var powerLevels: RoomPowerLevelsProxyProtocol { get }
|
||||
var powerLevels: RoomPowerLevelsProxyProtocol? { get }
|
||||
}
|
||||
|
||||
extension BaseRoomInfoProxyProtocol {
|
||||
|
||||
@@ -11,6 +11,8 @@ import MatrixRustSDK
|
||||
protocol RoomPowerLevelsProxyProtocol {
|
||||
var values: RoomPowerLevelsValues { get }
|
||||
|
||||
var userPowerLevels: [String: Int64] { get }
|
||||
|
||||
func canOwnUser(sendMessage messageType: MessageLikeEventType) -> Bool
|
||||
func canOwnUser(sendStateEvent event: StateEventType) -> Bool
|
||||
func canOwnUserInvite() -> Bool
|
||||
|
||||
@@ -10,7 +10,11 @@ import MatrixRustSDK
|
||||
struct RoomPowerLevelsProxy: RoomPowerLevelsProxyProtocol {
|
||||
private let powerLevels: RoomPowerLevels
|
||||
|
||||
init(_ powerLevels: RoomPowerLevels) {
|
||||
init?(_ powerLevels: RoomPowerLevels?) {
|
||||
guard let powerLevels else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.powerLevels = powerLevels
|
||||
}
|
||||
|
||||
@@ -18,6 +22,10 @@ struct RoomPowerLevelsProxy: RoomPowerLevelsProxyProtocol {
|
||||
powerLevels.values()
|
||||
}
|
||||
|
||||
var userPowerLevels: [String: Int64] {
|
||||
powerLevels.userPowerLevels()
|
||||
}
|
||||
|
||||
func canOwnUser(sendMessage messageType: MessageLikeEventType) -> Bool {
|
||||
powerLevels.canOwnUserSendMessage(message: messageType)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
|
||||
|
||||
// MARK: - Power Levels
|
||||
|
||||
func powerLevels() async -> Result<RoomPowerLevelsProxyProtocol, RoomProxyError>
|
||||
func powerLevels() async -> Result<RoomPowerLevelsProxyProtocol?, RoomProxyError>
|
||||
func applyPowerLevelChanges(_ changes: RoomPowerLevelChanges) async -> Result<Void, RoomProxyError>
|
||||
func resetPowerLevels() async -> Result<Void, RoomProxyError>
|
||||
func suggestedRole(for userID: String) async -> Result<RoomMemberRole, RoomProxyError>
|
||||
|
||||
Reference in New Issue
Block a user