Skip to main content

Listen to page events

Chat UI supports listening to click and long-press events on the channel list page and channel page. Applications can intercept these events in the corresponding methods and implement custom requirements.

Listen to channel list page events

Chat UI provides the channel list listener ChannelListBehaviorListener, which can listen to long-press and click events on channel items and channel portraits in the channel list.

Use NCChatUIConfig.channelListConfig().setBehaviorListener(...) to set the listener.

Java
NCChatUIConfig.channelListConfig().setBehaviorListener(listener);

Long press channel event

The following method is triggered when a channel item is long-pressed in the channel list. By default, the SDK displays a menu with options.

Java
boolean onConversationLongClick(Context context, View view, BaseUiChannel conversation)
ParameterTypeDescription
contextContextContext
viewViewView that triggered the click
conversationBaseUiChannelLong-pressed channel

Return true to handle this long-press event with custom logic; otherwise, return false to continue with the SDK default behavior.

Click channel event

The following method is triggered when a channel item is clicked in the channel list. When this click event is triggered, the SDK default navigation logic is as follows:

  • If it is a gathered channel, navigate to the gathered channel list page.
  • If it is a non-gathered channel, navigate to the channel page.
Java
boolean onConversationClick(Context context, View view, BaseUiChannel conversation)
ParameterTypeDescription
contextContextContext
viewViewView that triggered the click
conversationBaseUiChannelClicked channel

Return true to handle this click event with custom logic; otherwise, return false to continue with the SDK default behavior.

Click channel portrait event

The following method is triggered when a channel portrait (icon) is clicked. By default, the SDK does not handle this event.

Java
boolean onConversationPortraitClick(Context context, ChannelType conversationType, String targetId)
ParameterTypeDescription
contextContextContext
conversationTypeChannelTypeChannel type
targetIdStringChannel ID

Return true to handle this click event with custom logic. Otherwise, return false and the event is not handled.

Long press channel portrait event

The following method is triggered when a channel portrait (icon) is long-pressed. By default, the SDK does not handle this event and returns the result directly to the system.

Java
boolean onConversationPortraitLongClick(Context context, ChannelType conversationType, String targetId)
ParameterTypeDescription
contextContextContext
conversationTypeChannelTypeChannel type
targetIdStringChannel ID

Return true to handle this long-press event with custom logic. Otherwise, return false and the event is not handled.

Listen to channel page events

Chat UI provides the channel listener ChannelClickListener, which can listen to long-press and click events on message items and message portraits on the channel page.

Use NCChatUIConfig.channelConfig().setChannelClickListener(...) to set the listener.

Java
NCChatUIConfig.channelConfig().setChannelClickListener(listener);

Click message event

Java
boolean onMessageClick(Context context, View view, Message message);
ParameterTypeDescription
contextContextContext
viewViewView that triggered the click
messageMessageClicked message entity

Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.

Long press message event

Java
boolean onMessageLongClick(Context context, View view, Message message);
ParameterTypeDescription
contextContextContext
viewViewView that triggered the click
messageMessageLong-pressed message entity

Return true if you handle the long-press logic yourself; otherwise, return false to continue with the SDK default behavior.

Click user portrait on message event

Java
boolean onUserPortraitClick(
Context context,
ChannelType conversationType,
UserInfo user,
String targetId);
ParameterTypeDescription
contextContextContext
conversationTypeChannelTypeChannel type
userUserInfoClicked user info
targetIdStringChannel ID

Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.

Long press user portrait on message event

The following method is triggered when a user portrait (icon) on a message is long-pressed. By default, the SDK navigates to the user selection interface for the @ mention feature.

Java
boolean onUserPortraitLongClick(
Context context,
ChannelType conversationType,
UserInfo user,
String targetId);
ParameterTypeDescription
contextContextContext
conversationTypeChannelTypeChannel type
userUserInfoLong-pressed user info
targetIdStringChannel ID

Return true if you handle the long-press logic yourself; otherwise, return false to continue with the SDK default behavior.

Java
boolean onMessageLinkClick(Context context, String link, Message message);
ParameterTypeDescription
contextContextContext
linkStringClicked link
messageMessageClicked message entity

Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.

Click read receipt status event

Java
boolean onReadReceiptStateClick(Context context, Message message);
ParameterTypeDescription
contextContextContext
messageMessageClicked message entity

Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.

Click quick reply button event

If you have enabled the Chat UI quick reply feature, a quick reply panel appears when the user clicks the quick reply button on the channel page. To intercept this click event, return true and you can customize the logic after clicking the quick reply button; otherwise, return false to continue with the SDK default behavior.

Java
default boolean onQuickReplyClick(Context context) {
return false;
}