Group Conversations by Type
IMKit supports grouping (collapsing) conversations by type in the conversation list. After enabling grouping for specific conversation types, conversations of those types will be displayed as a single aggregated entry in the list.
By default, IMKit's conversation list displays all local conversations in a flat structure.
The illustration below demonstrates the effect of grouping one-to-one chat conversations. In the conversation list, all one-to-one chats are collapsed under "One-to-One Chats" (left). Tapping this entry navigates to the grouped conversation list (right). IMKit allows global configuration to customize the title and avatar of grouped conversations.
Usage
- Grouped conversation entries in the list cannot be pinned using the conversation pinning feature.
Configure Grouped Conversation Types
When initializing the conversation list RCConversationListViewController
or its subclass, you can specify which conversation types to group. Supported types include one-to-one chat, group chat, and system conversation.
Call the initialization method of RCConversationListViewController
to create the conversation list. Use displayConversationTypeArray
to define which conversation types should appear in the list, and collectionConversationTypeArray
to specify which types should be grouped (collapsed).
Note: Convert RCConversationType
to NSNumber when constructing the Array.
Parameter Description
Parameter | Type | Description |
---|---|---|
displayConversationTypeArray | NSArray (NSNumber *) | Array of conversation types to display. Convert RCConversationType to NSNumber. |
collectionConversationTypeArray | NSArray (NSNumber *) | Array of conversation types to group. Convert RCConversationType to NSNumber. |
Sample Code
NSArray *displayConversationTypeArray = @[@(ConversationType_PRIVATE), @(ConversationType_GROUP), @(ConversationType_SYSTEM)];
NSArray *collectionConversationTypeArray = @[@(ConversationType_SYSTEM)];
RCConversationListViewController *conversationListVC = [[RCDChatListViewController alloc] initWithDisplayConversationTypes:displayConversationTypeArray collectionConversationType:collectionConversationTypeArray];
[self.navigationController pushViewController:conversationListVC animated:YES];
Navigate to Grouped Conversation List
-
Handle tap events in the conversation list to navigate to the subgroup list when a grouped entry is tapped.
/*!
Callback when tapping a cell in the conversation list
@param conversationModelType Model type of the tapped conversation
@param model Conversation model
@param indexPath Index of the conversation in the data source
@discussion Override this method to navigate to the corresponding conversation.
When entering a subgroup list from a grouped entry, set isEnteredToCollectionViewController to YES.
*/
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType
conversationModel:(RCConversationModel *)model
atIndexPath:(NSIndexPath *)indexPath; -
Before navigating to the subgroup list, set the
isEnteredToCollectionViewController
property of theRCConversationListViewController
subclass toYES
.// Grouped conversation type (customize as needed)
if (conversationModelType == RC_CONVERSATION_MODEL_TYPE_COLLECTION) {
YouConversationListViewController *temp = [[YouConversationListViewController alloc] init];
NSArray *array = [NSArray arrayWithObject:[NSNumber numberWithInteger:model.conversationType]];
[temp setDisplayConversationTypes:array];
[temp setCollectionConversationType:nil];
temp.isEnteredToCollectionViewController = YES;
[self.navigationController pushViewController:temp animated:YES];
}
Customization
You can globally configure the title and avatar of grouped conversation entries through IMKit settings.
Customize Grouped Conversation Title
Supported since IMKit SDK 5.2.3.
In IMKit, the title of a grouped entry corresponds to its conversation type. Below are the default titles:
Grouped Type | Default Title | Resource Name |
---|---|---|
One-to-One | "Chat Assistant" | conversation_private_collection_title |
Group | "Group Assistant" | conversation_group_collection_title |
System | "System Assistant" | conversation_systemMessage_collection_title |
Discussion | "Discussion Assistant" | conversation_discussion_collection_title |
To customize titles, configure the globalConversationCollectionTitleDic property before initializing the conversation list:
Interface
/*!
Title for grouped conversations in the SDK conversation list
@discussion Uses default titles if not configured.
key: RCConversationType
value: Custom title (NSString)
*/
@property (nonatomic, strong) NSDictionary<NSNumber *, NSString *> *globalConversationCollectionTitleDic;
Parameters
Property | Type | Description |
---|---|---|
globalConversationCollectionTitleDic | NSDictionary | Custom title configuration |
key | NSNumber(RCConversationType) | Conversation type |
value | NSString | Custom title |
Sample Code
RCKitConfigCenter.ui.globalConversationCollectionTitleDic = @{
@(ConversationType_PRIVATE): @"Custom Group Title"
};
Customize Grouped Conversation Avatar
Supported since IMKit SDK 5.2.3.
IMKit uses the default RC avatar for all grouped conversations. To customize avatars, configure the globalConversationCollectionAvatarDic property before initializing the conversation list:
Interface
/*!
Avatar for grouped conversations in the SDK conversation list
@discussion Uses default avatars if not configured.
key: RCConversationType
value: Image path (local or remote URL)
*/
@property (nonatomic, strong) NSDictionary<NSNumber *, NSString *> *globalConversationCollectionAvatarDic;
Parameters
Property | Type | Description |
---|---|---|
globalConversationCollectionAvatarDic | NSDictionary | Custom avatar configuration |
key | NSNumber(RCConversationType) | Conversation type |
value | NSString | Image URI |
Sample Code
// Remote image
RCKitConfigCenter.ui.globalConversationCollectionAvatarDic = @{
@(ConversationType_PRIVATE): @"http://example.pic"
};
// Local image
RCKitConfigCenter.ui.globalConversationCollectionAvatarDic = @{
@(ConversationType_PRIVATE): [[NSBundle mainBundle] pathForResource:@"example" ofType:@"png"]
};