按类型聚合会话
IMKit 支持在会话列表中按照会话类型进行聚合(折叠)。设置聚合显示的会话类型后,该类型的会话在会话列表中仅被展示为一个聚合条目。默认情况下,IMKit 的会话列表页面会以平铺方式展示所有本地会话。
下图展示了设置了单聊类型会话聚合显示的效果。在会话列表中,所有单聊会话折叠为“单聊消息”(左侧),点击后跳转到聚合会话列表(右侧)。IMKit 支持通过全局配置修改聚合会话页面的标题与头像。
用法
- 会话列表中的聚合会话项目不支持通过会话置顶功能设置为置顶项目。
设置聚合显示的会话类型
在初始化会话列表 RCConversationListViewController
或子类时,设置需要聚合的会话类型。支持单聊、群聊、系统会话类型。注意,您需要将 RCConversationType
转为 NSNumber构建 Array。
使用 collectionConversationTypeArray
参数传入聚合显示的会话类型。下例中我们聚 合显示所有系统会话。
调用 RCConversationListViewController
类的初始化方法构建会话列表页面,在 displayConversationTypeArray
中设置会话列表中需要包含的会话的类型,在 collectionConversationTypeArray
中设置需要聚合(折叠显示)的会话类型。
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];
参数 | 类型 | 说明 |
---|---|---|
displayConversationTypeArray | NSArray (NSNumber *) | 列表中需要显示的会话类型数组。需要将 RCConversationType 转为 NSNumber构建 Array。 |
collectionConversationTypeArray | NSArray (NSNumber *) | 列表中需要聚合为一条显示的会话类型数组。您需要将 RCConversationType 转为 NSNumber构建 Array。 |
点击进入聚合会话列表
-
您需要处理会话列表页面的点击事件,在点击聚合会话条目时,进入子会话列表。
/*!
点击会话列表中Cell的回调
@param conversationModelType 当前点击的会话的Model类型
@param model 当前点击的会话的Model
@param indexPath 当前会话在列表数据源中 的索引值
@discussion 您需要重写此点击事件,跳转到指定会话的会话页面。
如果点击聚合Cell进入具体的子会话列表,在跳转时,需要将isEnteredToCollectionViewController设置为YES。
*/
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType
conversationModel:(RCConversationModel *)model
atIndexPath:(NSIndexPath *)indexPath; -
在进入子会话列表前,设置
RCConversationListViewController
子类的isEnteredToCollectionViewController
属性为YES
。//聚合会话类型,此处自定设置。
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];
}
定制化
您可以通过 IMKit 全局配置修改聚合会话条目的标题与头像。
自定义聚合会话标题
IMKit SDK 从 5.2.3 开始支持该功能。
IMKit 会话列表中,聚合条目的标题与会话类型相关。下表列出了各会话类型的聚合显示条目的标题字符串:
聚合会话类型 | 会话标题 | 资源名称 |
---|---|---|
单聊 | "聊天助手" | conversation_private_collection_title |
群聊 | "群助手" | conversation_group_collection_title |
系统 | "系统消息助手" | conversation_systemMessage_collection_title |
讨论组 | "讨论组助手" | conversation_discussion_collection_title |
如果需要更改聚合会话标题,可以在进入会话列表之前,调用下面方法配置:
/*!
SDK会话列表界面聚合会话的标题
@discussion 如果不设置此项会使用内置默认头像。
key: 聚合会话类型 RCConversationType
value: 聚合会话标题 NSString
*/
@property (nonatomic, strong) NSDictionary<NSNumber *, NSString *> *globalConversationCollectionTitleDic;
RCKitConfigCenter.ui.globalConversationCollectionTitleDic = @{
@(ConversationType_PRIVATE): @"自定义聚合标题"
};
属性 | 类型 | 说明 |
---|---|---|
globalConversationCollectionTitleDic | NSDictionary | 聚合显示的会话标题配置 |
key | NSNumber(RCConversationType) | 自定义的聚合会话类型 |
value | NSString | 自定义的聚合会话标题 |
自定义聚合会话头像
IMKit SDK 从 5.2.3 开始支持该功能。
IMKit 中聚合会话的头像统一使用融云默认头像。调用下面的方法可以自定义聚合条目的头像。
/*!
SDK会话列表界面聚合会话的头像
@discussion 如果不设置此项会使用内置默认头像。
key: 聚合会话类型 RCConversationType
value: 图片路径(支持本地路径或者远端url)
*/
@property (nonatomic, strong) NSDictionary<NSNumber *, NSString *> *globalConversationCollectionAvatarDic;
// 远端图片
RCKitConfigCenter.ui.globalConversationCollectionAvatarDic = @{
@(ConversationType_PRIVATE): @"http://example.pic"
};
// 本地图片
RCKitConfigCenter.ui.globalConversationCollectionAvatarDic = @{
@(ConversationType_PRIVATE): [[NSBundle mainBundle] pathForResource:@"example" ofType:@"png"]
};
属性 | 类型 | 说明 |
---|---|---|
globalConversationCollectionAvatarDic | NSDictionary | 聚合显示的会话头像配置 |
key | NSNumber(RCConversationType) | 自定义的聚合会话类型 |
value | NSString | 自定义的聚合会话的头像 uri |