join method
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({
/// In case of the room is not found on the server, the client leaves the
/// room and rethrows the exception.
bool leaveIfNotFound = true,
}) async {
final dmId = directChatMatrixID;
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.
if (dmId != null) await addToDirectChat(dmId);
// now join
await client.joinRoomById(id);
} on MatrixException catch (exception) {
if (dmId != null) await removeFromDirectChat();
if (leaveIfNotFound &&
membership == Membership.invite &&
// Right now Synapse responses with `M_UNKNOWN` when the room can not
// be found. This is the case for example when User A invites User B
// to a direct chat and then User A leaves the chat before User B
// joined.
// See: https://github.com/element-hq/synapse/issues/1533
exception.error == MatrixError.M_UNKNOWN) {
await leave();
}
rethrow;
}
return;
}