setPower method

Future<String> setPower(
  1. String userID,
  2. int power
)

Set the power level of the user with the userID to the value power. Returns the event ID of the new state event. If there is no known power level event, there might something broken and this returns null.

Implementation

Future<String> setPower(String userID, int power) async {
  var powerMap = getState(EventTypes.RoomPowerLevels)?.content;
  if (powerMap is! Map<String, dynamic>) {
    powerMap = <String, dynamic>{};
  }
  (powerMap['users'] ??= {})[userID] = power;

  return await client.setRoomStateWithKey(
    id,
    EventTypes.RoomPowerLevels,
    '',
    powerMap,
  );
}