goToRoom method

ActionResult goToRoom(
  1. String roomId, {
  2. bool notify = true,
})

Changes the current room.

Implementation

ActionResult goToRoom(String roomId, {bool notify = true}) {
  currentRoom.removeListener(notifyListeners);
  String oldRoom = _currentRoom;
  _currentRoom = roomId;
  Room current = currentRoom;
  current.addListener(notifyListeners);
  if (notify) {
    notifyListeners();
  }
  if (!current.hasBeenVisited) {
    if (current.onFirstVisit != null) {
      ActionResult result = current.onFirstVisit!(this);
      if (result.state != ActionResultState.success) {
        goToRoom(oldRoom, notify: notify);
        return result;
      }
    }
    current.hasBeenVisited = true;
  }
  return ActionResult.success(object: current);
}