From fcff9e3c9c2a7c366f88d42e3f8c980afdc84f24 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 5 Dec 2019 10:06:23 +0100 Subject: [PATCH] [Room] Fix power level setters and getters --- lib/src/Room.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index dda82161..ca4bd49b 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -468,13 +468,15 @@ class Room { /// Set the power level of the user with the [userID] to the value [power]. Future setPower(String userID, int power) async { if (states["m.room.power_levels"] == null) return null; - Map powerMap = states["m.room.power_levels"].content["users"]; - powerMap[userID] = power; + Map powerMap = {} + ..addAll(states["m.room.power_levels"].content); + if (powerMap["users"] == null) powerMap["users"] = {}; + powerMap["users"][userID] = power; dynamic res = await client.connection.jsonRequest( type: HTTPType.PUT, action: "/client/r0/rooms/$id/state/m.room.power_levels", - data: {"users": powerMap}); + data: powerMap); if (res is ErrorResponse) client.connection.onError.add(res); return res; } @@ -843,9 +845,9 @@ class Room { bool get canChangePowerLevel => canSendEvent("m.room.power_levels"); bool canSendEvent(String eventType) { - if (getState("m.room.power_levels") == null || - getState("m.room.power_levels").content["events"] == null) return false; - if (getState("m.room.power_levels").content["events"][eventType] == null) + if (getState("m.room.power_levels") == null) return false; + if (getState("m.room.power_levels").content["events"] == null || + getState("m.room.power_levels").content["events"][eventType] == null) return eventType == "m.room.message" ? canSendDefaultMessages : canSendDefaultStates;