join method

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

Call the SDN 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 = directChatSDNID;
    if (dmId != null) {
      await addToDirectChat(dmId);
    }

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