Skip to main content
Version: v4

Threaded Messages

Overview

ThreadedMessages is a Composite Component that displays all replies made to a particular message in a conversation. By default, the parent message will be displayed at the top, the message composer will be at the bottom and between them a message list will contain all replies.

Image

ThreadedMessages is composed of the following components:

ComponentDescription
MessageListCometChatMessageList is a component that displays a list of Messages
MessageComposerCometChatMessageComposer is a component that helps in writing and editing of messages and also sending attachments

Usage

Integration

The following code snippet illustrates how you can directly incorporate the ThreadedMessages component into your layout.xml file.

<com.cometchat.chatuikit.threadedmessages.CometChatThreadedMessages
android:id="@+id/threaded_messages"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

ThreadedMessages does not have its own actions. However, you can override the behavior of the ThreadedMessages component by using the actions of its Components, with the help of Configurations.

Example

In this example, we are overriding the onThreadReplyClick of the MessageList Component using MessageListConfiguration and applying it to ThreadedMessages.

MessageListConfiguration configuration = new MessageListConfiguration();
configuration.setOnThreadRepliesClick(new CometChatMessageList.ThreadReplyClick() {
@Override
public void onThreadReplyClick(Context context, BaseMessage baseMessage, CometChatMessageTemplate cometChatMessageTemplate, CometChatMessageBubble cometChatMessageBubble) {

}
});
threadedMessages.setMessageListConfiguration(configuration);

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.

ThreadedMessages does not have its own Filters. However, you can filter the messages list in ThreadedMessages Component using MessageListConfiguration.

Example

In this example, we are filtering messages based on the ParentMessageID and searching for messages that contain the keyword "payment".

MessageListConfiguration configuration = new MessageListConfiguration();

MessagesRequest.MessagesRequestBuilder builder = new MessagesRequest.MessagesRequestBuilder()
.setParentMessageId(213)
.setSearchKeyword("payment");
configuration.setMessagesRequestBuilder(builder);

threadedMessages.setMessageListConfiguration(configuration);


Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.

The MessageList Component does not emit any events of its own.


Customization

To fit your app's design requirements, you can customize the appearance of the conversation component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.


Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

1. ThreadedMessage Style

To modify the styling, you can apply the ThreadedMessageStyle to the ThreadedMessage Component using the setStyle method.

ThreadedMessagesStyle style = new ThreadedMessagesStyle();
threadedMessages.setStyle(style)

The following properties are exposed by ThreadedMessagesStyle:

MethodsTypeDescription
setBackground@ColorInt

int
used to set the background color
setBorderWidthintused to set border
borderRadiusdoubleused to set border radius
setBackgroundDrawableused to set background gradient
setTitleAppearance@StyleRes intused to customise the appearance of the title in the app bar
setCloseIconTint@ColorInt intused to set the color of the close icon in the app bar

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

CometChatMessageList threadedMessages = findViewById(R.id.threaded_messages);
threadedMessages.setCloseIcon(R.drawable.ic_back_ios);
threadedMessages.setTitle("Your_Title");

Below is a list of customizations along with corresponding code snippets

PropertyDescriptionCode
Set ParentMessage report Used to to set the message for which the replies need to be fetched.setParentMessage(BaseMessage)
Set TitleUsed to set title in the app bar.setTitle(String)
Set CloseIconUsed to set the icon to exit the widget.setTitle(@DrawableRes int)
setHideMessageComposerUsed to toggle visibility for CometChatMessageComposer.setHideMessageComposer(boolen)

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.

MessageBubbleView

By using setMessageBubbleView(), You can set parent message buggle view inside ThreadedMessage Component.

threadedMessages.setMessageBubbleView()

Example

Image

In this example, we will set parent message view which we get from setOnThreadRepliesClick Action of MessageList Component and apply custom styles on it.

messageList.setOnThreadRepliesClick(new CometChatMessageList.ThreadReplyClick() {
@Override
public void onThreadReplyClick(Context context, BaseMessage baseMessage, CometChatMessageTemplate cometChatMessageTemplate, CometChatMessageBubble cometChatMessageBubble) {
threadedMessages.setParentMessage(baseMessage);
threadedMessages.setMessageBubbleView(new Function2<Context, BaseMessage, View>() {
@Override
public View apply(Context context, BaseMessage baseMessage) {
MessageBubbleStyle messageBubbleStyle = new MessageBubbleStyle();
messageBubbleStyle.setBorderColor(R.color.purple_700);
messageBubbleStyle.setBorderWidth(10);
cometChatMessageBubble.setStyle(messageBubbleStyle);
return cometChatMessageBubble;
}
});
}
});

MessageActionView

By utilizing the setMessageActionView() method, you can assign custom actions to the parent message bubble view inside the ThreadedMessage Component.

threadedMessages.setMessageActionView();

Example

Image

In this example, we are setting mock smart reply view to parent message bubble in ThreadedMessages Component.

custom_header_view_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.cardview.widget.CardView
android:id="@+id/card1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
app:cardCornerRadius="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smart Reply"
android:padding="10dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:textColor="@color/white"
android:background="@color/purple_700"
/>

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/card2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
app:cardCornerRadius="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smart Reply"
android:padding="10dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:textColor="@color/white"
android:background="@color/purple_700"
/>

</androidx.cardview.widget.CardView>


<androidx.cardview.widget.CardView
android:id="@+id/card3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
app:cardCornerRadius="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smart Reply"
android:padding="10dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:textColor="@color/white"
android:background="@color/purple_700"
/>

</androidx.cardview.widget.CardView>


<androidx.cardview.widget.CardView
android:id="@+id/card4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
app:cardCornerRadius="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smart Reply"
android:padding="10dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:textColor="@color/white"
android:background="@color/purple_700"
/>

</androidx.cardview.widget.CardView>

</LinearLayout>

threadedMessages.setMessageActionView((context1, baseMessage1) -> {
View view = getLayoutInflater().inflate(R.layout.custom_header_view_layout, null);
return view;
});

setMessageListView

You can set your custom message list view using the setMessageListView() method. But keep in mind, by using this you will override the default message ListView functionality.

threadedMessages.setMessageListView()

Example

Image

In this example, we will create a custom_messages_list_layout.xml and inflate it inside the setMessageListView() method.

custom_messages_list_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"

xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="15dp"
app:cardBackgroundColor="@color/secondary_dark"
>

<com.cometchat.chatuikit.messagelist.CometChatMessageList
android:id="@+id/message_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
/>

</androidx.cardview.widget.CardView>

</RelativeLayout>
threadedMessages.setMessageListView((context, parentMessage, user1, group) -> {
View view = getLayoutInflater().inflate(R.layout.custom_messages_list_layout, null);
CometChatMessageList messageList = view.findViewById(R.id.message_list);
if(user1 != null)
messageList.setUser(user1);
else
messageList.setGroup(group);
return view;
});

setMessageComposerView

You can set your custom Message Composer view using the setMessageComposerView() method. But keep in mind, by using this you will override the default message composer functionality.

threadedMessages.setMessageComposerView()

Example

Image

In this example, we will create a custom_composer_view_layout.xml and inflate it inside the setMessageComposerView() method.

custom_composer_view_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto">


<androidx.cardview.widget.CardView
android:id="@+id/card_editext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/purple_700"
app:contentPadding="10dp"
app:cardCornerRadius="10dp"
app:cardElevation="10dp"
android:layout_toLeftOf="@+id/card_sendbtn"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type message"
android:textColorHint="@color/white"
android:textColor="@color/white"
/>

</androidx.cardview.widget.CardView>


<androidx.cardview.widget.CardView
android:id="@+id/card_sendbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/purple_700"
app:contentPadding="10dp"
app:cardCornerRadius="10dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
app:cardElevation="10dp"
>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_send"
/>

</androidx.cardview.widget.CardView>

</RelativeLayout>
threadedMessages.setMessageComposerView(new Function4<Context, BaseMessage, User, Group, View>() {
@Override
public View apply(Context context,BaseMessage parentMessage, User user, Group group) {
View view = getLayoutInflater().inflate(R.layout.custom_composer_view_layout, null);
return view;
}
});

Configuration

Configurations offer the ability to customize the properties of each individual component within a Composite Component.

The ThreadedMessages is a Composite Component, and it has a distinct set of configurations for each of its components as follows.

MessageList

If you want to customize the properties of the MessageList Component inside ThreadedMessages Component, you need use the MessageListConfiguration object.

MessageListConfiguration messageListConfiguration = new MessageListConfiguration();
threadedMessages.setMessageListConfiguration(messageListConfiguration);

The MessageListConfiguration provides access to all the Action, Filters, Styles, Functionality, and Advanced properties of the MessageList component.

Please note that the properties marked with the report symbol are not accessible within the Configuration Object.

Example

Image

In this example, we will be changing the list alignment and modifying the message bubble styles in the MessageList component using MessageListConfiguration.

MessageListConfiguration messageListConfiguration = new MessageListConfiguration();

messageListConfiguration.setListAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED);

MessageBubbleStyle messageBubbleStyle= new MessageBubbleStyle();
messageBubbleStyle.setCornerRadius(20f);
messageBubbleStyle.setBorderColor(R.color.purple_700);
messageBubbleStyle.setBorderWidth(5);

messageListConfiguration.setWrapperMessageBubbleStyle(messageBubbleStyle);

threadedMessages.setMessageListConfiguration(messageListConfiguration);

MessageComposer

If you want to customize the properties of the MessageComposer Component inside ThreadedMessages Component, you need use the MessageComposerConfiguration object.

MessageComposerConfiguration configuration = new MessageComposerConfiguration();
threadedMessages.setMessageComposerConfiguration(configuration);

The MessageComposerConfiguration provides access to all the Action, Filters, Styles, Functionality, and Advanced properties of the MessageComposer component.

Please note that the properties marked with the report symbol are not accessible within the Configuration Object.

Example

Image

In this example, we'll be adding a custom header view and customizing some properties of the MessageComposer component using MessageComposerConfiguration.

MessageComposerConfiguration configuration = new MessageComposerConfiguration();

View view = getLayoutInflater().inflate(R.layout.custom_header_view_layout, null);
configuration.setHeaderView(view);

MessageComposerStyle composerStyle = new MessageComposerStyle();
composerStyle.setBorderColor(Color.LTGRAY);
composerStyle.setBorderWidth(5);
composerStyle.setCornerRadius(20);
configuration.setStyle(composerStyle);

threadedMessages.setMessageComposerConfiguration(configuration);