[Room] Fix power level setters and getters
This commit is contained in:
parent
a9a1a5ddd5
commit
fcff9e3c9c
|
@ -468,13 +468,15 @@ class Room {
|
||||||
/// Set the power level of the user with the [userID] to the value [power].
|
/// Set the power level of the user with the [userID] to the value [power].
|
||||||
Future<dynamic> setPower(String userID, int power) async {
|
Future<dynamic> setPower(String userID, int power) async {
|
||||||
if (states["m.room.power_levels"] == null) return null;
|
if (states["m.room.power_levels"] == null) return null;
|
||||||
Map powerMap = states["m.room.power_levels"].content["users"];
|
Map<String, dynamic> powerMap = {}
|
||||||
powerMap[userID] = power;
|
..addAll(states["m.room.power_levels"].content);
|
||||||
|
if (powerMap["users"] == null) powerMap["users"] = {};
|
||||||
|
powerMap["users"][userID] = power;
|
||||||
|
|
||||||
dynamic res = await client.connection.jsonRequest(
|
dynamic res = await client.connection.jsonRequest(
|
||||||
type: HTTPType.PUT,
|
type: HTTPType.PUT,
|
||||||
action: "/client/r0/rooms/$id/state/m.room.power_levels",
|
action: "/client/r0/rooms/$id/state/m.room.power_levels",
|
||||||
data: {"users": powerMap});
|
data: powerMap);
|
||||||
if (res is ErrorResponse) client.connection.onError.add(res);
|
if (res is ErrorResponse) client.connection.onError.add(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -843,9 +845,9 @@ class Room {
|
||||||
bool get canChangePowerLevel => canSendEvent("m.room.power_levels");
|
bool get canChangePowerLevel => canSendEvent("m.room.power_levels");
|
||||||
|
|
||||||
bool canSendEvent(String eventType) {
|
bool canSendEvent(String eventType) {
|
||||||
if (getState("m.room.power_levels") == null ||
|
if (getState("m.room.power_levels") == null) return false;
|
||||||
getState("m.room.power_levels").content["events"] == null) return false;
|
if (getState("m.room.power_levels").content["events"] == null ||
|
||||||
if (getState("m.room.power_levels").content["events"][eventType] == null)
|
getState("m.room.power_levels").content["events"][eventType] == null)
|
||||||
return eventType == "m.room.message"
|
return eventType == "m.room.message"
|
||||||
? canSendDefaultMessages
|
? canSendDefaultMessages
|
||||||
: canSendDefaultStates;
|
: canSendDefaultStates;
|
||||||
|
|
Loading…
Reference in a new issue