# joinRoom method

Future <Result<bool, MUCError>> joinRoom(

1. JID roomJid,
2. String nick,
3. {int? maxHistoryStanzas}

)

Joins a Multi-User Chat room.

Joins the specified MUC room using the provided nickname. Sends a presence stanza with the appropriate attributes to join the room. Returns a `Result` with a boolean value indicating success or failure, or an MUCError if applicable.

## Implementation

    Future<Result<bool, MUCError>> joinRoom(
      JID roomJid,
      String nick, {
      int? maxHistoryStanzas,
    }) async {
      if (nick.isEmpty) {
        return Result(NoNicknameSpecified());
      }

      final completer =
          await _cacheLock.synchronized<Completer<Result<bool, MUCError>>>(
        () {
          _mucRoomCache[roomJid] = RoomState(
            roomJid: roomJid,
            nick: nick,
            joined: false,
          );

          final completer = Completer<Result<bool, MUCError>>();
          _mucRoomJoinCompleter[roomJid] = completer;
          return completer;
        },
      );

      await _sendMucJoin(roomJid, nick, maxHistoryStanzas);
      return completer.future;
    }