==

Q-Consultation for every industry

Securely hold virtual meetings and video conferences

Learn More>

Want to learn more about our products and services?

Speak to us now

How to update a group dialog on your Android chat app?

Android Chat App

Introduction

Welcome to our Android developer tutorial on how to update a group dialog in your chat app. Group chats have become an integral part of modern messaging platforms, facilitating collaborative conversations and fostering connections among users. It is essential that users have a smooth and intuitive experience while interacting with group conversations. Every mobile messaging chat application needs to have a logic to update specific chats, such as updating names, deleting or adding users, or updating custom parameters. In the following we will provide you with clear guidelines on how to effectively update group dialogues when using the QuickBlox Android SDK.

The QuickBlox Android SDK

QuickBlox offers a robust and developer-friendly Android SDK, that enables you to build powerful and feature-rich chat applications for the Android platform. The SDK comprises a comprehensive suite of tools and functionalities to streamline the development process. Chat features include one-on-one messaging, group chats, file sharing, push notifications, and more.

We have published a series of tutorials to show you how to use of SDKs most effectively:

Updating group dialog with the QuickBlox SDK

When we discuss a ‘group dialog’ we are referring to a ‘group chat.’ There are many cases when you would need to implement logic to update a group chat. Using the example of an e-learning application that students use to form group chats, or group dialogs, based on their class membership, let’s walk through the various scenarios where we would need to update that dialog.

1. Adding a new participant to the group dialog

A new student joins the mathematics class and wants to join the group chat on the app, we would need some logic to enable them to be added to the group dialog.

2. Removing and existing participant from the group dialog

Another student has decided to pause their education and they no longer need to participate in the online group chat. Now we require logic to remove them from the dialog.

3. Renaming the dialog

The students on the algebra group chat have completed the syllabus and are moving on to study geometry. Instead of creating a brand new group dialog, the “9th Algebra” group chat can be updated and renamed “9th Geometry”.

4. Updating image of group dialog

Furthermore, if we have used images to further illustrate each distinct group dialog, we need to be able to update those icons as well as the name of the dialog.

Now that we have set out several scenarios for when you would need to update a group dialog, let’s take a look at some code snippet below that shows this logic in action.

QBDialogRequestBuilder requestBuilder = new QBDialogRequestBuilder();

QBRestChatService.updateChatDialog(groupDialog, requestBuilder).performAsync(new QBEntityCallback() {
   @Override
   public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }


   @Override
   public void onError(QBResponseException e) {
       // something wrong happened
   }
});
QBDialogRequestBuilder

This object has the responsibility to “add” and “remove” users.

QBRestChatService.updateChatDialog(groupDialog, requestBuilder)

The method “updateChatDialog” in QBRestService accepts two arguments. First, the dialog which we want to update and second, the “requestBuilder” object which can be used to “add” or “remove” users.

new QBEntityCallback() {
   @Override
   public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }


   @Override
   public void onError(QBResponseException e) {
       // something wrong happened
   }
}

We use “QBEntityCallback” to receive the result of the operation.

public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }

The “onSuccess” method will be called when we have successfully updated our dialog and don’t have any problems.

This method has two arguments:
“dialog” – our updated dialog with updated data,
“args” – an additional object when we can get additional information. In our case we have not used it.

public void onError(QBResponseException e) {
       // something wrong happened
   }

The “onError” method will be called when we haven’t updated dialog correctly and are facing some problems. We can find details about the problem inside the “QBResponseException” object.

Code Snippet for each Use Case

1. Adding a new participant to the group dialog

QBDialogRequestBuilder requestBuilder = new QBDialogRequestBuilder();
requestBuilder.addUsers(users);

QBRestChatService.updateChatDialog(groupDialog, requestBuilder).performAsync(new QBEntityCallback() {
   @Override
   public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }


   @Override
   public void onError(QBResponseException e) {
       // something wrong happened
   }
});

As we can see, the code is same but we have only one additional line of code, which is:

requestBuilder.addUsers(users);

In the above code snippet, we call the “addUsers” method from the “requestBuilder” object and we can either pass an array of user objects or an array of user ids with it. Result will be the same.

2. Removing existing participant from the group dialog

QBDialogRequestBuilder requestBuilder = new QBDialogRequestBuilder();
requestBuilder.removeUsers(users);

QBRestChatService.updateChatDialog(groupDialog, requestBuilder).performAsync(new QBEntityCallback() {
   @Override
   public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }


   @Override
   public void onError(QBResponseException e) {
       // something wrong happened
   }
});

In the above code, we are calling the “removeUsers” method from the “requestBuilder”, and similar to the “addUsers” method, we can either pass an array of user objects or an array of user ids with it. Result will be the same.

3. Renaming the dialog

groupDialog.setName("Here will be our new dialog name");

QBRestChatService.updateChatDialog(groupDialog, new QBDialogRequestBuilder()).performAsync(new QBEntityCallback() {
   @Override
   public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }


   @Override
   public void onError(QBResponseException e) {
       // something wrong happened
   }
});

In the above code snippet, we use a slightly different approach. We pass an empty “QBDialogRequestBuilder” object to the “updateChatDialog” method, because we don’t need to use it. Alternatively, we can also pass “null” instead of the “QBDialogRequestBuilder” object, and the result will be the same.

To rename the dialog, we just need to call the “setName” method from the “groupDialog” object, which accepts only one string argument, which represents the new name of the dialog. In our case we rename our “mathematic” class to “common class chat”.

groupDialog.setName("Common class chat");

4. Updating image of group dialog

groupDialog.setPhoto("photo link");

QBRestChatService.updateChatDialog(groupDialog, new QBDialogRequestBuilder()).performAsync(new QBEntityCallback() {
   @Override
   public void onSuccess(QBChatDialog dialog, Bundle args) {
       // dialog updated
   }


   @Override
   public void onError(QBResponseException e) {
       // something wrong happened
   }
});

Here we have a similar situation like rename dialog, we are passing an empty “QBDialogRequestBuilder” object, because we don’t need to use it. Alternatively we can also pass a “null” and the result will be the same.

To update the image of the dialog, we just need to call the “setPhoto” method from the “groupDialog” object, which accepts a string parameter that contains a link to the image that we want to set:

Note: We need to pass a link to an image and not the image directly in the binary format.

groupDialog.setPhoto("photo link");

Conclusion

The ability to update a group dialog is an important feature of any chat app. In this tutorial we have demonstrated how to implement group dialog updates effectively in your Android chat app when building with the QuickBlox SDK.

Don’t forget to check out our other Android development tutorials to learn helpful hacks when building chat apps with the QuickBlox Android SDK or Android UI Kit.

Have Questions? Need Support?

Join the QuickBlox Developer Discord Community, where you can share ideas, learn about our software, & get support.

Join QuickBlox Discord

Leave a Comment

Your email address will not be published. Required fields are marked *

Read More

Ready to get started?

QUICKBLOX
QuickBlox post-box