Skip to main content

Page Event Listening

Listening to Conversation List Page Events

You can set up conversation list operation listeners to implement custom requirements. Below are common events provided by RCConversationListViewController.h. You can also refer directly to the IMKit source code to view all available events.

tip

When overriding listener methods, ensure to call the super method of the overridden method to avoid affecting the original logic of the IMKit SDK.

About to Display Conversation Cell

You can override the willDisplayConversationTableCell: method of RCConversationListViewController to modify certain display attributes of the conversation Cell, such as font color or size for the built-in Cell styles in the conversation list.

Modifying the Cell layout is not recommended. For higher UI customization requirements, consider customizing the conversation Cell in the conversation list.

Method Prototype

- (void)willDisplayConversationTableCell:(RCConversationBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath;

Parameter Description

ParameterTypeDescription
cellRCConversationBaseCellThe Cell about to be displayed
indexPathNSIndexPathThe index value of the corresponding conversation Cell data model in the data source

Tapping a Conversation Cell

Override the onSelectedTableRow: method of RCConversationListViewController to navigate to your custom chat UI.

Method Prototype

- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType
conversationModel:(RCConversationModel *)model
atIndexPath:(NSIndexPath *)indexPath;

Parameter Description

ParameterTypeDescription
conversationModelTypeRCConversationModelTypeThe Model type of the currently tapped conversation
modelRCConversationModelThe Model of the currently tapped conversation
indexPathNSIndexPathThe index value of the current conversation in the list data source

Tapping a Conversation List Avatar

Each conversation item in the conversation list displays an avatar icon (not the avatar in the message list within the chat UI). For one-to-one chats, it shows the other user's avatar; for group chats, it shows the group avatar; for aggregated conversations, it shows the default avatar or one set by the application.

You can override the didTapCellPortrait: method of RCConversationListViewController to customize the handling of avatar tap events.

Method Prototype

- (void)didTapCellPortrait:(RCConversationModel *)model;

Parameter Description

ParameterTypeDescription
modelRCConversationModelThe data model of the conversation Cell

Long-Pressing a Conversation List Avatar

Each conversation item in the conversation list displays an avatar icon (not the avatar in the message list within the chat UI). For one-to-one chats, it shows the other user's avatar; for group chats, it shows the group avatar; for aggregated conversations, it shows the default avatar or one set by the application.

You can override the didLongPressCellPortrait: method of RCConversationListViewController to customize the handling of long-press events on conversation list avatars.

Method Prototype

- (void)didLongPressCellPortrait:(RCConversationModel *)model;

Parameter Description

ParameterTypeDescription
modelRCConversationModelThe data model of the conversation Cell

Deleting a Conversation

You can override the didDeleteConversationCell: method of RCConversationListViewController to customize the handling of conversation deletion events.

Method Prototype

- (void)didDeleteConversationCell:(RCConversationModel *)model;

Parameter Description

ParameterTypeDescription
modelRCConversationModelThe data model of the conversation Cell

About to Load Data Source

You can override the willReloadTableData: method of RCConversationListViewController to modify, add, or delete elements in the data source to customize the displayed content. The conversation list will display based on the modified data source you return. The data source contains elements that are data models of conversation Cells, i.e., RCConversationModel objects.

Method Prototype

- (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource;

Parameter Description

ParameterTypeDescription
dataSourceNSMutableArrayThe incremental data source about to be loaded
tip

The dataSource is incremental data: conversationListDataSource += dataSource. To change the content of the full data, modify conversationListDataSource.

About to Update Unread Message Count

This callback is triggered when a message is received or a conversation is deleted. You can override the notifyUpdateUnreadMessageCount method of RCConversationListViewController to perform operations related to unread message counts.

Method Prototype

- (void)notifyUpdateUnreadMessageCount;
tip

This method is called on a non-main thread. If you need to perform UI operations in this method, manually switch to the main thread.

Receiving a New Message in the Conversation List

You can override the didReceiveMessageNotification: method of RCConversationListViewController to customize the handling of new message events in the conversation list.

Method Prototype

- (void)didReceiveMessageNotification:(NSNotification *)notification;

Parameter Description

ParameterTypeDescription
notificationNSNotificationThe notification for the new message. The object of the notification is the RCMessage object. The userInfo is an NSDictionary object where the key is @"left" and the value is an NSNumber object representing the remaining number of unreceived messages.
tip

The SDK has default handling for message reception in this method (e.g., refreshing). If you override this method, ensure to call the super method of this method.

Listening to Chat UI Events

You can set up chat UI operation listeners to implement custom requirements. Below are common events provided by RCConversationViewController.h. You can also refer directly to the IMKit source code to view all available events.

Input Box Content Change

You can override the inputTextView: method of RCConversationViewController to customize the handling of input box content changes.

Method Prototype

- (void)inputTextView:(UITextView *)inputTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;

Parameter Description

ParameterTypeDescription
inputTextViewUITextViewThe text input box
rangeNSRangeThe range of the current operation
textNSStringThe inserted text

Input Box Height Change

You can override this method of RCConversationViewController to customize the handling of input box height changes.

Method Prototype

- (void)chatInputBar:(RCChatSessionInputBarControl *)chatInputBar shouldChangeFrame:(CGRect)frame;

Parameter Description

ParameterTypeDescription
chatInputBarRCChatSessionInputBarControlThe input toolbar
frameCGRectThe final frame to display the input toolbar
tip

If you override this method, ensure to call the super method of this method.

Preparing to Send a Message

This callback is triggered when preparing to send a message (excluding location messages, short videos, and RC sticker messages sent via plugins). You can override the willSendMessage: method of RCConversationViewController to customize the handling of message sending preparation. If the return value of this callback is not nil, the SDK will send the returned message content.

Method Prototype

- (RCMessageContent *)willSendMessage:(RCMessageContent *)messageContent;

Parameter Description

ParameterTypeDescription
messageContentRCMessageContentThe message content
tip

Messages sent via location plugins, business card plugins, or RC sticker messages do not trigger this callback. For message interception, filtering, or modification, consider using the RCIMMessageInterceptor protocol. For details, see Intercepting Messages.

Message Sent Completion

Override this method of RCConversationViewController to customize the handling of this event.

Method Prototype

- (void)didSendMessage:(NSInteger)status content:(RCMessageContent *)messageContent;

Parameter Description

ParameterTypeDescription
statusNSIntegerThe sending status: 0 for success, non-zero for failure
messageContentRCMessageContentThe message content

Canceling Message Sending

You can override the didCancelMessage: method of RCConversationViewController to customize the handling of message sending cancellation events.

Method Prototype

- (void)didCancelMessage:(RCMessageContent *)messageContent;

Parameter Description

ParameterTypeDescription
messageContentRCMessageContentThe message content

About to Insert a Message into the Data Source

This method is called when a message is about to be inserted into the data source. You can override the willAppendAndDisplayMessage: method of RCConversationViewController to filter or modify the message. If the return value of this callback is not nil, the SDK will insert the message Cell data model corresponding to the returned message entity into the data source and display it in the chat UI.

Method Prototype

- (RCMessage *)willAppendAndDisplayMessage:(RCMessage *)message;

Parameter Description

ParameterTypeDescription
messageRCMessageThe message content

About to Display a Message

You can override the willDisplayMessageCell: method of RCConversationViewController to customize the attribute settings of the message about to be displayed.

Method Prototype

- (void)willDisplayMessageCell:(RCMessageBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath;

Parameter Description

ParameterTypeDescription
cellRCMessageBaseCellThe message Cell
indexPathNSIndexPathThe index value of the corresponding message Cell data model in the data source

Displaying an Unregistered Message Cell

You can override the rcUnkownConversationCollectionView: method of RCConversationViewController to set the Cell for unknown message types (unregistered message types).

Method Prototype

- (RCMessageBaseCell *)rcUnkownConversationCollectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath;

Parameter Description

Returns the RCMessageBaseCell or the Cell to display for unregistered messages.

ParameterTypeDescription
collectionViewUICollectionViewThe current CollectionView
indexPathNSIndexPathThe index value of the corresponding message Cell data model in the data source

Displaying the Height of an Unregistered Message Cell

You can override the rcUnkownConversationCollectionView method of RCConversationViewController to set the display height of the Cell for unknown message types (unregistered message types).

Method Prototype

- (CGSize)rcUnkownConversationCollectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

Parameter Description

Returns the CGSize for the display height of the unregistered message Cell.

ParameterTypeDescription
collectionViewUICollectionViewThe current CollectionView
collectionViewLayoutUICollectionViewLayoutThe current CollectionView Layout
indexPathNSIndexPathThe index value of the corresponding message Cell data model in the data source

Tapping a Message Cell Avatar

You can override the didTapCellPortrait: method of RCConversationViewController to customize the handling of message Cell avatar tap events.

Method Prototype

- (void)didTapCellPortrait:(NSString *)userId;

Parameter Description

ParameterTypeDescription
userIdNSStringThe user ID corresponding to the tapped avatar

Long-Pressing a Message Cell Avatar

You can override the didLongPressCellPortrait: method of RCConversationViewController to customize the handling of long-press events on message Cell avatars.

Method Prototype

- (void)didLongPressCellPortrait:(NSString *)userId;

Parameter Description

ParameterTypeDescription
userIdNSStringThe user ID corresponding to the tapped avatar

Tapping a Message Cell Content

You can override the didTapMessageCell: method of RCConversationViewController to customize the handling of message Cell content tap events.

Method Prototype

- (void)didTapMessageCell:(RCMessageModel *)model;

Parameter Description

ParameterTypeDescription
modelRCMessageModelThe data model of the message Cell
tip

The IMKit SDK has default handling for taps on image, voice, and location messages in this method (e.g., viewing or playing). If you override this callback and wish to retain the SDK's original functionality, ensure to call the super method of this method.

Long-Pressing a Message Cell Content

You can override the didLongTouchMessageCell: method of RCConversationViewController to customize the handling of long-press events on message Cell content.

Method Prototype

- (void)didLongTouchMessageCell:(RCMessageModel *)model inView:(UIView *)view;

Parameter Description

ParameterTypeDescription
modelRCMessageModelThe data model of the message Cell
viewUIViewThe view where the long-press occurred
tip

The IMKit SDK has default handling for long-presses on message content in this method (e.g., displaying the context menu). If you override this callback and wish to retain the SDK's original functionality, ensure to call the super method of this method.

Tapping a URL in a Message Cell

You can override the didTapUrlInMessageCell: method of RCConversationViewController to customize the handling of URL tap events in message Cells.

Method Prototype

- (void)didTapUrlInMessageCell:(NSString *)url model:(RCMessageModel *)model;

Parameter Description

ParameterTypeDescription
modelRCMessageModelThe data model of the message Cell
urlNSStringThe tapped URL
tip

If you override this callback and wish to retain the SDK's original functionality, ensure to call the super method of this method.

Tapping a Phone Number in a Message Cell

You can override the didTapPhoneNumberInMessageCell: method of RCConversationViewController to customize the handling of phone number tap events in message Cells.

Method Prototype

- (void)didTapPhoneNumberInMessageCell:(NSString *)phoneNumber model:(RCMessageModel *)model;

Parameter Description

ParameterTypeDescription
modelRCMessageModelThe data model of the message Cell
phoneNumberNSStringThe tapped phone number

Getting the Long-Press Menu for a Message Cell

You can override the getLongTouchMessageCellMenuList: method of RCConversationViewController to customize the handling of the long-press menu for message Cells.

Method Prototype

- (NSArray<UIMenuItem *> *)getLongTouchMessageCellMenuList:(RCMessageModel *)model;

Parameter Description

ParameterTypeDescription
modelRCMessageModelThe data model of the message Cell
tip

If you override this callback and wish to retain the SDK's original functionality, ensure to call the super method of this method.

Starting Voice Recording

You can override the onBeginRecordEvent method of RCConversationViewController to customize the handling of voice recording start events.

Method Prototype

- (void)onBeginRecordEvent;

Ending Voice Recording

You can override the onEndRecordEvent method of RCConversationViewController to customize the handling of voice recording end events.

Method Prototype

- (void)onEndRecordEvent;

Canceling Voice Recording

You can override the onCancelRecordEvent method of RCConversationViewController to customize the handling of voice recording cancellation events.

Method Prototype

- (void)onCancelRecordEvent;

Tapping the Quick Reply Button

tip

Requires IMKit version ≥ 5.6.3.

If you have enabled the IMKit Quick Reply feature, tapping the Quick Reply button on the chat UI will display quick reply options.

You can override the didTapCommonPhrasesButton method of RCConversationViewController to return YES to intercept and implement custom logic when the quick reply button is tapped; otherwise, return NO to continue with the SDK's default logic.

Method Prototype

- (BOOL)didTapCommonPhrasesButton;

All Messages Fetched Event

tip

Requires IMKit SDK version ≥ 5.8.2.

When implementing message fetching functionality, you may need to know when all available remote messages have been fetched. To receive this notification event, you can override the noMoreMessageToFetch method in the RCConversationViewController class.

Method Prototype

- (void)noMoreMessageToFetch;