按会话设置免打扰
单会话级别优先级最高,适合“这个群太吵,先静音”的场景。设置后保存到服务端,多端同步。
setConversationNotificationLevel
会话提醒级别:0 全部 / 1 仅提及 / 2 免打扰。
| 项 | 值 |
|---|---|
| Swift | func setConversationNotificationLevel(conversationType: IMPConversationType, targetId: String, level: IMPNotificationLevel) async -> RcResult<Void> |
| Objective-C | - (void)setConversationNotificationLevelWithConversationType:(NSInteger)conversationType targetId:(NSString *)targetId level:(NSInteger)level completion:(void (^)(IMPOSResult *result))completion |
| 传输 | REST(HTTP) |
| 幂等 | 是 |
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
conversationType | ConversationType | 是 | 会话类型枚举(ConversationType) |
targetId | string | 是 | 目标会话 ID:单聊为对方 userId,群聊为 groupId,聊天室为 chatroomId |
level | NotificationLevel | 是 | 字段含义见类型定义 |
返回
null:无返回数据;成功与否通过错误码判断
示例(Swift / Objective-C)
let res = await client.setConversationNotificationLevel(conversationType: .privateChat, targetId: "user2", level: .muted)
if res.code != 0 { print(res.msg ?? "") }[client setConversationNotificationLevelWithConversationType:1 /* 单聊 */ targetId:@"user2" level:2 /* 免打扰 */ completion:^(IMPOSResult *result) {
if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];错误码
| 错误码 | 名称 | 分类 | HTTP | 可重试 | 说明 |
|---|---|---|---|---|---|
1001 | INVALID_PARAMETER | 客户端 / 参数 / 权限 | 400 | 否 | 参数错误 |
1003 | FORBIDDEN | 客户端 / 参数 / 权限 | 403 | 否 | 无权限 |
读取当前级别
通过 `getConversation` / `getConversationList` 读取会话的 `notificationLevel` 字段,不需要额外请求。
let groupRes = await client.setConversationNotificationLevel(conversationType: .group, targetId: "g_1001", level: .muted)
if groupRes.code != 0 { print(groupRes.msg ?? "") }[client setConversationNotificationLevelWithConversationType:2 /* 群聊 */
targetId:@"g_1001"
level:2 /* 免打扰 */
completion:^(IMPOSResult *result) {
if (result.code != 0) {
NSLog(@"set level failed: %ld %@", (long)result.code, result.msg);
}
}];交互建议
- 会话列表长按 → 免打扰,提供“1 小时 / 8 小时 / 永久”时,前两者由客户端定时器到期后恢复(服务端只存最终级别)。
- 设置后立即更新本地读模型(乐观更新),失败时回滚并提示。
- 免打扰会话的角标不计入总数(见「角标」页),红点不展示。
- 多端同时修改时以最后一次写入为准,另一端通过 `CONVERSATION` 事件刷新。