Page Event Listening
Listening to Conversation List Page Events
You can set up conversation list operation listeners to implement custom requirements. The listening events for the conversation list RCChatListViewController are in the delegates RCChatListViewDelegate, RCChatListViewDataSource, and RCChatListViewModelDelegate. Overriding these delegate methods allows for custom handling.
Conversation List View Event Callbacks
RCChatListViewDelegate includes callbacks for cell loading, search bar clicks, conversation selection and deselection, and loading more conversations. After handling custom requirements in the methods below, you may still need the SDK's default processing, which can be invoked via super.
Cell About to Load in the List
/// Cell about to load in the list
/// - Parameters:
/// - listView: The list page
/// - chatModel: The conversation object
- (void)listView:(RCChatListView *)listView willLoadCell:(UITableViewCell *)cell
forChatModel:(RCChatModel *)chatModel;
Cell Loaded in the List
/// Cell loaded in the list
/// - Parameters:
/// - listView: The list page
/// - chatModel: The conversation message object
- (void)listView:(RCChatListView *)listView didLoadCell:(UITableViewCell *)cell
forChatModel:(RCChatModel *)chatModel;
Search Bar Click Event
/// Search bar click event
/// - Parameter listView: The conversation list
/// - Parameter searBar: The search bar
- (void)listView:(RCChatListView *)listView didClickSearchBar:(RCChatListSearchBar *)searBar;
Selecting a Conversation in the List
/// Selecting a conversation in the list
/// - Parameter listView: The conversation list
/// - Parameter chatModel: The conversation object
- (void)listView:(RCChatListView *)listView didSelectedChat:(RCChatModel *)chatModel;
Deselecting a Conversation in the List
/// Deselecting a conversation in the list
/// - Parameter listView: The conversation list
/// - Parameter chatModel: The conversation object
- (void)listView:(RCChatListView *)listView didDeselectedChat:(RCChatModel *)chatModel;
Conversation List About to Load More
/// Conversation list about to load more
/// - Parameter listView: The conversation list
/// - Parameter chatModel: The conversation object
- (void)listView:(RCChatListView *)listView didDetectPreloadingAtIndexPath:(NSIndexPath *)indexPath;
Conversation List View Data Source
RCChatListViewDataSource allows you to access the data source of the conversation list, and perform add, delete, modify, and query operations on the swipe edit items of the conversation.
Conversation List Data
/// Conversation list data
/// - Parameters:
/// - listView: The conversation list component
/// - tableView: The tableView
- (NSArray<RCChatModel *> *)listView:(RCChatListView *)listView
chatModelsInTableView:(UITableView *)tableView;
Code Example:
- (NSArray<RCChatModel *> *)listView:(RCChatListView *)listView chatModelsInTableView:(UITableView *)tableView {
NSMutableArray *tempArray = [super listView:listView chatModelsInTableView:tableView].mutableCopy;
/// Perform add, delete, modify operations on tempArray
///
return tempArray;
}
Swipe Edit Items for Conversation
/// Returns the items displayed by the cell based on indexPath and swipe direction
/// - Parameter listView: The conversation list
/// - Parameter indexPath: The conversation position
/// - Parameter direction: The swipe direction
- (NSArray<RCSwipeItem *> *)listView:(RCChatListView *)listView
cellSwipeItemsAtIndexPath:(NSIndexPath *)indexPath
forDirection:(RCSwipeDirection)direction;
Code Example:
- (NSArray<RCSwipeItem *> *)listView:(RCChatListView *)listView cellSwipeItemsAtIndexPath:(NSIndexPath *)indexPath forDirection:(RCSwipeDirection)direction {
NSMutableArray *tempArray = [super listView:listView cellSwipeItemsAtIndexPath:indexPath forDirection:direction].mutableCopy;
/// Perform add, delete, modify operations on tempArray
return tempArray;
}
Conversation List ViewModel Callbacks
RCChatListViewModelDelegate includes callbacks related to updating the conversation view. After handling custom requirements in the methods below, you may still need the SDK's default processing, which can be invoked via super.
Reloading the Conversation List
/// Reloading the conversation list
/// - Parameter viewModel: The ViewModel
/// - Parameter chatModels: The conversation data
- (void)viewModel:(RCChatListViewModel *)viewModel chatListDidReload:(NSArray<RCChatModel *> *)chatModels;
Inserting a Conversation
/// Inserting a conversation
/// - Parameter viewModel: The ViewModel
/// - Parameter indexSet: The conversation index list
- (void)viewModel:(RCChatListViewModel *)viewModel chatListDidInsertAtIndexSet:(NSIndexSet *)indexSet;
Moving a Conversation
/// Moving a conversation
/// - Parameter viewModel: The ViewModel
/// - Parameter indexSet: The conversation index list
- (void)viewModel:(RCChatListViewModel *)viewModel chatListDidMoveFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;
Updating Certain Conversations
/// Updating certain conversations
/// - Parameter viewModel: The ViewModel
/// - Parameter indexSet: The conversation index list
- (void)viewModel:(RCChatListViewModel *)viewModel chatListDidUpdateAtIndexSet:(NSIndexSet *)indexSet;
Removing Certain Conversations
/// Removing certain conversations
/// - Parameter viewModel: The ViewModel
/// - Parameter indexSet: The conversation index list
- (void)viewModel:(RCChatListViewModel *)viewModel chatListDidRemoveAtIndexSet:(NSIndexSet *)indexSet;
All Data Loaded in the Conversation List
/// All data loaded in the conversation list
/// - Parameter viewModel: The ViewModel
- (void)viewModelDidLoadAllChat:(RCChatListViewModel *)viewModel;
Error Occurred in the Conversation List
/// Error occurred in the conversation list
/// - Parameters:
/// - viewModel: The ViewModel
/// - error: The error information
- (void)viewModel:(RCChatListViewModel *)viewModel errorDidOccur:(NSError *)error;
Listening to Conversation Page Events
You can set up conversation page operation listeners to implement custom requirements. Below are the common events provided by RCChatViewController.
More Page About to Display
/// More page about to display
/// - Parameters:
/// - items: Built-in events
/// - chatModel: The conversation object
- (NSArray<RCChatMoreBarItem *> *)willDisplayMoreMenu:(NSArray<RCChatMoreBarItem *> *)items
forChatModel:(RCChatModel *)chatModel;
Search Bar Item Click Event
- (void)didClickSearchBarItem;
Long Press Message Edit View About to Display
- (NSArray<RCMessageEditBarItem *> *)willDisplayEditMenu:(NSArray<RCMessageEditBarItem *> *)items
forMessageModel:(RCMessageModel *)messageModel;
Select Bar About to Display When Selecting Messages
- (NSArray<RCMessageSelectionBarItem *> *)willDisplaySelectBar:(NSArray<RCMessageSelectionBarItem *> *)items
forChatModel:(RCChatModel *)chatModel;
Step-by-Step Forward Event
- (void)forwardOriginalMessages:(NSArray *)messageModels;
Merge Forward Event
- (void)forwardCombinedMessages:(NSArray *)messageModels;
End Selection Event
- (void)endSelection;
Message List Events
Message list events are defined in RCMessageListViewDelegate
@protocol RCMessageListViewDelegate <NSObject>
@optional
/// Called when a cell in the list is about to be loaded
/// - Parameters:
/// - listView: The list view
/// - messageModel: The Message Object
- (void)listView:(RCMessageListView *)listView willLoadCell:(UITableViewCell *)cell forMessageModel:(RCMessageModel *)messageModel;
/// Called when a cell in the list has finished loading
/// - Parameters:
/// - listView: The list view
/// - messageModel: The Message Object
- (void)listView:(RCMessageListView *)listView didLoadCell:(UITableViewCell *)cell forMessageModel:(RCMessageModel *)messageModel;
/// Called when a cell in the list is about to be displayed
/// - Parameters:
/// - listView: The list view
/// - messageModel: The Message Object
- (void)listView:(RCMessageListView *)listView willDisplayCell:(UITableViewCell *)cell forMessageModel:(RCMessageModel *)messageModel;
/// Called when previous page data needs to be loaded
/// - Parameters:
/// - listView: The list view
/// - messageModel: The first Message Object in the list
- (void)listView:(RCMessageListView *)listView didDetectPreviousPageLoadingWithMessageModel:(RCMessageModel *)messageModel;
/// Called when next page data needs to be loaded
/// - Parameters:
/// - listView: The list view
/// - messageModel: The last Message Object in the list
- (void)listView:(RCMessageListView *)listView didDetectNextPageLoadingWithMessageModel:(RCMessageModel *)messageModel;
/// Called when a list item is selected
/// - Parameters:
/// - listView: The list view
/// - tableView: tableView
/// - indexPath: indexPath
- (void)listView:(RCMessageListView *)listView didSelectRow:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath;
/// Called when a list item is deselected
/// - Parameters:
/// - listView: The list view
/// - tableView: tableView
/// - indexPath: indexPath
- (void)listView:(RCMessageListView *)listView didDeselectRow:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath;
/// Called when an unread message indicator in the list is tapped
/// - Parameters:
/// - listView: The list view
/// - unreadView: The unread message view
/// - type: The unread type
- (void)listView:(RCMessageListView *)listView didTapUnreadView:(RCMessageUnreadView *)unreadView type:(RCMessageUnreadViewType)type;
@end
Message List Data Source
Message list data source methods are defined in RCMessageListViewDataSource
@protocol RCMessageListViewDataSource <NSObject>
@required
/// Returns the messages in the current list
/// - Parameters:
/// - listView: The list component
/// - tableView: tableView
- (NSArray<RCMessageModel *> *)listView:(RCMessageListView *)listView
messagesInTableView:(UITableView *)tableView;
@optional
/// Customizes message edit items
/// - Parameters:
/// - listView: The list component
/// - tableView: tableView
/// - editItems: Built-in edit items
/// - indexPath: indexPath
- (NSArray<RCBarItem *> *)listView:(RCMessageListView *)listView
messagesEditItems:(NSArray<RCBarItem *> *)editItems
inTableView:(UITableView *)tableView
atIndexPath:(NSIndexPath *)indexPath;
/// Returns a custom cell
/// - Parameters:
/// - listView: The list component
/// - indexPath: The position of the cell
/// - tableView: tableView
- (nullable UITableViewCell *)listView:(RCMessageListView *)listView
cellAtIndexPath:(NSIndexPath *)indexPath
inTableView:(UITableView *)tableView;
@end
Message Cell Events
Message cell events are defined in RCMessageCellDelegate
@protocol RCMessageCellDelegate <NSObject>
@optional
/// Called when the portrait is tapped
- (void)tableViewCell:(UITableViewCell *)cell
didTapPortraitView:(RCMessageModel *)messageModel;
/// Called when the portrait is long-pressed
- (void)tableViewCell:(UITableViewCell *)cell
didLongPressPortraitView:(RCMessageModel *)messageModel;
/*!
Called when a phone number in the cell is tapped
- Parameter phoneNumber: The phone number that was tapped
- Parameter model: The data model of the message cell
When a phone number in the cell is tapped, this callback is invoked and didTapMessageCell: will not be triggered.
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapPhoneNumber:(NSString *)phoneNumber
messageModel:(RCMessageModel *)messageModel;
/*!
Called when a URL in the cell is tapped
- Parameter url: The URL that was tapped
- Parameter model: The data model of the message cell
When a URL in the cell is tapped, this callback is invoked and didTapMessageCell: will not be triggered.
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapUrl:(NSString *)url
messageModel:(RCMessageModel *)messageModel;
/*!
Called when the re-edit option in a recalled message cell is tapped
- Parameter model: The data model of the message cell
When the re-edit option in a recalled message cell is tapped, this callback is invoked and didTapMessageCell: will not be triggered.
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapReedit:(RCMessageModel *)messageModel;
/*!
Called when resend is tapped for a failed message
- Parameter model: The data model of the message cell
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapResend:(RCMessageModel *)messageModel;
/*!
Called when the cancel upload button for a multimedia message is tapped
- Parameter model: The data model of the multimedia message cell
Only supports cancelling file message uploads. The message is deleted after cancellation.
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapCancelUpload:(RCMessageModel *)messageModel;
/*!
Called when the referenced message content preview in a reference message is tapped
- Parameter model: The data model of the reference message cell
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapReferenced:(RCMessageModel *)messageModel;
/// Called when the message content is tapped
/// - Parameter model: The data model of the reference message cell
- (void)tableViewCell:(UITableViewCell *)cell
didTapMessage:(RCMessageModel *)messageModel;
/// Called when the message content is long-pressed
/// - Parameter model: The data model of the reference message cell
- (void)tableViewCell:(UITableViewCell *)cell
didLongPressMessage:(RCMessageModel *)messageModel;
@end
Text Input Events
Text input events are defined in RCTextInputDelegate
@protocol RCTextInputDelegate <NSObject>
@optional
/// Called when the input field begins editing
/// - Parameters:
/// - textView: The text input field
- (void)inputTextViewDidBeginEditing:(UITextView *)textView;
/// Called when the input field ends editing
/// - Parameters:
/// - textView: The text input field
- (void)inputTextViewDidEndEditing:(UITextView *)textView;
/// Called when the text in the input field changes
/// - Parameters:
/// - textView: The text input field
- (void)inputTextViewDidChange:(UITextView *)textView;
/// Called when text is about to be sent
/// - Parameters:
/// - textView: The text input field
/// - text: The text content
/// - mentionedInfo : Mention information
- (BOOL)inputTextView:(UITextView *)textView
didSelectSend:(NSString *)text
mentionedInfo:(RCMentionedInfo *)mentionedInfo;
/// Called when the text in the input field is about to change
/// - Parameters:
/// - textView: The text input field
/// - range: The range of the change
/// - text: The replacement text
- (BOOL) inputTextView:(UITextView *)textView
shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text;
/// Called when the cursor position in the input field changes
/// - Parameters:
/// - textView: The text input field
- (void)inputTextViewDidChangeSelection:(UITextView *)textView;
/// Called when the height of the input field changes
/// - Parameters:
/// - textView: The text input field
/// - beginHeight: The starting height
/// - endHeight: The ending height
- (void)inputTextView:(UITextView *)textView
heightDidChange:(CGFloat)beginHeight
endHeight:(CGFloat)endHeight;
/// Called when a mention (@) is input in the input field
/// - Parameters:
/// - textView: The text input field
- (void)inputTextViewDidInputMention:(UITextView *)textView;
/// Called when mention (@) input is cancelled in the input field
/// - Parameters:
/// - textView: The text input field
- (void)inputTextViewDidCancelMention:(UITextView *)textView;
@end
Photo Picker Callback
- (void)photoPickerDidSelect:(NSArray<PHAsset *> *)assets;