getSingleRoom method

  1. @override
Future<Room?> getSingleRoom(
  1. Client client,
  2. String roomId, {
  3. bool loadImportantStates = true,
})
override

Implementation

@override
Future<Room?> getSingleRoom(Client client, String roomId,
    {bool loadImportantStates = true}) async {
  // Get raw room from database:
  final roomData = await _roomsBox.get(roomId);
  if (roomData == null) return null;
  final room = Room.fromJson(copyMap(roomData), client);

  // Get important states:
  if (loadImportantStates) {
    final dbKeys = client.importantStateEvents
        .map((state) => TupleKey(roomId, state).toString())
        .toList();
    final rawStates = await _roomStateBox.getAll(dbKeys);
    for (final rawState in rawStates) {
      if (rawState == null || rawState[''] == null) continue;
      room.setState(Event.fromJson(copyMap(rawState['']), room));
    }
  }

  return room;
}