# Chat Room

You can use the methods from the **TapCoreChatRoomManager** class to manage chat rooms.

| **Method Name**                                                                                        | **Description**                                                                                         |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| [​Get Personal Chat Room with Recipient User​](#get-personal-chat-room-with-recipient-user)            | Create new personal chat room with recipient user, or obtain chat room data if it already exists.       |
| [​Get Personal Chat Room with Recipient User ID​](#get-personal-chat-room-with-recipient-user-id)      | Create new personal chat room with recipient user ID, or obtain chat room data if it already exists.    |
| [​Get Personal Chat Room with Recipient XC User ID​](#get-personal-chat-room-with-recipient-user-id-1) | Create new personal chat room with recipient XC user ID, or obtain chat room data if it already exists. |
| [Create Group Chat Room](#create-group-chat-room)                                                      | Create a new group chat room with selected group name.                                                  |
| [Create Group Chat Room with Picture](#create-group-chat-room-with-group-image)                        | Create a new group chat room with selected group name and group picture.                                |
| [Get Group Chat Room](#get-group-chat-room)                                                            | Get group room data from selected group room ID.                                                        |
| [Update Group Chat Room Details](#update-group-chat-room-details)                                      | Update existing group chat room data.                                                                   |
| [Update Group Image](#update-group-image)                                                              | Update group picture with current selected image.                                                       |
| [Delete Group Chat Room](#delete-group-chat-room)                                                      | Delete group chat room and clear all chat data and participants.                                        |
| [Leave Group Chat](#leave-group-chat)                                                                  | Leave from selected group chat.                                                                         |
| [Add Members to Group Chat](#add-members-to-group-chat)                                                | Add selected member(s) to current group chat room.                                                      |
| [Remove Members from Group Chat](#remove-members-from-group-chat)                                      | Remove selected member(s) from current group chat room.                                                 |
| [Promote Group Admin](#promote-group-admin)                                                            | Promote selected member(s) as admin(s) to the current group chat room.                                  |
| [Demote Group Admin](#demote-group-admin)                                                              | Demote selected admin(s) to member(s) to the current group chat room.                                   |
| [Start Typing](#send-start-typing)                                                                     | Notify that the active user has started typing in the selected room.                                    |
| [Stop Typing](#send-stop-typing)                                                                       | Notify that the active user has stopped typing in the selected room.                                    |
| [Get Room Medias](#get-newer-messages-from-chat-room)                                                  | Retrieve existing media messages from a chat room                                                       |
| [Mark Chat Room as Unread](#download-message-file)                                                     | Mark a chat room as unread by the active user.                                                          |
| [Get Marked as Unread Chat Room List](#get-marked-as-unread-chat-room-list)                            | Get a list of chat rooms marked as unread by the active user.                                           |
| [Delete All Chat Room Messages](#delete-all-chat-room-messages)                                        | Clear all existing messages in a selected chat room for the active user.                                |

### Get Personal Chat Room with Recipient User Model <a href="#get-personal-chat-room-with-recipient-user" id="get-personal-chat-room-with-recipient-user"></a>

Create new personal chat room with recipient user, or obtain chat room data if it already exists.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
var roomModel = tapCoreChatRoomManager.createRoomWithOtherUser(RECIPIENT_USER)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**&#x20;

**`RECIPIENT_USER`**: (TAPUserModel) recipient user data
{% endhint %}

### Get Personal Chat Room with Recipient User ID <a href="#get-personal-chat-room-with-recipient-user-id" id="get-personal-chat-room-with-recipient-user-id"></a>

Create new personal chat room with recipient user ID, or obtain chat room data if it already exists.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
tapCoreChatRoomManager.createRoomWithuserID(RECIPIENT_ID, (roomModel) => {
   // do action here
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**&#x20;

**`RECIPIENT_ID`**: (String) user ID of recipient
{% endhint %}

### Get Personal Chat Room with Recipient **XC** User ID <a href="#get-personal-chat-room-with-recipient-user-id" id="get-personal-chat-room-with-recipient-user-id"></a>

Create new personal chat room with recipient user ID, or obtain chat room data if it already exists.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
tapCoreChatRoomManager.createRoomWithXCuserID(XC_USER_ID, (roomModel) => {
   // do action here
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**&#x20;

**`XC_USER_ID`**: (String) XC user ID of recipient
{% endhint %}

### Create Group Chat Room

Create a new group chat room with selected group name.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.createGroupChatRoom(GROUP_NAME, PARTICIPANT_LIST, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_NAME`**: (String) your group name\
\&#xNAN;**`PARTICIPANT_LIST`**: (List) list of the group participant's user IDs
{% endhint %}

### Create Group Chat Room With Group Image

Create a new group chat room with selected group name and group picture.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.createGroupChatRoomWithPicture(GROUP_NAME, PARTICIPANT_LIST, IMAGE_FILE, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_NAME`**: (String) name of the group chat room to create\
\&#xNAN;**`PARTICIPANT_LIST`**: (List) list of the group participant's user IDs\
\&#xNAN;**`IMAGE_FILE`**: (File) picture to be uploaded as the group's profile
{% endhint %}

### Get Group Chat Room

Get group room data from selected group room ID.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.getGroupChatRoom(GROUP_ID, {
      onSuccess : (response) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of group
{% endhint %}

### Update Group Chat Room Details

Create a new Update existing group chat room data.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.updateGroupChatRoomDetails(GROUP_ID, GROUP_NAME, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of group\
\&#xNAN;**`GROUP_NAME`**: (String) name of group
{% endhint %}

### Update Group Image

Update group picture with current selected image.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.updateGroupPicture(GROUP_ID, IMAGE_FILE, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of the selected group\
\&#xNAN;**`IMAGE_FILE`**: (File) new picture for the group's profile
{% endhint %}

### Delete Group Chat Room

Delete group chat room and clear all chat data and participants.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.deleteGroupChatRoom(ROOM_ID, {
      onSuccess : (response) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`ROOM_ID`**: (String) a room id of the group to delete
{% endhint %}

### Leave Group Chat

Leave from selected group chat.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.leaveGroupChatRoom(GROUP_ID, {
      onSuccess : (isSuccess, responseMessage) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of the selected group
{% endhint %}

### Add Members to Group Chat

Add selected member(s) to current group chat room.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.addGroupChatMembers(GROUP_ID, USER_IDs, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of the selected group\
\&#xNAN;**`USER_IDs`**: (List) list of the user IDs to add to the group
{% endhint %}

### Remove Members from Group Chat

Remove selected member(s) from current group chat room.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.removeGroupChatMembers : (GROUP_ID, USER_IDs, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of the selected group\
\&#xNAN;**`USER_IDs`**: (List) list of the user IDs to add to the group
{% endhint %}

### Promote Group Admin

Promote selected member(s) as admin(s) to the current group chat room.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.promoteGroupAdmins(GROUP_ID, USER_IDs, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of the selected group\
\&#xNAN;**`USER_IDs`**: (List) list of the user IDs to add to the group
{% endhint %}

### Demote Group Admin

Demote selected admin(s) to member(s) to the current group chat room.

{% tabs %}
{% tab title="JavaScript" %}

```java
tapCoreChatRoomManager.demoteGroupAdmins(GROUP_ID, USER_IDs, {
      onSuccess : (roomModel) => {
         // do action here
      },
      onError: (errorCode, errorMessage) => {
         // do action here     
      }
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GROUP_ID`**: (String) room ID of the selected group\
\&#xNAN;**`USER_IDs`**: (List) list of the user IDs to add to the group
{% endhint %}

### Send Start Typing <a href="#send-start-typing" id="send-start-typing"></a>

Notify that the active user has started typing in the selected room.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
tapCoreChatRoomManager.sendStartTypingEmit(roomID)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**&#x20;

**`ROOM_ID`**: (String) ID of the room where the user starts typing in
{% endhint %}

### Send Stop Typing <a href="#send-stop-typing" id="send-stop-typing"></a>

Notify that the active user has stopped typing in the selected room.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
tapCoreChatRoomManager.sendStopTypingEmit(roomID)
```

{% endtab %}
{% endtabs %}

### Get Room Media <a href="#get-newer-messages-from-chat-room" id="get-newer-messages-from-chat-room"></a>

{% tabs %}
{% tab title="JavaScript" %}

```javascript
tapCoreChatRoomManager.getRoomMedia(ROOM_ID, {
     onSuccess: (response) => {
             //do action here
     },
     onError: (errorCode, errorMessage) => {
            // do action here
     }
 }, minCreated = 0)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`ROOM_ID`**: (String) Group ID\
\&#xNAN;**`MIN_CREATED`**: (Long) Minimum Created Time in Millisecond. Leave empty if unnecessary
{% endhint %}

### Mark Chat Room as Unread <a href="#download-message-file" id="download-message-file"></a>

You can mark your chat room as unread.

```javascript
tapCoreChatRoomManager.markChatRoomAsUnread(ROOM_ID, {
    onSuccess: (res) => {
        // do action here
    },
    onError: (errCode, errMessage) => {
        // do action here
    }
});
```

{% hint style="info" %}
**ROOM\_ID:** (Number) room id\
**CALLBACK:** (Object) object of callback methods
{% endhint %}

### Get Marked as Unread Chat Room List

You can retrieve unread room list.

```javascript
tapCoreChatRoomManager.getMarkedAsUnreadChatRoomList({
    onSuccess: (res) => {
        // do action here
    },
    onError: (errCode, errMessage) => {
        // do action here
    }
});
```

{% hint style="info" %}
**CALLBACK:** (Object) object of callback methods
{% endhint %}

### Delete All Chat Room Messages

Use the **`deleteAllChatRoomMessages:`** method from the **TapCoreChatRoomManager** class to clear all existing messages in a selected chat room for the active user. The selected messages will only be deleted for the active user, and will not affect the other participants in the selected room.

```javascript
tapCoreChatRoomManager.deleteAllChatRoomMessages(ROOM_IDS, {
    onSuccess: (res) => {
        // do action here
    },
    onError: (err) => {
        // do action here
    }
})
```

{% hint style="info" %}
**ROOM\_IDS:** (Array\<Number>) IDs of the target rooms to delete the messages from
{% endhint %}

### Get Group In Common <a href="#get-group-in-common" id="get-group-in-common"></a>

You can retrieve group in common list.

```javascript
tapCoreChatRoomManager.fetchGroupInCommon(USER_ID, {
    onSuccess: (res) => {
        // do action here
    },
    onError: (errCode, errMessage) => {
        // do action here
    }
});
```

{% hint style="info" %}
**USER\_ID:** (Number) user id\
**CALLBACK:** (Object) object of callback methods
{% endhint %}
