From beff1660375a388c0573f54c66cd323f0de44e47 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 7 Aug 2019 11:23:57 +0200 Subject: [PATCH] [Room] Add powerLevel methods --- lib/src/Room.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index a44e80e..613fe25 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -497,4 +497,25 @@ class Room { if (resp is ErrorResponse) return null; return Event.fromJson(resp, this); } + + /// Returns the user's own power level. + int get ownPowerLevel { + int powerLevel = 0; + State powerLevelState = states["m.room.power_levels"]; + if (powerLevelState == null) return powerLevel; + if (powerLevelState.content["users_default"] is int) + powerLevel = powerLevelState.content["users_default"]; + if (powerLevelState.content["users"] is Map && + powerLevelState.content["users"][client.userID] != null) + powerLevel = powerLevelState.content["users"][client.userID]; + return powerLevel; + } + + /// Returns the power levels from all users for this room or null if not given. + Map get powerLevels { + State powerLevelState = states["m.room.power_levels"]; + if (powerLevelState.content["users"] is Map) + return powerLevelState.content["users"]; + return null; + } }