join method

Future<void> join({
  1. bool leaveIfNotFound = true,
})

Call the Matrix API to join this room if the user is not already a member. If this room is intended to be a direct chat, the direct chat flag will automatically be set.

Implementation

Future<void> join({bool leaveIfNotFound = true}) async {
  try {
    // If this is a DM, mark it as a DM first, because otherwise the current member
    // event might be the join event already and there is also a race condition there for SDK users.
    final dmId = directChatMatrixID;
    if (dmId != null) {
      await addToDirectChat(dmId);
    }

    // now join
    await client.joinRoomById(id);
  } on MatrixException catch (exception) {
    if (leaveIfNotFound &&
        [MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN]
            .contains(exception.error)) {
      await leave();
    }
    rethrow;
  }
  return;
}