会话盒子
会话盒子介绍
会话盒子指拥有共同性质的一类会话的合集,由会话设置属性boxType
确定,可将相同类型的会话聚合为一类列表,减少主列表消息干扰。
获取会话盒子列表
接口定义
swift
func getBoxList() -> [KIMBoxInfo]
Objective-C
- (NSArray<KIMBoxInfo *> *)getBoxList;
参数说明
KIMBoxInfo
说明
属性 | 类型 | 说明 |
---|---|---|
type | Int | 盒子类型, KIMChatBoxType 枚举值。 0: none 2: 消息助手 |
name | String | 盒子名称 |
avatar | String | 盒子头像 |
lastReadTime | Int64 | 最新已读时间 ns |
setting | Setting | 相关设置 |
bizInfo | String | 业务相关信息 |
Setting
说明
属性 | 类型 | 说明 |
---|---|---|
stickied | Bool | 是否置顶 |
代码示例
swift
let list = KIMCore.shared.getBoxList()
获取指定盒子类型的会话列表
如果需要获取指定会话盒子类型下的会话列表,可以通过获取会话列表,然后再筛选对应的 boxType
得到。
代码示例
swift
let boxType = KIMBoxType.assistant.rawValue
let boxChatList = KIMCore.shared.getChatList().filter({ $0.settings.boxType == boxType })
获取指定类型会话盒子未读数
如果需要获取指定类型会话盒子未读数,可以通过获取会话列表筛选出指定盒子类型的会话,然后通过 unreadCount
属性计算出总的未读数。
代码示例
swift
let boxType = KIMBoxType.assistant.rawValue
let boxChatList = KIMCore.shared.getChatList().filter({ $0.settings.boxType == boxType })
let totalUnread = boxChatList.reduce(0, { $0+$1.unreadCount })
清除指定类型会话盒子未读数
接口定义
swift
func clearBoxUnread(type: Int, complete: ((_ success: Bool, _ error: KIMError?) -> Void)?)
Objective-C
- (void)clearBoxUnreadWithType:(NSInteger)type complete:(void (^ _Nullable)(BOOL, KIMError * _Nullable))complete;
参数说明
参数 | 类型 | 说明 |
---|---|---|
type | Int | 盒子类型, KIMChatBoxType 枚举值。 0: none 2: 消息助手 |
complete | (_ success: Bool, _ error: KIMError?) -> Void)? | 完成回调,success:是否操作成功;error:错误信息 |
代码示例
swift
KIMCore.shared.clearBoxUnread(type: type) { success, error in
}
操作会话盒子
接口定义
swift
func setBox(type: Int, action: String, complete: ((_ success: Bool, _ error: KIMError?) -> Void)?)
Objective-C
- (void)setBoxWithType:(NSInteger)type action:(NSString *)action complete:(void (^ _Nullable)(BOOL, KIMError * _Nullable))complete;
参数说明
参数 | 类型 | 说明 |
---|---|---|
type | Int | 盒子类型, KIMChatBoxType 枚举值。 0: none 2: 消息助手 |
action | String | 类型操作, KIMBoxAction 枚举值。 sticky:置顶 unsticky:取消置顶 |
complete | (_ success: Bool, _ error: KIMError?) -> Void)? | 完成回调。 success:是否操作成功 error:错误信息 |
代码示例
swift
KIMCore.shared.setBox(type: type, action: action) { success, error in
}
监听会话盒子变化
可以通过注册监听会话列表代理 KIMChatListDelegate
来监听会话盒子变化。
接口定义
swift
func register(chatListDelegate: KIMChatListDelegate)
Objective-C
- (void)registerWithChatListDelegate:(id <KIMChatListDelegate> _Nonnull)chatListDelegate;
参数说明
参数 | 类型 | 说明 |
---|---|---|
chatListDelegate | KIMChatListDelegate | 监听代理 |
KIMChatListDelegate
说明:
方法 | 参数 | 返回值 | 说明 |
---|---|---|---|
didUpdateBoxList | list: [KIMBoxInfo] 会话盒子列表, finish: Bool 是否完成 | Void | 更新聚合类型回调 |
代码示例
swift
KIMCore.shared.register(chatListDelegate: self)