CometChatMessageHeader displays the User or Group information using CometChat SDK’s User or Group object. It also shows the typing indicator when the user starts typing in MessageComposer.
CometChatMessageComposer is an independent and critical component that allows users to compose and send various types of messages includes text, image, video and custom messages.
The CometChatMessages is responsible for managing runtime permissions. To ensure the ActivityResultLauncher is properly initialized, its object should be created in the the onCreate state of an activity. To ensure that the CometChatMessages is loaded within the fragment, it is important to make sure that the fragment is loaded in the onCreate state of the activity.
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.The Messages component does not have its actions. However, since it’s a Composite Component, you can use the actions of its components by utilizing the Configurations object of each component.ExampleIn this example, we are employing the ThreadRepliesClick action from the MessageList Component through the MessageListConfiguration object.
Report incorrect code
Copy
Ask AI
MessageListConfiguration configuration = new MessageListConfiguration();configuration.setOnThreadRepliesClick((context, baseMessage, cometChatMessageTemplate cometChatMessageBubble) -> { // You Custom Action});messages.setMessageListConfiguration(configuration);
The Messages Component overrides the ThreadRepliesClick action to navigate to the ThreadedMessages component. If you override ThreadRepliesClick, it will also override the default behavior of the Messages Component.
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.The Messages component does not have its filters. But as it is a Composite Component, you can use the filters of its components by using the Configurations object of each component. For more details on the filters of its components, please refer to MessageList Filters.ExampleIn this example, we’re applying the MessageList Component filter to the Messages Component using MessageListConfiguration.
Report incorrect code
Copy
Ask AI
MessageListConfiguration configuration = new MessageListConfiguration();MessagesRequest.MessagesRequestBuilder messagesRequest = new MessagesRequestMessagesRequestBuilder() .setSearchKeyword("your search keyword") .setUID("user uid");configuration.setMessagesRequestBuilder(messagesRequest);messages.setMessageListConfiguration(configuration);
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 list of events emitted by the Messages component is as follows.
Event
Description
ccMessageSent
Triggers whenever a loggedIn user sends any message, it will have two states such as: inProgress & sent
ccMessageEdited
Triggers whenever a loggedIn user edits any message from the list of messages .it will have two states such as: inProgress & sent
ccMessageDeleted
Triggers whenever a loggedIn user deletes any message from the list of messages
ccMessageRead
Triggers whenever a loggedIn user reads any message.
ccLiveReaction
Triggers whenever a loggedIn clicks on live reaction
Adding CometChatMessageEvents Listener’s
Report incorrect code
Copy
Ask AI
CometChatMessageEvents.addListener("YOUR_LISTENER_TAG", new CometChatMessageEvents() { @Override public void ccMessageSent(BaseMessage baseMessage, int status) { super.ccMessageSent(baseMessage, status); } @Override public void ccMessageEdited(BaseMessage baseMessage, int status) { super.ccMessageEdited(baseMessage, status); } @Override public void ccMessageDeleted(BaseMessage baseMessage) { super.ccMessageDeleted(baseMessage); } @Override public void ccMessageRead(BaseMessage baseMessage) { super.ccMessageRead(baseMessage); } @Override public void ccLiveReaction(int icon) { super.ccLiveReaction(icon); } });
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.
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. Messages Style
You can customize the appearance of the Messages Component by applying the MessagesStyle to it using the following code snippet.
Report incorrect code
Copy
Ask AI
MessagesStyle messagesStyle = new MessagesStyle();messagesStyle.setBackground(Color.BLACK);messagesStyle.setCornerRadius(20f);messages.setStyle(messagesStyle);
List of properties exposed by MessagesStyle
Property
Description
Code
set Background
Used to set the background color
.setBackground(@ColorInt int)
set Background
Used to set drawable background
.setBackground(Drawable)
set BorderColor
Used to set border color
.setBorderColor(@ColorInt int)
set BorderWidth
Used to set border width
.setBorderWidth(int)
set CornerRadius
Used to set corner radius
.setCornerRadius(float)
2. Component’s Styles
Being a Composite component, the Messages Component allows you to customize the styles of its components using their respective Configuration objects.For a list of all available properties, refer to each component’s styling documentation: MesssageHeader Styles, MessageList Styles, MessageComposer Styles, Details Styles, ThreadMessages Styles.ExampleIn this example, we are creating MessageListStyle and MessageComposerStyle and then applying them to the Messages Component using MessageListConfiguration and MessageComposerConfiguration.
Report incorrect code
Copy
Ask AI
MessageListStyle messageListStyle = new MessageListStyle();messageListStyle.setBackground(Color.BLACK);messageListStyle.setBorderColor(Color.WHITE);MessageComposerStyle messageComposerStyle = new MessageComposerStyle();messageComposerStyle.setBackground(R.color.black);messageComposerStyle.setBorderColor(com.cometchat.chatuikit.R.color.grey);MessageListConfiguration messageListConfiguration = new MessageListConfiguration();messageListConfiguration.setStyle(messageListStyle);messages.setMessageListConfiguration(messageListConfiguration);MessageComposerConfiguration messageComposerConfiguration = new MessageComposerConfiguration();messageComposerConfiguration.setStyle(messageComposerStyle);messages.setMessageComposerConfiguration(messageComposerConfiguration);
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.
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.
You can set your custom message header view using the setMessageHeaderView() method. But keep in mind, by using this you will override the default message header functionality.
Report incorrect code
Copy
Ask AI
messages.setMessageHeaderView()
Example
In this example, we will create a custom_header_view.xml and inflate it inside the setMessageHeaderView() method.
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.
Report incorrect code
Copy
Ask AI
messages.setMessageListView()
Example
In this example, we will create a custom_messages_list_layout.xml and inflate it inside the setMessageListView() method.
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.
Report incorrect code
Copy
Ask AI
messages.setMessageComposerView()
Example
In this example, we will create a custom_composer_view_layout.xml and inflate it inside the setMessageComposerView() method.
messages.setAuxiliaryHeaderMenu(new Function3<Context, User, Group, View>() { @Override public View apply(Context context, User user, Group group) { View view = getLayoutInflater().inflate(R.layout.auxiliary_button_layout, null); ImageView imgPayment = findViewById(R.id.img_payment); imgPayment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, "Clicked on payment option", Toast.LENGTH_SHORT).show(); } }); return view; }});
The Messages Component uses the setAuxiliaryHeaderMenu() method to establish its default functionality. By setting an Auxiliary Menu, the Messages Component gains the capability to navigate to the Details section.
Configurations offer the ability to customize the properties of each individual component within a Composite Component.The Messages Component is a Composite Component and it has a specific set of configuration for each of its components.
Please note that the properties marked with the 🛑 symbol are not accessible within the Configuration Object.
Example
In this example, we will be adding a custom back button and styling a few properties of the Avatar component of the MessageHeader component using MessageHeaderConfiguration.
Report incorrect code
Copy
Ask AI
MessageHeaderConfiguration configuration = new MessageHeaderConfiguration();View backButtonView = getLayoutInflater().inflate(R.layout.custom_header_back_icon, null);configuration.setBackIconView(backButtonView);AvatarStyle avatarStyle = new AvatarStyle();avatarStyle.setBorderColor(R.color.purple_700);avatarStyle.setBorderWidth(10);configuration.setAvatarStyle(avatarStyle);messages.setMessageHeaderConfiguration(configuration);
Please note that the properties marked with the 🛑 symbol are not accessible within the Configuration Object.
Example
In this example, we will be changing the list alignment and modifying the message bubble styles in the MessageList component using MessageListConfiguration.
Report incorrect code
Copy
Ask AI
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);messages.setMessageListConfiguration(messageListConfiguration);
If you want to customize the properties of the MessageComposer Component inside Messages Component, you need use the MessageComposerConfiguration object.
Report incorrect code
Copy
Ask AI
MessageComposerConfiguration configuration = new MessageComposerConfiguration();messages.setMessageComposerConfiguration(configuration);
Please note that the properties marked with the 🛑 symbol are not accessible within the Configuration Object.
Example
In this example, we’ll be adding a custom header view and customizing some properties of the MessageComposer component using MessageComposerConfiguration.
Report incorrect code
Copy
Ask AI
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);messages.setMessageComposerConfiguration(configuration);
If you want to customize the properties of the ThreadedMessages Component inside Messages Component, you need use the ThreadedMessagesConfiguration object.
Report incorrect code
Copy
Ask AI
ThreadedMessagesConfiguration configuration = new ThreadedMessagesConfiguration();messages.setThreadedMessagesConfiguration(configuration);
Please note that the properties marked with the 🛑 symbol are not accessible within the Configuration Object.
Example
In this example, we are adding a custom title to the Threaded Message component and also adding custom properties to the MessageList using MessageListConfiguration. We then apply these changes to the ThreadedMessages component using ThreadedMessagesConfiguration.
Report incorrect code
Copy
Ask AI
ThreadedMessagesConfiguration configuration = new ThreadedMessagesConfiguration();configuration.setTitle("Replies");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);configuration.setMessageListConfiguration(messageListConfiguration);messages.setThreadedMessagesConfiguration(configuration);