跳到主要内容

获取未读消息数

IMLib SDK 支持您获取超级群下的未读消息数,具体可以获取的内容如下:

  • 当前用户加入的所有超级群、指定超级群、或指定频道的未读消息数。
  • 当前用户加入的所有超级群、指定超级群、或指定频道的未读 @ 消息数。
  • 按免打扰级别获取总未读消息数。
  • 返回的未读数最大值为 999,如果实际未读数超过 999,接口仍返回 999。
提示

IMLib SDK 仅在 ChannelClient 中提供相关接口的调用。

获取多个超级群的未读消息数

SDK 支持获取当前用户加入的所有超级群中未读消息数与未读 @ 消息数。

批量获取当前用户的超级群的未读消息数

提示

IMLib SDK 从 5.4.6 版本开始支持此功能。

在社群应用场景中,如果您需要实时显示用户所在的多个超级群下所有频道的最新未读消息数据,您可以使用 getUltraGroupConversationUnreadInfoList 一次获取最多 20 个超级群下所有频道的未读数据。具体包含:

  • 超级群频道的未读消息数
  • 超级群频道的未读 @ 消息数
  • 超级群频道中仅 @ 当前用户的未读 @ 消息数
  • 超级群频道的免打扰级别

接口原型

Objective C
- (void)getUltraGroupConversationUnreadInfoList:(nonnull NSArray<NSString *> *)targetIds
success:(nonnull void (^)(NSArray<RCConversationUnreadInfo *> *list))successBlock
error:(nonnull void (^)(RCErrorCode status))errorBlock;

参数说明

参数类型说明
targetIdsNSString超级群会话 targetId 的列表,最多 20 个。
successBlockBlock查询未读信息的成功的回调,返回 RCConversationUnreadInfo 数组,包含会话中的未读消息数量、@ 消息的总个数、@ 我的消息的个数、免打扰级别等参数。
errorBlockBlock查询消息数量失败的回调。

示例代码

Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupConversationUnreadInfoList:targetIds success:^(NSArray<RCConversationUnreadInfo *> * _Nonnull list) {
for (RCConversationUnreadInfo *info in list) {
NSString *content = [NSString stringWithFormat:@"%@ %@:%@,%@,%@,%@", info.targetId, info.channelId, @(info.unreadMessageCount), @(info.mentionedCount), @(info.mentionedMeCount), @(info.notificationLevel)];
NSLog(@"%@", content);
}
} error:^(RCErrorCode status) {
// TODO error code
}];

获取当前用户加入的所有超级群未读消息数总和

接口原型

Objective C
- (void)getUltraGroupAllUnreadCount:(void (^)(NSInteger count))successBlock
error:(void (^)(RCErrorCode status))errorBlock;

参数说明

参数类型说明

| successBlock | Block | 查询未读信息的成功的回调,返回未读消息的数量。 | | errorBlock | Block | 查询消息数量失败的回调。 |

示例代码

Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupAllUnreadCount:^(NSInteger count) {
} error:^(RCErrorCode status) {
}];

获取当前用户加入的所有超级群会话中的未读 @ 消息数的总和

接口原型

Objective C
- (void)getUltraGroupAllUnreadMentionedCount:(void (^)(NSInteger  count))successBlock
error:(void (^)(RCErrorCode status))errorBlock;

参数说明

参数类型说明

| successBlock | Block | 查询未读 @ 消息数量的成功的回调,返回未读 @ 消息的数量。 | | errorBlock | Block | 查询消息数量失败的回调。 |

示例代码

Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupAllUnreadMentionedCount:^(NSInteger count) {
} error:^(RCErrorCode status) {
}];

获取指定超级群或频道中的未读消息数和未读 @ 消息数

获取指定单个超级群下所有频道的未读消息数

Objective C
- (void)getUltraGroupUnreadCount:(NSString *)targetId
success:(void (^)(NSInteger count))successBlock
error:(void (^)(RCErrorCode status))errorBlock

参数说明

参数类型说明
targetIdNSString超级群 targetId。
successBlockBlock查询未读消息数量的成功的回调,返回未读消息的数量。
errorBlockBlock查询消息数量失败的回调。

示例代码

Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupUnreadCount:@"targetId" success:^(NSInteger count) {
} error:^(RCErrorCode status) {
}];

获取指定单个超级群的未读 @ 消息数

接口原型

Objective C
- (void)getUltraGroupUnreadMentionedCount:(NSString *)targetId
completion:(nullable void(^)(int num))completion;

参数说明

参数类型说明
targetIdNSString超级群 targetId。
completionBlock查询未读 @ 消息数量的回调。

示例代码

Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupUnreadMentionedCount:@"targetId" completion:^(int num) {

}];

获取超级群会话指定频道的未读消息数

Objective C
- (void)getUnreadCount:(RCConversationType)conversationType
targetId:(NSString *)targetId
channelId:(nullable NSString *)channelId
completion:(nullable void(^)(int num))completion;

参数说明

参数类型说明
conversationTypeRCConversationType会话类型。
targetIdNSString超级群 targetId。
channelIdNSString超级群 channelId。
completionBlock查询未读消息数量的回调。

示例代码

Objective C
[[RCChannelClient sharedChannelManager] getUnreadCount:ConversationType_ULTRAGROUP targetId:@"targetId" channelId:@"channelId" completion:^(int num) {

}];

获取指定频道的未读 @ 消息数

您可以可以直接从 RCConversation 对象上获取该频道未读 @ 消息数。

  • mentionedCount:当前频道中 “@所有人”与“@当前用户”的未读消息数之和。
  • mentionedMeCount:当前频道中 “@当前用户”的未读消息数。要求 SDK 版本 ≧ 5.4.5。

具体示例可参见获取频道列表

按免打扰级别获取超级群的总未读消息数

提示

SDK 从 5.2.5 版本开始支持该接口。仅在 RCChannelClient 中提供。

您可以获取已设置指定免打扰级别的会话及频道的总未读消息数。IMLib SDK 将按照传入的免打扰级别配置查找,再返回该会话下符合设置的频道的总未读消息数。

接口原型

Objective C
- (void)getUltraGroupUnreadCount:(nonnull NSString *)targetId
levels:(nonnull NSArray <NSNumber*>*)levels
success:(nullable void (^)(NSInteger count))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

参数说明

参数类型必填
targetIdNSString超级群会话 targetId。
levelsRCPushNotificationLevel[]免打扰类型数组。详见免打扰功能概述
successBlockBlock成功回调,返回未读消息数。
errorBlockBlock失败回调。

示例代码

Objective C
NSArray * pushNotificationLevels = @[@(RCPushNotificationLevelMention)];
[[RCChannelClient sharedChannelManager] getUltraGroupUnreadCount:targetId
levels: pushNotificationLevels
success:^(NSInteger unReadCount) {}
error:^(RCErrorCode status) {}];

按免打扰级别获取超级群的总未读 @ 消息数

提示

SDK 从 5.2.5 版本开始支持该接口。仅在 RCChannelClient 中提供。

您可以获取已设置指定免打扰级别的会话及频道的总未读 @ 消息数。IMLib SDK 将按照传入的免打扰级别配置查找,再返回该会话下符合设置的频道的总未读 @ 消息数。

接口原型

Objective C
- (void)getUltraGroupUnreadMentionedCount:(nonnull NSString *)targetId
levels:(nonnull NSArray <NSNumber*>*)levels
success:(nullable void (^)(NSInteger count))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

参数说明

参数类型必填
targetIdNSString超级群会话 targetId。
levelsRCPushNotificationLevel[]免打扰类型数组。详见免打扰功能概述
successBlockBlock成功回调,返回未读消息数。
errorBlockBlock失败回调。

示例代码

Objective C
NSArray * pushNotificationLevels = @[@(RCPushNotificationLevelMention)];
[[RCChannelClient sharedChannelManager] getUltraGroupUnreadMentionedCount:targetId
levels: pushNotificationLevels
success:^(NSInteger unReadCount) {}
error:^(RCErrorCode status) {}];

如果您希望获取多个类型会话的未读消息总数,可参见处理会话未读消息数中介绍的方法。