# Room

## Create a room

```objectivec
- (MXHTTPOperation*)createRoom:(NSString*)name
                    visibility:(MXRoomDirectoryVisibility)visibility
                     roomAlias:(NSString*)roomAlias
                         topic:(NSString*)topic
                       success:(void (^)(MXCreateRoomResponse *response))success
                       failure:(void (^)(NSError *error))failure NS_SWIFT_UNAVAILABLE("TEST");
```

**Input Parameters**:

<table><thead><tr><th width="144">Name</th><th width="113">Type</th><th width="396">Description</th><th>Required</th></tr></thead><tbody><tr><td>name</td><td>NSString</td><td>the room name</td><td>false</td></tr><tr><td>visibility</td><td>NSString</td><td>the visibility of the room</td><td>false</td></tr><tr><td>roomAlias</td><td>NSString</td><td>the room alias on the node the room will be created</td><td>false</td></tr><tr><td>topic</td><td>NSString</td><td>the room topic</td><td>false</td></tr></tbody></table>

**Output Parameters**:

`MXCreateRoomResponse`

<table><thead><tr><th>Name</th><th width="144">Type</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td>roomId</td><td>NSString</td><td>The allocated room id</td><td>true</td></tr></tbody></table>

## Create a room with parameters

```objectivec
- (MXHTTPOperation*)createRoomWithParameters:(MXRoomCreationParameters*)parameters
                                     success:(void (^)(MXCreateRoomResponse *response))success
                                     failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
```

**Input Parameters**:

| Name       | Type     | Description              | Required |
| ---------- | -------- | ------------------------ | -------- |
| parameters | NSString | MXRoomCreationParameters | true     |

**Output Parameters**:

`MXCreateRoomResponse`

<table><thead><tr><th>Name</th><th width="133">Type</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td>roomId</td><td>NSString</td><td>The allocated room id</td><td>true</td></tr></tbody></table>

## **Join a chat room**

```swift
client?.joinRoom(room_id, completion: { response in })
```

Parameters:

| Name      | Type   | Description | Required |
| --------- | ------ | ----------- | -------- |
| `room_id` | string | room id     | true     |

## **Invite user to the room**

```swift
client?.invite(user_id, toRoom: room_id) { response in }
```

Parameters:

| Name      | Type   | Description | Required |
| --------- | ------ | ----------- | -------- |
| `room_id` | string | room id     | true     |
| `user_id` | string | user id     | true     |

## **Leave the room**

```swift
client?.leaveRoom(room_id, completion: { response in })
```

Parameters:

| Name      | Type   | Description | Required |
| --------- | ------ | ----------- | -------- |
| `room_id` | string | room id     | true     |

## **Remove a user from the room**

```swift
client?.banUser(user_id, fromRoom: room_id, reason: reason, completion: { response in })
```

Parameters:

| Name      | Type   | Description   | Required |
| --------- | ------ | ------------- | -------- |
| `room_id` | string | room id       | true     |
| `user_id` | String | user id       | true     |
| `reason`  | String | reason string | true     |

## **Modify room name**

```swift
client?.setName(ofRoom: room_id, name: name, completion: { response in })
```

Parameters:

| Name      | Type   | Description   | Required |
| --------- | ------ | ------------- | -------- |
| `room_id` | string | room id       | true     |
| `name`    | string | new room name | true     |

## **Get room name**

```swift
client?.name(ofRoom: room_id, completion: { response in })
```

Parameters:

| Name      | Type   | Description | Required |
| --------- | ------ | ----------- | -------- |
| `room_id` | string | room id     | true     |

## Ban User from a room

```swift
- (MXHTTPOperation*)banUser:(NSString*)userId
                     inRoom:(NSString*)roomId
                     reason:(NSString*)reason
                    success:(void (^)(void))success
                    failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
```

**Input Parameters**：

<table><thead><tr><th>Name</th><th>Type</th><th width="183">Description</th><th>Required</th></tr></thead><tbody><tr><td>userId</td><td>NSString</td><td>user id</td><td>true</td></tr><tr><td>roomId</td><td>NSString</td><td>room id</td><td>true</td></tr><tr><td>reason</td><td>NSString</td><td>reason of banning the user</td><td>false</td></tr></tbody></table>

**Output Parameters**：

| Name    | Type  | Description                                       | Required |
| ------- | ----- | ------------------------------------------------- | -------- |
| success | block | A block object called when the operation succeeds | true     |
| failure | block | A block object called when the operation fails.   | true     |

## Unban user from a room

```swift
- (MXHTTPOperation*)unbanUser:(NSString*)userId
                       inRoom:(NSString*)roomId
                      success:(void (^)(void))success
                      failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
```

**Input Parameters**：

| Name   | Type     | Description | Required |
| ------ | -------- | ----------- | -------- |
| userId | NSString | user id     | true     |
| roomId | NSString | room id     | true     |

**Output Parameters**：

| Name    | Type  | Description                                       | Required |
| ------- | ----- | ------------------------------------------------- | -------- |
| success | block | A block object called when the operation succeeds | true     |
| failure | block | A block object called when the operation fails.   | true     |

***

{% hint style="warning" %}
The methods below are deprecated. Please avoid using them.
{% endhint %}

## **(Deprecated) Create a chat room**

```swift
client?.createRoom(parameters: params, completion: { response in })
```

Parameters:

MXRoomCreationParameters

| Name         | Type   | Description                                                             | Required |
| ------------ | ------ | ----------------------------------------------------------------------- | -------- |
| `type`       | string | type of login (the type of the above example is `m.login.did.identity`) | true     |
| `updated`    | string | updated time returned by the `pre_login`                                | true     |
| `identifier` | json   | login information                                                       | true     |
| `device_id`  | string | device id, not needed for new device                                    | false    |
