Documentation Index
Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Components provide context menus (e.g., long-press on a conversation) and the message composer provides attachment and AI action options. You can customize all of these at the component level or globally via the DataSource framework.
Component-Level Options
setOptions vs addOptions
| Method | Behavior |
|---|
setOptions(Function2<Context, Conversation, List<MenuItem>>) | Replaces all default options with your custom list |
addOptions(Function2<Context, Conversation, List<MenuItem>>) | Appends your custom options to the existing defaults |
Use addOptions when you want to keep the default actions (like “Delete”) and add your own. Use setOptions when you want full control over the menu.
Example: Adding a Custom Option
conversations.addOptions { context, conversation ->
listOf(
CometChatPopupMenu.MenuItem(
id = "pin",
name = "Pin Conversation",
startIcon = ContextCompat.getDrawable(context, R.drawable.ic_pin),
endIcon = null,
onClick = {
pinConversation(conversation)
}
)
)
}
conversations.addOptions((context, conversation) -> {
List<CometChatPopupMenu.MenuItem> items = new ArrayList<>();
items.add(new CometChatPopupMenu.MenuItem(
"pin",
"Pin Conversation",
ContextCompat.getDrawable(context, R.drawable.ic_pin),
null,
() -> pinConversation(conversation)
));
return items;
});
Example: Replacing All Options
conversations.setOptions { context, conversation ->
listOf(
CometChatPopupMenu.MenuItem(
id = "archive",
name = "Archive",
startIcon = ContextCompat.getDrawable(context, R.drawable.ic_archive),
endIcon = null,
onClick = { archiveConversation(conversation) }
),
CometChatPopupMenu.MenuItem(
id = "mute",
name = "Mute",
startIcon = ContextCompat.getDrawable(context, R.drawable.ic_mute),
endIcon = null,
onClick = { muteConversation(conversation) }
)
)
}
conversations.setOptions((context, conversation) -> {
List<CometChatPopupMenu.MenuItem> items = new ArrayList<>();
items.add(new CometChatPopupMenu.MenuItem("archive", "Archive",
ContextCompat.getDrawable(context, R.drawable.ic_archive), null,
() -> archiveConversation(conversation)));
items.add(new CometChatPopupMenu.MenuItem("mute", "Mute",
ContextCompat.getDrawable(context, R.drawable.ic_mute), null,
() -> muteConversation(conversation)));
return items;
});
DataSource Message Options
For message-level options (the actions that appear on message bubbles), use the DataSource framework. Override these methods in a DataSourceDecorator:
Message Option Methods
| Method | Description |
|---|
getTextMessageOptions(Context, BaseMessage, Group) | Options for text messages |
getImageMessageOptions(Context, BaseMessage, Group) | Options for image messages |
getVideoMessageOptions(Context, BaseMessage, Group) | Options for video messages |
getAudioMessageOptions(Context, BaseMessage, Group) | Options for audio messages |
getFileMessageOptions(Context, BaseMessage, Group) | Options for file messages |
getCommonOptions(Context, BaseMessage, Group) | Options common to all message types |
getMessageOptions(Context, BaseMessage, Group) | All options for a message (combines type-specific and common) |
Composer Action Methods
| Method | Description |
|---|
getAttachmentOptions(Context, User, Group) | Attachment options in the composer (camera, gallery, file, etc.) |
getAIOptions(Context, User, Group) | AI action options in the composer |
Extending Options via DataSourceDecorator
Use a DataSourceDecorator to add custom options globally without replacing the defaults:
class CustomOptionsDataSource(dataSource: DataSource) : DataSourceDecorator(dataSource) {
override fun getTextMessageOptions(
context: Context,
baseMessage: BaseMessage,
group: Group?
): List<CometChatMessageOption> {
val options = super.getTextMessageOptions(context, baseMessage, group).toMutableList()
options.add(CometChatMessageOption(
id = "translate",
title = "Translate",
icon = R.drawable.ic_translate,
onClick = { translateMessage(baseMessage) }
))
return options
}
}
// Register globally
ChatConfigurator.enable { dataSource -> CustomOptionsDataSource(dataSource) }
public class CustomOptionsDataSource extends DataSourceDecorator {
public CustomOptionsDataSource(DataSource dataSource) {
super(dataSource);
}
@Override
public List<CometChatMessageOption> getTextMessageOptions(
Context context, BaseMessage baseMessage, Group group) {
List<CometChatMessageOption> options =
new ArrayList<>(super.getTextMessageOptions(context, baseMessage, group));
options.add(new CometChatMessageOption(
"translate", "Translate", R.drawable.ic_translate,
() -> translateMessage(baseMessage)
));
return options;
}
}
// Register globally
ChatConfigurator.enable(dataSource -> new CustomOptionsDataSource(dataSource));