# Room

## Join a room

```dart
client.joinRoomById(id);
```

Input Parameters:

| Name   | Type   | Description     | Required |
| ------ | ------ | --------------- | -------- |
| roomId | String | Room\_id string | true     |

## Create a room

```dart
 Future<String> createRoom(
      {Map<String, Object?>? creationContent,
      List<StateEvent>? initialState,
      List<String>? invite,
      List<Invite3pid>? invite3pid,
      bool? isDirect,
      String? name,
      Map<String, Object?>? powerLevelContentOverride,
      CreateRoomPreset? preset,
      String? roomAliasName,
      String? roomVersion,
      String? topic,
      Visibility? visibility})
```

## Create DM

```dart
// Start a new direct chat
final roomId = await createRoom(
      invite: [mxid],
      isDirect: true,
      preset: preset,
      initialState: initialState,
      powerLevelContentOverride: powerLevelContentOverride,
 );
```

## Invite user to a room

```
Future<void> invite(String userID)
```

Input Parameters:

| Name   | Type   | Description | Required |
| ------ | ------ | ----------- | -------- |
| userID | String | user ID     | true     |

## Get room information

```dart
builder: (context, snapshot) {
   final timeline = snapshot.data;
 }

Future<SyncUpdate> sync(
      {String? filter,
      String? since,
      bool? fullState,
      PresenceType? setPresence,
      int? timeout})
```

Input Parameters:

| Name        | Type         | Description              | Required |
| ----------- | ------------ | ------------------------ | -------- |
| filter      | String       | filter string            | false    |
| since       | String       | since string             | false    |
| fullState   | bool         | fullState bool           | false    |
| setPresence | PresenceType | setPresence PresenceType | false    |
| timeout     | String       | timeout int              | false    |

## Leave a room

```dart
Future<void> leave() async
```

## Modify room name

```dart
Future<String> setName(String newName)
```

Input Parameters:

| Name    | Type   | Description | Required |
| ------- | ------ | ----------- | -------- |
| newName | String | room name   | true     |

## Modify room type

```dart
 var response = await client.setRoomStateWithKey(
      roomId,
      eventType,
      stateKey,
      body,
    );
```

Input parameters:

| Name      | Type   | Description                           | Required |
| --------- | ------ | ------------------------------------- | -------- |
| roomid    | string | Roomid string                         | true     |
| eventType | string | The type of event to send             | true     |
| stateKey  | string | The state\_key for the state to send. | false    |
| body      | map    | JSON data                             | true     |

**Example**

```
 var response = await client.setRoomStateWithKey(
      room.id,
      "m.room.join_rules",
      '',
      jsonData,
    );
```

**JSON structure**

The JSON data has the following structure:

```json
{
    "join_rule": "token.access",
    "join_params": {
        "logic": "ANY",
        "Require": [
            {
                "required token": {
                    "name": "USD Coin",
                    "symbol": "USDC",
                    "logo": "https://static.alchemyapi.io/images/assets/3408.png",
                    "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
                },
                "requiredAmount": 10
            },
            {
                "required token": {
                    "name": "0N1 Power",
                    "symbol": "0N1",
                    "logo": "https://lh3.googleusercontent.com/7gOej3SUvqALR-qkqL_ApAt97SpUKQOZQe88p8jPjeiDDcqITesbAdsLcWlsIg8oh7SRrTpUPfPlm12lb4xDahgP2h32pQQYCsuOM_s=s120",
                    "Address": "0x3bf2922f4520a8ba0c2efc3d2a1539678dad5e9d",
                    "type": "ERC721"
                },
                "Amount required": 1
            }
        ]
    }
}
```

#### Explanation of Fields

* **join\_rule:** This field specifies the rule for joining a room.&#x20;
  * _token.access_: This rule allows only users with the required tokens to enter the room.
  * _token.message_: With this rule, all users are permitted to enter the room and view messages. However, only users who meet certain requirements can send messages within the room.
* **join\_params**: This section contains additional parameters for controlling room access.
  * _logic_: It specifies whether users need to meet just one of the specified requirements (_ANY_) or all of them (_ALL_) in order to gain access to the room.
  * _Require_: An array of objects specifying the required tokens and their associated criteria for access. You can configure at most five requirements.
    * _required token_: Details of the token that is required for access. This includes:
      * _name_: The name of the token.
      * _symbol_: The symbol of the token.
      * _logo_: URL to the logo image of the token.
      * _address_: The contract address of the token.
      * _requiredAmount_: Specifies the minimum required amount of the token for access.
