Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
- Connect to the Chat server. See Connection page to learn how to do it.
Dialog types
All chats between users are organized in dialogs. There are 3 types of dialogs:- private dialog - a dialog between 2 users.
- group dialog - a dialog between the specified list of users.
- public dialog - an open dialog. Any user from your app can be joined to it.
Create dialog
To create a private dialog, you need to set the dialog type toQBDialogType.PRIVATE and ID of an opponent you want to create a chat with.
- Java
- Kotlin
QBDialogType.GROUP and IDs of opponents you want to create a chat with using the QBChatDialog value.
- Java
- Kotlin
QBDialogType.PUBLIC_GROUP as a dialog type.
- Java
- Kotlin
Create dialog with custom parameters
Any dialog can be extended with additional parameters whether it is a private, group, or public. These parameters can be used to store additional data. Also, these parameters can be used in dialogs retrieval requests. To start using additional parameters, create an additional schema of your parameters. This is a Custom Objects class. Just create an empty class with all fields that you need. These fields will be additional parameters in your dialog. See this section to learn how to create a schema using Custom Objects. Then, specify the parameters defined in the schema in a new dialog.- Java
- Kotlin
Create group dialog with join required
When creating a group dialog, you can set theisJoinRequired parameter to true to require participants to explicitly join the dialog before they can send or receive real-time messages. This is only needed when you want to restrict real-time messaging in specific dialogs until participants explicitly join.
By default, isJoinRequired is false and participants can message without joining. This parameter applies only to group dialogs. You can change the default in application settings.
- Java
- Kotlin
Check if join required for group dialog
The
isJoinRequired field is available starting from QuickBlox Android SDK v4.4.0. See Create group dialog with join required for details.isJoinRequired value for any group dialog:
- Java
- Kotlin
Join group dialog
Starting from QuickBlox Android SDK v4.4.0, joining a group dialog is required only when
isJoinRequired is set to true for a dialog. See Create group dialog with join required for details.isJoinRequired is set to true for a group dialog, you need to join it by calling the join() method before you can send or receive real-time messages. See this section to learn how to send/receive real-time messages.
You must join the dialog after every new connection or reconnection. If the connection is lost and then restored, whether manually or automatically, you need to call join() again for each dialog where isJoinRequired is true.
- Java
- Kotlin
- Java
- Kotlin
You can join a group dialog only if your user ID is present in the
occupantIDs array in the dialog model.Your user ID is added to the occupantIDs array if you create a dialog or you are added to the dialog by another user. See this section to learn how to add occupants to the group dialog.- Java
- Kotlin
Join public dialog
Before you start chatting in a public dialog, you must join it by calling thejoin() method. Unlike group dialogs, joining a public dialog is always required. If you’ve successfully joined the dialog, you can send/receive real-time messages. See this section to learn how to send/receive real-time messages.
You must join the dialog after every new connection or reconnection. If the connection is lost and then restored, whether manually or automatically, you need to call join() again.
- Java
- Kotlin
- Java
- Kotlin
- Java
- Kotlin
Leave group dialog
You can leave the group dialog by calling theleave() method. After leaving, you will stop receiving real-time messages from this dialog. You need to join the dialog again to resume receiving real-time messages.
Starting from QuickBlox Android SDK v4.4.0, leaving a group dialog is only needed when
isJoinRequired is set to true. If isJoinRequired is false, you do not need to call leave().- Java
- Kotlin
When you leave a group dialog, your user ID is still present in the
occupantIDs array in the dialog model. The dialog will still appear in the list of dialogs and you will still have access to the chat history.To remove yourself from the group dialog, use the updateChatDialog() method. See this section to learn how to remove occupants from the group dialog.Leave public dialog
You can leave the public dialog by calling theleave() method. After leaving, you will stop receiving real-time messages from this dialog. You need to join the dialog again to resume receiving real-time messages.
- Java
- Kotlin
Retrieve online users
You can get a list of dialog occupants who are currently online. Call therequestOnlineUsers() method to get the list of online users who are joined to the dialog. As a result, a list of user IDs is returned.
- Java
- Kotlin
requestOnlineUsers() method is used with regard to the dialog type
You can retrieve online users from the group dialog only if you are joined to it.
Retrieve list of dialogs
It’s common to request all your dialogs on every app login. The request below will return group dialogs containing thetest in the names, sorted in descending order, and limited to 50 dialogs on the page.
- Java
- Kotlin
If you want to retrieve only dialogs updated after some specific date time and order the search results, you can apply operators. This is useful if you cache dialogs somehow and do not want to obtain the whole list of your dialogs on every app start. Thus, you can apply search and sort operators to list dialogs on the page so that it is easier to view specific dialogs. The operators are set in the
QBRequestGetBuilder class.
If you want to get a paginated list of users from the server, you can set the following pagination parameters in the QBRequestGetBuilder class.
Search operators
You can use search operators to get more specific search results. The request below will return group dialogs in the array containingtest in their names.
- Java
- Kotlin
Sort operators
You can use sort operators to order the search results. The request below will return group dialogs by the field sorted in descending order.- Java
- Kotlin
Update dialog
You can update the information for a private, group, and public dialog.- Java
- Kotlin
Add occupants
You can add occupants in a group dialog by using theaddUsers() method. As a result, your ID will be added to the occupantIDs array.
- Java
- Kotlin
Let’s see what capabilities a particular user role has with regard to the dialog type.
Remove occupants
You can remove occupants from a group dialog by using theremoveUsers() method. As a result, the IDs will be removed the occupantIDs array.
- Java
- Kotlin
Let’s see what capabilities a particular user role has with regard to the dialog type.
Delete dialog
A request below will remove a dialog for a current user, but other users will be still able to chat there.- Java
- Kotlin
forceDelete parameter as true to completely remove the dialog for all users. You can also delete multiple dialogs in a single request.
You can also use multiple dialogs deleting using the snippet below.
- Java
- Kotlin
Get number of dialogs
You can get a number of dialogs using thegetChatDialogsCount() method. The request below will return a count of all group dialogs.
- Java
- Kotlin
Get number of unread messages
To get a number of unread messages from a particular dialog, use the code snippet below.- Java
- Kotlin
getTotalUnreadMessagesCount() method.
- Java
- Kotlin
Resources
A sequence of steps a user takes to start a dialog by moving through the application lifecycle.