getPowerLevelByUserId method

int getPowerLevelByUserId(
  1. String userId
)

Returns the power level of the given user ID. If a user_id is in the users list, then that user_id has the associated power level. Otherwise they have the default level users_default. If users_default is not supplied, it is assumed to be 0. If the room contains no m.room.power_levels event, the room’s creator has a power level of 100, and all other users have a power level of 0.

Implementation

int getPowerLevelByUserId(String userId) {
  final powerLevelMap = getState(EventTypes.RoomPowerLevels)?.content;
  if (powerLevelMap == null) {
    return getState(EventTypes.RoomCreate)?.senderId == userId ? 100 : 0;
  }
  return powerLevelMap
          .tryGetMap<String, Object?>('users')
          ?.tryGet<int>(userId) ??
      powerLevelMap.tryGet<int>('users_default') ??
      0;
}