Page Event Listeners
IMKit supports listening to click and long-press events on the conversation list page and chat UI. Applications can intercept these events in corresponding methods to implement custom requirements.
Listening to Conversation List Page Events
IMKit provides the ConversationListBehaviorListener to monitor long-press and click events on conversation items and avatars in the conversation list.
Use the setConversationListBehaviorListener
method of RongIM
or IMCenter
to set up the listener.
RongIM.setConversationListBehaviorListener(listener);
Long-Press Conversation Event
This method is triggered when a conversation item is long-pressed in the conversation list. By default, the SDK displays a menu.
boolean onConversationLongClick(Context context, View view, BaseUiConversation conversation)
Parameter | Type | Description |
---|---|---|
context | Context | Context |
view | View | The view that triggered the event |
conversation | BaseUiConversation | The long-pressed conversation |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Click Conversation Event
This method is triggered when a conversation item is clicked in the conversation list. The SDK's default navigation logic is as follows:
- For aggregated conversations: Navigate to the aggregated conversation list page.
- For non-aggregated conversations: Navigate to the chat UI.
boolean onConversationClick(Context context, View view, BaseUiConversation conversation)
Parameter | Type | Description |
---|---|---|
context | Context | Context |
view | View | The view that triggered the event |
conversation | BaseUiConversation | The clicked conversation |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Click Conversation Avatar Event
This method is triggered when a conversation avatar (icon) is clicked. The SDK does not handle this event by default.
boolean onConversationPortraitClick(Context context, Conversation.ConversationType conversationType, String targetId)
Parameter | Type | Description |
---|---|---|
context | Context | Context |
conversationType | Conversation.ConversationType | Conversation type |
targetId | String | Target ID |
Return true
to handle the event customly; otherwise, return false
to ignore it.
Long-Press Conversation Avatar Event
This method is triggered when a conversation avatar (icon) is long-pressed. The SDK does not handle this event by default.
boolean onConversationPortraitLongClick(Context context, Conversation.ConversationType conversationType, String targetId)
Parameter | Type | Description |
---|---|---|
context | Context | Context |
conversationType | Conversation.ConversationType | Conversation type |
targetId | String | Target ID |
Return true
to handle the event customly; otherwise, return false
to ignore it.
Listening to Chat UI Events
IMKit provides the ConversationClickListener to monitor click and long-press events on message items and avatars in the chat UI.
Use the setConversationClickListener
method of RongIM
or IMCenter
to set up the listener.
IMCenter.setConversationClickListener(listener);
Click Message Event
boolean onMessageClick(Context context, View view, Message message);
Parameter | Type | Description |
---|---|---|
context | Context | Context |
view | View | The view that triggered the event |
message | Message | The clicked message object |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Long-Press Message Event
boolean onMessageLongClick(Context context, View view, Message message);
Parameter | Type | Description |
---|---|---|
context | Context | Context |
view | View | The view that triggered the event |
message | Message | The long-pressed message object |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Click User Avatar in Message Event
boolean onUserPortraitClick(
Context context,
Conversation.ConversationType conversationType,
UserInfo user,
String targetId);
Parameter | Type | Description |
---|---|---|
context | Context | Context |
conversationType | Conversation.ConversationType | Conversation type |
user | UserInfo | The clicked user's information |
targetId | String | Target ID |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Long-Press User Avatar in Message Event
This method is triggered when a user avatar (icon) in a message is long-pressed. By default, the SDK navigates to the @mention user selection interface.
boolean onUserPortraitLongClick(
Context context,
Conversation.ConversationType conversationType,
UserInfo user,
String targetId);
Parameter | Type | Description |
---|---|---|
context | Context | Context |
conversationType | Conversation.ConversationType | Conversation type |
user | UserInfo | The long-pressed user's information |
targetId | String | Target ID |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Click Hyperlink in Message Event
boolean onMessageLinkClick(Context context, String link, Message message);
Parameter | Type | Description |
---|---|---|
context | Context | Context |
link | String | The clicked hyperlink |
message | Message | The message containing the hyperlink |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Click Read Receipt Status Event
boolean onReadReceiptStateClick(Context context, Message message);
Parameter | Type | Description |
---|---|---|
context | Context | Context |
message | Message | The message with read receipt status |
Return true
to handle the event customly; otherwise, return false
to proceed with the SDK's default logic.
Click Quick Reply Button Event
Requires IMKit version ≥ 5.6.3.
If the IMKit Quick Reply feature is enabled, clicking the Quick Reply button in the chat UI will display quick replies. To intercept this event, return true
to implement custom logic; otherwise, return false
to proceed with the SDK's default behavior.
default boolean onQuickReplyClick(Context context) {
return false;
}