聊天室服务
更新时间: 2024/08/22 17:09:53
NetEase IM SDK(以下简称 NIM SDK)提供聊天室服务,支持用户收发聊天室消息、管理聊天室成员、维护聊天室信息。
本文介绍聊天室服务相关 API。更多聊天室相关功能请参考开发指南文档聊天室概述。
支持平台
Android | iOS | macOS/Windows | Web/uni-app/小程序 | HarmonyOS |
---|---|---|---|---|
✓ | ✓ | ✓ | ✓ | ✓ |
API 概览
聊天室监听
API | 描述 | 起始版本 |
---|---|---|
addChatroomListener | 注册聊天室监听器 | v10.2.0 |
removeChatroomListener | 移除聊天室监听器 | v10.2.0 |
API | 描述 | 起始版本 |
---|---|---|
on("EventName") | 注册聊天室监听 | v10.2.0(对应 HarmonyOS v1.0.0) |
off("EventName") | 取消注册聊天室监听 | v10.2.0(对应 HarmonyOS v1.0.0) |
聊天室消息
API | 描述 | 起始版本 |
---|---|---|
sendMessage | 发送聊天室消息 | v10.2.0(对应 HarmonyOS v1.0.0) |
cancelMessageAttachmentUpload | 取消文件类附件上传 | v10.2.0(对应 HarmonyOS v1.0.0) |
getMessageList | 分页获取聊天室历史消息 | v10.2.0(对应 HarmonyOS v1.0.0) |
getMessageListByTag | 根据标签分页获取聊天室消息列表 | v10.2.0(对应 HarmonyOS v1.0.0) |
聊天室成员
API | 描述 | 起始版本 |
---|---|---|
kickMember | 将成员踢出聊天室 | v10.2.0(对应 HarmonyOS v1.0.0) |
getMemberListByOption | 分页获取聊天室成员列表 | v10.2.0(对应 HarmonyOS v1.0.0) |
getMemberByIds | 批量获取聊天室成员列表 | v10.2.0(对应 HarmonyOS v1.0.0) |
getMemberListByTag | 根据标签分页获取聊天室成员列表 | v10.2.0(对应 HarmonyOS v1.0.0) |
getMemberCountByTag | 根据标签获取聊天室成员数量 | v10.2.0(对应 HarmonyOS v1.0.0) |
updateMemberRole | 更新聊天室成员角色 | v10.2.0(对应 HarmonyOS v1.0.0) |
setMemberBlockedStatus | 设置聊天室成员黑名单状态 | v10.2.0(对应 HarmonyOS v1.0.0) |
setMemberChatBannedStatus | 设置聊天室成员禁言状态 | v10.2.0(对应 HarmonyOS v1.0.0) |
setMemberTempChatBanned | 设置聊天室成员临时禁言状态 | v10.2.0(对应 HarmonyOS v1.0.0) |
setTempChatBannedByTag | 设置指定标签下的聊天室成员临时禁言状态 | v10.2.0(对应 HarmonyOS v1.0.0) |
updateSelfMemberInfo | 更新本人的聊天室成员信息 | v10.2.0(对应 HarmonyOS v1.0.0) |
聊天室信息
API | 描述 | 起始版本 |
---|---|---|
updateChatroomInfo | 更新聊天室信息 | v10.2.0(对应 HarmonyOS v1.0.0) |
updateChatroomLocationInfo | 更新聊天室空间坐标信息 | v10.2.0(对应 HarmonyOS v1.0.0) |
updateChatroomTags | 更新聊天室标签信息 | v10.2.0(对应 HarmonyOS v1.0.0) |
接口类
V2NIMChatroomService
类提供聊天室服务接口,包括注册/注销聊天室监听器、收发聊天室消息、管理聊天室成员、维护聊天室信息等。
使用前提
在使用 V2NIMChatroomService
类中的 API 前,需要先调用 V2NIMChatroomClient#getChatroomService
方法获取 V2NIMChatroomService
类。
addChatroomListener
接口描述
注册聊天室监听器。
注册成功后,当事件发生时,SDK 会返回对应的回调。
-
建议在初始化后调用该方法。
-
全局只需注册一次。
-
该方法为同步。
参数说明
javavoid addChatroomListener(V2NIMChatroomListener listener);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
listener |
V2NIMChatroomListener |
是 | - | 聊天室监听器 |
objective-c- (void)addChatroomListener:(id<V2NIMChatroomListener>)listener;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
listener |
V2NIMChatroomListener |
是 | - | 聊天室监听器 |
cppvirtual void addChatroomListener(V2NIMChatroomListener listener) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
listener |
V2NIMChatroomListener |
是 | - | 聊天室监听器 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomListener listener = new V2NIMChatroomListener() {
@Override
public void onSendMessage(V2NIMChatroomMessage message);
}
@Override
public void onReceiveMessages(List<V2NIMChatroomMessage> messages) {
}
@Override
public void onChatroomMemberEnter(V2NIMChatroomMember member) {
}
@Override
public void onChatroomMemberExit(String accountId) {
}
@Override
public void onChatroomMemberRoleUpdated(V2NIMChatroomMemberRole previousRole, V2NIMChatroomMember member) {
}
@Override
public void onChatroomMemberInfoUpdated(V2NIMChatroomMember member) {
}
@Override
public void onSelfChatBannedUpdated(boolean chatBanned) {
}
@Override
public void onSelfTempChatBannedUpdated(boolean tempChatBanned, long tempChatBannedDuration) {
}
@Override
public void onChatroomInfoUpdated(V2NIMChatroomInfo chatroom) {
}
@Override
public void onChatroomChatBannedUpdated(boolean chatBanned) {
}
@Override
public void onMessageRevokedNotification(String messageClientId, long messageTime) {
}
@Override
public void onChatroomTagsUpdated(List<String> tags) {
}
};
v2ChatroomService.addChatroomListener(listener);
objective-c@interface Listener: NSObject<V2NIMChatroomListener>
- (void)addToService;
@end
@implementation Listener
- (void)addToService
{
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
[service addChatroomListener:self];
}
- (void)onSendMessage:(V2NIMChatroomMessage *)message;
{
}
- (void)onReceiveMessages:(NSArray *)messages
{
}
- (void)onChatroomMemberEnter:(V2NIMChatroomMember *)member
{
}
- (void)onChatroomMemberExit:(NSString *)accountId
{
}
- (void)onChatroomMemberRoleUpdated:(V2NIMChatroomMemberRole)previousRole
member:(V2NIMChatroomMember *)member
{
}
- (void)onChatroomMemberInfoUpdated:(V2NIMChatroomMember *)member
{
}
- (void)onSelfChatBannedUpdated:(BOOL)chatBanned
{
}
- (void)onSelfTempChatBannedUpdated:(BOOL)tempChatBanned
tempChatBannedDuration:(NSInteger)tempChatBannedDuration
{
}
- (void)onChatroomInfoUpdated:(V2NIMChatroomInfo *)chatroomInfo
{
}
- (void)onChatroomChatBannedUpdated:(BOOL)chatBanned
{
}
- (void)onMessageRevokedNotification:(NSString *)messageClientId
messageTime:(NSTimeInterval)messageTime
{
}
- (void)onChatroomTagsUpdated:(NSArray<NSString *> *)tags
{
}
@end
cppV2NIMChatroomListener listener;
listener.onReceiveMessages = [](nstd::vector<V2NIMChatroomMessage> messages) {
// handle receive messages
};
listener.onChatroomMemberEnter = [](V2NIMChatroomMember member) {
// handle chatroom member enter
};
listener.onChatroomMemberExit = [](nstd::string accountId) {
// handle chatroom member exit
};
listener.onChatroomMemberRoleUpdated = [](V2NIMChatroomMemberRole previousRole, V2NIMChatroomMember member) {
// handle chatroom member role updated
};
listener.onChatroomMemberInfoUpdated = [](V2NIMChatroomMember member) {
// handle chatroom member info updated
};
listener.onSelfChatBannedUpdated = [](bool chatBanned) {
// handle self chat banned updated
};
listener.onSelfTempChatBannedUpdated = [](bool tempChatBanned, uint64_t tempChatBannedDuration) {
// handle self temp chat banned updated
};
listener.onChatroomInfoUpdated = [](V2NIMChatroomInfo chatroomInfo) {
// handle chatroom info updated
};
listener.onChatroomChatBannedUpdated = [](bool chatBanned) {
// handle chatroom chat banned updated
};
listener.onMessageRevokedNotification = [](nstd::string messageClientId, uint64_t messageTime) {
// handle message revoked notification
};
listener.onChatroomTagsUpdated = [](nstd::vector<nstd::string> tags) {
// handle chatroom tags updated
};
chatroomService.addChatroomListener(listener);
返回值
无
removeChatroomListener
接口描述
移除聊天室实例监听器。
该方法为同步。
参数说明
javavoid removeChatroomListener(V2NIMChatroomListener listener);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
listener |
V2NIMChatroomListener |
是 | - | 聊天室监听器 |
objective-c- (void)removeChatroomListener:(id<V2NIMChatroomListener>)listener;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
listener |
V2NIMChatroomListener |
是 | - | 聊天室监听器 |
cppvirtual void removeChatroomListener(V2NIMChatroomListener listener) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
listener |
V2NIMChatroomListener |
是 | - | 聊天室监听器 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
v2ChatroomService.removeChatroomListener(listener);
objective-c@interface Listener: NSObject<V2NIMChatroomListener>
- (void)addToService;
- (void)removeFromService;
@end
@implementation Listener
- (void)addToService
{
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
[service addChatroomListener:self];
}
- (void)removeFromService
{
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
[service removeChatroomListener:self];
}
- (void)onReceiveMessages:(NSArray *)messages
{
}
@end
cppV2NIMChatroomListener listener;
// ...
chatroomService.addChatroomListener(listener);
// ...
chatroomService.removeChatroomListener(listener);
返回值
无
on("EventName")
接口描述
注册聊天室监听。
注册成功后,当事件发生时,SDK 会返回对应的回调。
-
建议在初始化后调用该方法。
-
全局只需注册一次。
-
该方法为同步。
参数说明
typescriptexport interface NIMEBaseServiceInterface<I extends NIMEBaseListener> {
/**
* 继承自 EventEmitter3 的监听事件方法。
*/
on<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void;
/**
* 继承自 EventEmitter3 的监听事件方法。
*/
once<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void;
}
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
eventName |
T | 是 | - | 事件名称:onSendMessage :本端发送聊天室消息状态回调,本端发送聊天室消息或插入聊天室消息成功后,SDK 会返回该回调。onReceiveMessages :聊天室消息接收回调。本端接收到消息,或其他端同步的消息时会触发该回调。onChatroomInfoUpdated :聊天室资料信息更新回调。聊天室内所有成员均会收到该回调。onChatroomMemberEnter :成员进入聊天室回调。聊天室内所有成员均会收到该回调。onChatroomMemberExit :成员退出聊天室回调。当成员退出或被踢出聊天室,聊天室内所有成员均会收到该回调。onChatroomMemberRoleUpdated :聊天室成员角色类型变更回调。聊天室内所有成员均会收到该回调。onChatroomMemberInfoUpdated :聊天室成员信息变更回调。聊天室内所有成员均会收到该回调。onSelfChatBannedUpdated :聊天室成员本人禁言状态变更回调。onSelfTempChatBannedUpdated :聊天室成员本人临时禁言状态变更回调。onChatroomChatBannedUpdated :聊天室整体禁言状态变更回调。onMessageRevokedNotification :聊天室消息撤回回调。onChatroomTagsUpdated :聊天室标签信息变更回调。 |
fn |
function | 是 | - | 监听事件的回调函数。当事件触发时,会调用该函数进行处理。 |
typescriptexport interface NIMEBaseServiceInterface<I extends NIMEBaseListener> {
/**
* 继承自 eventEmitter3 的监听事件方法
*/
on<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void
/**
* 继承自 eventEmitter3 的监听事件方法
*/
once<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void
}
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
eventName |
T | 是 | - | 事件名称:onSendMessage :本端发送聊天室消息状态回调,本端发送聊天室消息或插入聊天室消息成功后,SDK 会返回该回调。onReceiveMessages :聊天室消息接收回调。本端接收到消息,或其他端同步的消息时会触发该回调。onChatroomInfoUpdated :聊天室资料信息更新回调。聊天室内所有成员均会收到该回调。onChatroomMemberEnter :成员进入聊天室回调。聊天室内所有成员均会收到该回调。onChatroomMemberExit :成员退出聊天室回调。当成员退出或被踢出聊天室,聊天室内所有成员均会收到该回调。onChatroomMemberRoleUpdated :聊天室成员角色类型变更回调。聊天室内所有成员均会收到该回调。onChatroomMemberInfoUpdated :聊天室成员信息变更回调。聊天室内所有成员均会收到该回调。onSelfChatBannedUpdated :聊天室成员本人禁言状态变更回调。onSelfTempChatBannedUpdated :聊天室成员本人临时禁言状态变更回调。onChatroomChatBannedUpdated :聊天室整体禁言状态变更回调。onMessageRevokedNotification :聊天室消息撤回回调。onChatroomTagsUpdated :聊天室标签信息变更回调。 |
fn |
function | 是 | - | 监听事件的回调函数。当事件触发时,会调用该函数进行处理。 |
示例代码
typescriptchatroom.V2NIMChatroomService.on('onSendMessage', function (message: V2NIMChatroomMessage){})
chatroom.V2NIMChatroomService.on('onReceiveMessages', function (messages: V2NIMChatroomMessage[]){})
chatroom.V2NIMChatroomService.on('onMessageRevokedNotification', function (messageClientId: string, messageTime: number){})
chatroom.V2NIMChatroomService.on('onChatroomMemberEnter', function (member: V2NIMChatroomMember){})
chatroom.V2NIMChatroomService.on('onChatroomMemberExit', function (accountId: string){})
chatroom.V2NIMChatroomService.on('onChatroomMemberRoleUpdated', function (previousRole: V2NIMChatroomMemberRole, currentMember: V2NIMChatroomMember){})
chatroom.V2NIMChatroomService.on('onChatroomMemberInfoUpdated', function (member: V2NIMChatroomMember){})
chatroom.V2NIMChatroomService.on('onSelfChatBannedUpdated', function (chatBanned: boolean){})
chatroom.V2NIMChatroomService.on('onSelfTempChatBannedUpdated', function (tempChatBanned: boolean, tempChatBannedDuration: number){})
chatroom.V2NIMChatroomService.on('onChatroomInfoUpdated', function (chatroomInfo: V2NIMChatroomInfo){})
chatroom.V2NIMChatroomService.on('onChatroomChatBannedUpdated', function (chatBanned: boolean){})
chatroom.V2NIMChatroomService.on('onChatroomTagsUpdated', function (tags: Array<string>){})
typescriptchatroom.chatroomService.on('onReceiveMessages', (messages: V2NIMChatroomMessage[]) => {})
chatroom.chatroomService.on('onMessageRevokedNotification', (messageClientId: string, messageTime: number) => {})
chatroom.chatroomService.on('onChatroomMemberEnter', (member: V2NIMChatroomMember) => {})
chatroom.chatroomService.on('onChatroomMemberExit', (accountId: string) => {})
chatroom.chatroomService.on('onChatroomMemberRoleUpdated', (previousRole: V2NIMChatroomMemberRole, currentMember: V2NIMChatroomMember) => {})
chatroom.chatroomService.on('onChatroomMemberInfoUpdated', (member: V2NIMChatroomMember) => {})
chatroom.chatroomService.on('onSelfChatBannedUpdated', (chatBanned: boolean) => {})
chatroom.chatroomService.on('onSelfTempChatBannedUpdated', (tempChatBanned: boolean, tempChatBannedDuration: number) => {})
chatroom.chatroomService.on('onChatroomInfoUpdated', (chatroomInfo: V2NIMChatroomInfo) => {})
chatroom.chatroomService.on('onChatroomChatBannedUpdated', (chatBanned: boolean) => {})
chatroom.chatroomService.on('onChatroomTagsUpdated', (tags: Array<string>) => {})
返回值
无
off("EventName")
接口描述
取消注册聊天室监听。
该方法为同步。
参数说明
typescriptexport interface NIMEBaseServiceInterface<I extends NIMEBaseListener> {
/**
* 继承自 EventEmitter3 的取消监听方法。
*/
off<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void;
/**
* 继承自 EventEmitter3 的移除事件方法。
*/
removeAllListeners<T extends keyof I>(eventName?: T): void;
}
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
eventName |
T | 是 | - | 事件名称:onSendMessage :本端发送聊天室消息状态回调,本端发送聊天室消息或插入聊天室消息成功后,SDK 会返回该回调。onReceiveMessages :聊天室消息接收回调。本端接收到消息,或其他端同步的消息时会触发该回调。onChatroomInfoUpdated :聊天室资料信息更新回调。聊天室内所有成员均会收到该回调。onChatroomMemberEnter :成员进入聊天室回调。聊天室内所有成员均会收到该回调。onChatroomMemberExit :成员退出聊天室回调。当成员退出或被踢出聊天室,聊天室内所有成员均会收到该回调。onChatroomMemberRoleUpdated :聊天室成员角色类型变更回调。聊天室内所有成员均会收到该回调。onChatroomMemberInfoUpdated :聊天室成员信息变更回调。聊天室内所有成员均会收到该回调。onSelfChatBannedUpdated :聊天室成员本人禁言状态变更回调。onSelfTempChatBannedUpdated :聊天室成员本人临时禁言状态变更回调。onChatroomChatBannedUpdated :聊天室整体禁言状态变更回调。onMessageRevokedNotification :聊天室消息撤回回调。onChatroomTagsUpdated :聊天室标签信息变更回调。 |
fn |
function | 是 | - | 监听事件的回调函数。当事件触发时,会调用该函数进行处理。 |
typescriptexport interface NIMEBaseServiceInterface<I extends NIMEBaseListener> {
/**
* 继承自 eventEmitter3 的取消监听方法
*/
off<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void
/**
* 继承自 eventEmitter3 的移除事件方法
*/
removeAllListeners<T extends keyof I>(eventName?: T): void
}
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
eventName |
T | 是 | - | 事件名称:onSendMessage :本端发送聊天室消息状态回调,本端发送聊天室消息或插入聊天室消息成功后,SDK 会返回该回调。onReceiveMessages :聊天室消息接收回调。本端接收到消息,或其他端同步的消息时会触发该回调。onChatroomInfoUpdated :聊天室资料信息更新回调。聊天室内所有成员均会收到该回调。onChatroomMemberEnter :成员进入聊天室回调。聊天室内所有成员均会收到该回调。onChatroomMemberExit :成员退出聊天室回调。当成员退出或被踢出聊天室,聊天室内所有成员均会收到该回调。onChatroomMemberRoleUpdated :聊天室成员角色类型变更回调。聊天室内所有成员均会收到该回调。onChatroomMemberInfoUpdated :聊天室成员信息变更回调。聊天室内所有成员均会收到该回调。onSelfChatBannedUpdated :聊天室成员本人禁言状态变更回调。onSelfTempChatBannedUpdated :聊天室成员本人临时禁言状态变更回调。onChatroomChatBannedUpdated :聊天室整体禁言状态变更回调。onMessageRevokedNotification :聊天室消息撤回回调。onChatroomTagsUpdated :聊天室标签信息变更回调。 |
fn |
function | 是 | - | 监听事件的回调函数。当事件触发时,会调用该函数进行处理。 |
示例代码
typescriptchatroom.V2NIMChatroomService.off('onSendMessage', function (message: V2NIMChatroomMessage){})
chatroom.V2NIMChatroomService.off('onReceiveMessages', function (messages: V2NIMChatroomMessage[]){})
chatroom.V2NIMChatroomService.off('onMessageRevokedNotification', function (messageClientId: string, messageTime: number){})
chatroom.V2NIMChatroomService.off('onChatroomMemberEnter', function (member: V2NIMChatroomMember){})
chatroom.V2NIMChatroomService.off('onChatroomMemberExit', function (accountId: string){})
chatroom.V2NIMChatroomService.off('onChatroomMemberRoleUpdated', function (previousRole: V2NIMChatroomMemberRole, currentMember: V2NIMChatroomMember){})
chatroom.V2NIMChatroomService.off('onChatroomMemberInfoUpdated', function (member: V2NIMChatroomMember){})
chatroom.V2NIMChatroomService.off('onSelfChatBannedUpdated', function (chatBanned: boolean){})
chatroom.V2NIMChatroomService.off('onSelfTempChatBannedUpdated', function (tempChatBanned: boolean, tempChatBannedDuration: number){})
chatroom.V2NIMChatroomService.off('onChatroomInfoUpdated', function (chatroomInfo: V2NIMChatroomInfo){})
chatroom.V2NIMChatroomService.off('onChatroomChatBannedUpdated', function (chatBanned: boolean){})
chatroom.V2NIMChatroomService.off('onChatroomTagsUpdated', function (tags: Array<string>){})
typescriptchatroom.chatroomService.off('onReceiveMessages', (messages: V2NIMChatroomMessage[]) => {})
chatroom.chatroomService.off('onMessageRevokedNotification', (messageClientId: string, messageTime: number) => {})
chatroom.chatroomService.off('onChatroomMemberEnter', (member: V2NIMChatroomMember) => {})
chatroom.chatroomService.off('onChatroomMemberExit', (accountId: string) => {})
chatroom.chatroomService.off('onChatroomMemberRoleUpdated', (previousRole: V2NIMChatroomMemberRole, currentMember: V2NIMChatroomMember) => {})
chatroom.chatroomService.off('onChatroomMemberInfoUpdated', (member: V2NIMChatroomMember) => {})
chatroom.chatroomService.off('onSelfChatBannedUpdated', (chatBanned: boolean) => {})
chatroom.chatroomService.off('onSelfTempChatBannedUpdated', (tempChatBanned: boolean, tempChatBannedDuration: number) => {})
chatroom.chatroomService.off('onChatroomInfoUpdated', (chatroomInfo: V2NIMChatroomInfo) => {})
chatroom.chatroomService.off('onChatroomChatBannedUpdated', (chatBanned: boolean) => {})
chatroom.chatroomService.off('onChatroomTagsUpdated', (tags: Array<string>) => {})
返回值
无
sendMessage
接口描述
发送一条聊天室消息。
本端发送消息成功后,聊天室内所有成员会收到消息接收回调 onReceiveMessages
。
- 发送消息前,请先调用
V2NIMChatroomMessageCreator
中的接口创建不同类型的聊天室消息。 - 如因网络等问题导致消息发送失败,可再次调用该方法重发消息。
参数说明
javavoid sendMessage(V2NIMChatroomMessage message, V2NIMSendChatroomMessageParams params, V2NIMSuccessCallback<V2NIMSendChatroomMessageResult> success,
V2NIMFailureCallback failure,
V2NIMProgressCallback progress);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 聊天室消息对象,通过调用 V2NIMChatroomMessageCreator 中的接口创建。如果为空或不存在则返回 191004 参数错误。 |
params |
V2NIMSendChatroomMessageParams |
否 | null | 聊天室消息发送配置参数,包括发送、抄送、反垃圾、标签、空间位置等配置。 |
success |
V2NIMSuccessCallback |
是 | - | 消息发送成功回调,返回 V2NIMSendChatroomMessageResult 。 |
failure |
V2NIMFailureCallback |
是 | - | 消息发送失败回调,返回错误码。 |
progress |
V2NIMProgressCallback |
否 | null | 附件上传进度回调,用于图片、语音、视频、文件类型消息。 |
objective-c- (void)sendMessage:(V2NIMChatroomMessage *)message
params:(V2NIMSendChatroomMessageParams*)params
success:(nullable V2NIMSendChatroomMessageSuccess)success
failure:(nullable V2NIMFailureCallback)failure
progress:(nullable V2NIMProgressCallback)progress;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 聊天室消息对象,通过调用 V2NIMChatroomMessageCreator 中的接口创建。如果为空或不存在则返回 191004 参数错误。 |
params |
V2NIMSendChatroomMessageParams |
- | null | 聊天室消息发送配置参数,包括发送、抄送、反垃圾、标签、空间位置等配置。 |
success |
V2NIMSendChatroomMessageSuccess |
是 | - | 消息发送成功回调,可自定义设置。 |
failure |
V2NIMFailureCallback |
是 | - | 消息发送失败回调,返回错误码。 |
progress |
V2NIMProgressCallback |
否 | null | 附件上传进度回调,用于图片、语音、视频、文件类型消息。 |
cppvirtual void sendMessage(V2NIMChatroomMessage message,
V2NIMSendChatroomMessageParams params,
V2NIMSuccessCallback<V2NIMSendChatroomMessageResult> success,
V2NIMFailureCallback failure,
V2NIMProgressCallback progress) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 聊天室消息对象,通过调用 V2NIMChatroomMessageCreator 中的接口创建。如果为空或不存在则返回 191004 参数错误。 |
params |
V2NIMSendChatroomMessageParams |
否 | null | 聊天室消息发送配置参数,包括发送、抄送、反垃圾、标签、空间位置等配置。 |
success |
V2NIMSuccessCallback |
是 | - | 消息发送成功回调,返回 V2NIMSendChatroomMessageResult 。 |
failure |
V2NIMFailureCallback |
是 | - | 消息发送失败回调,返回错误码。 |
progress |
V2NIMProgressCallback |
否 | null | 附件上传进度回调,用于图片、语音、视频、文件类型消息。 |
typescriptsendMessage(
message: V2NIMChatroomMessage,
params?: V2NIMSendChatroomMessageParams,
progress?: (percentage: number) => void
): Promise<V2NIMSendChatroomMessageResult>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 聊天室消息对象,通过调用 V2NIMChatroomMessageCreator 中的接口创建。如果为空或不存在则返回 191004 参数错误。 |
params |
V2NIMSendChatroomMessageParams |
否 | null | 聊天室消息发送配置参数,包括发送、抄送、反垃圾、标签、空间位置等配置。 |
progress |
number | 否 | null | 附件上传进度(百分比),用于图片、语音、视频、文件类型消息。 |
typescriptsendMessage(
message: V2NIMChatroomMessage,
params?: V2NIMSendChatroomMessageParams,
progress?: (percentage: number) => void
): Promise<V2NIMSendChatroomMessageResult>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 聊天室消息对象,通过调用 V2NIMChatroomMessageCreator 中的接口创建。如果为空或不存在则返回 191004 参数错误。 |
params |
V2NIMSendChatroomMessageParams |
否 | null | 聊天室消息发送配置参数,包括发送、抄送、反垃圾、标签、空间位置等配置。 |
progress |
number | 否 | null | 附件上传进度(百分比),用于图片、语音、视频、文件类型消息。 |
示例代码
java// 新建一个聊天室实例,注意:每次 newInstance 都会返回一个新的实例,实际使用中请一个聊天室对应一个V2NIMChatroomClient实例,使用中需要临时缓存
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.newInstance();
// 获取聊天室服务
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 创建一条文本消息
V2NIMChatroomMessage v2Message = V2NIMChatroomMessageCreator.createTextMessage("xxx");
V2NIMChatroomMessageConfig messageConfig = new V2NIMChatroomMessageConfig();
// 根据实际情况配置
// 设置是否需要在服务端保存历史消息,默认true
// messageConfig.setHistoryEnabled(true);
// 设置是否是高优先级消息,默认false
// messageConfig.setHighPriority(false);
V2NIMMessageRouteConfig routeConfig = V2NIMMessageRouteConfig.V2NIMMessageRouteConfigBuilder.builder()
// 根据实际情况配置
// .withRouteEnabled()
// .withRouteEnvironment()
.build();
V2NIMMessageAntispamConfig antispamConfig = V2NIMMessageAntispamConfig.V2NIMMessageAntispamConfigBuilder.builder()
// 根据实际情况配置
// .withAntispamBusinessId()
// .withAntispamCheating()
// .withAntispamCustomMessage()
// .withAntispamEnabled()
// .withAntispamExtension()
.build();
V2NIMSendChatroomMessageParams params = new V2NIMSendChatroomMessageParams();
// 设置消息相关配置
// params.setMessageConfig(messageConfig);
// 设置路由抄送相关配置
// params.setRouteConfig(routeConfig);
// 设置反垃圾相关配置
// params.setAntispamConfig(antispamConfig);
// 是否开启本地反垃圾,默认false
// params.setClientAntispamEnabled(false);
// 本地反垃圾的替换文本
// params.setClientAntispamReplace("xxx");
//设置聊天室定向消息接收者账号ID列表
// params.setReceiverIds(receiverIds);
// 设置消息的目标标签表达式
// params.setNotifyTargetTags("xxx");
// 设置位置信息
// params.setLocationInfo(locationInfo);
v2ChatroomService.sendMessage(v2Message,params,
new V2NIMSuccessCallback<V2NIMSendChatroomMessageResult>() {
@Override
public void onSuccess(V2NIMSendChatroomMessageResult result) {
// 发送成功
}
},
new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 发送失败
}
},
new V2NIMProgressCallback() {
@Override
public void onProgress(int progress) {
// 发送进度
}
});
objective-c// 通过实例 ID 获取聊天室服务
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:instanceId] getChatroomService];
// 创建一条文本消息
V2NIMChatroomMessage *message = [V2NIMChatroomMessageCreator createTextMessage:@"xxx"];
V2NIMChatroomMessageConfig *messageConfig = [V2NIMChatroomMessageConfig new];
// 根据实际情况配置
// 设置是否需要在服务端保存历史消息,默认 true
// messageConfig.historyEnabled = YES;
// 设置是否是高优先级消息,默认 false
// messageConfig.highPriority = NO;
V2NIMMessageRouteConfig *routeConfig = [V2NIMMessageRouteConfig new];
// 根据实际情况配置
// routeConfig.routeEnabled
// routeConfig.routeEnvironment
V2NIMMessageAntispamConfig *antispamConfig = [V2NIMMessageAntispamConfig new];
// 根据实际情况配置
// antispamConfig.antispamBusinessId
// antispamConfig.antispamCheating
// antispamConfig.antispamCustomMessage
// antispamConfig.antispamEnabled
// antispamConfig.antispamExtension
V2NIMSendChatroomMessageParams *params = [V2NIMSendChatroomMessageParams new];
// 设置消息相关配置
// params.messageConfig = messageConfig;
// 设置路由抄送相关配置
// params.routeConfig = routeConfig;
// 设置反垃圾相关配置
// params.antispamConfig = antispamConfig;
// 是否开启本地反垃圾,默认false
// params.clientAntispamEnabled = false;
// 本地反垃圾的替换文本
// params.clientAntispamReplace = @"xxx";
// 设置聊天室定向消息接收者账号ID列表
// params.receiverIds = receiverIds;
// 设置消息的目标标签表达式
// params.notifyTargetTags = @"xxx";
// 设置位置信息
// params.locationInfo = locationInfo;
[service sendMessage:message
params:params
success:^(V2NIMSendChatroomMessageResult *result)
{
// 发送成功
}
failure:^(V2NIMError *error)
{
// 发送失败
}
progress:^(NSUInteger progress)
{
// 上传进度
}];
cpp// 创建一条文本消息
auto message = V2NIMChatroomMessageCreator::createTextMessage("hello world");
auto params = V2NIMSendChatroomMessageParams();
// 发送消息
chatroomService.sendMessage(
message,
params,
[](V2NIMSendChatroomMessageResult result) {
// send message succeeded
},
[](V2NIMError error) {
// send message failed, handle error
},
[](uint32_t progress) {
// upload progress
});
typescriptconst message = chatroomV2.V2NIMChatroomMessageCreator.createTextMessage("hello")
await chatroom.V2NIMChatroomService.sendMessage(
message,
// V2NIMSendChatroomMessageParams
{
locationInfo: {x: 0, y: 100, z: 0}
},
progress: (percentage) => {console.log('上传进度: ' + percentage)}
)
typescript// 准备代发送的消息
const msg: V2NIMChatroomMessage = this.chatroomClient.messageCreator.createTextMessage(text)
// 发送聊天室消息时的参数
const params: V2NIMSendChatroomMessageParams = {
// 配置参数,如
locationInfo: {x: 0, y: 100, z: 0}
}
// 发送进度回调,如上传附件时由该 cb 回调
const progressCb = (percentage: number) => {
this.messageSetProgress(imgMsg, percentage)
console.info(`onUploadProgress: ${JSON.stringify(percentage)}`)
}
// send
const msgRes: V2NIMSendChatroomMessageResult = await this.chatroomClient.chatroomService.sendMessage(msg, params, progressCb)
返回值
无返回值
Promise<V2NIMSendChatroomMessageResult
> 聊天室消息发送结果
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调,包含V2NIMSendChatroomMessageResult
。 - 请求失败,返回
V2NIMFailureCallback
回调,包含聊天室消息相关错误码。
- 请求成功,返回
V2NIMSendChatroomMessageSuccess
回调,可自定义设置。 - 请求失败,返回
V2NIMFailureCallback
回调,包含聊天室消息相关错误码。
无
cancelMessageAttachmentUpload
接口描述
取消上传聊天室消息附件。
- 该方法仅支持取消文件类消息(图片、视频、文件)的附件上传。
- 无法取消已经上传成功的附件。
- 如果取消上传成功,消息附件上传状态会转变为上传失败
V2NIMMessageAttachmentUploadState.V2NIM_MESSAGE_ATTACHMENT_UPLOAD_STATE_FAILED
,对应的文件类消息会发送失败。
参数说明
javavoid cancelMessageAttachmentUpload(V2NIMChatroomMessage message,V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 取消附件上传的聊天室消息对象。该消息必须为图片、视频、文件类型。 |
success |
V2NIMSuccessCallback |
是 | - | 取消成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 取消失败回调,返回错误码。 |
objective-c- (void)cancelMessageAttachmentUpload:(V2NIMChatroomMessage *)message
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage * |
是 | - | 取消附件上传的聊天室消息对象。该消息必须为图片、视频、文件类型。 |
success |
V2NIMSuccessCallback |
是 | - | 取消成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 取消失败回调,返回错误码。 |
cppvirtual void cancelMessageAttachmentUpload(V2NIMChatroomMessage message, V2NIMSuccessCallback<void> success, V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 取消附件上传的聊天室消息对象。该消息必须为图片、视频、文件类型。 |
success |
V2NIMSuccessCallback |
是 | - | 取消成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 取消失败回调,返回错误码。 |
typescriptcancelMessageAttachmentUpload(message: V2NIMChatroomMessage): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 取消附件上传的聊天室消息对象。该消息必须为图片、视频、文件类型。 |
typescriptcancelMessageAttachmentUpload(message: V2NIMChatroomMessage): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
message |
V2NIMChatroomMessage |
是 | - | 取消附件上传的聊天室消息对象。该消息必须为图片、视频、文件类型。 |
示例代码
java// 通过实例ID获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
v2ChatroomService.cancelMessageAttachmentUpload(v2Message, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 取消成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 取消失败
}
});
objective-c// 通过实例 ID 获取聊天室服务
id<V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
[service cancelMessageAttachmentUpload:message
success:^{
// 取消成功
}
failure:^(V2NIMError *error) {
// 取消失败
}];
cppV2NIMChatroomMessage message;
// ...
chatroomService.cancelMessageAttachmentUpload(
message,
[]() {
// cancel message attachment upload succeeded
},
[](V2NIMError error) {
// cancel message attachment upload failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.cancelMessageAttachmentUpload(message)
typescriptawait this.chatroomClient.chatroomService.cancelMessageAttachmentUpload(message)
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调。 - 请求失败,返回
V2NIMFailureCallback
回调,包含消息相关错误码。
无
getMessageList
接口描述
按查询配置项分页获取所有历史消息。
该方法用于分页获取聊天室消息数据,直到获取聊天室全量消息,获取到的消息包括聊天室通知消息。
参数说明
javavoid getMessageList(V2NIMChatroomMessageListOption option, V2NIMSuccessCallback<List<V2NIMChatroomMessage>> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomMessageListOption |
是 | - | 聊天室消息查询选项,支持查询指定时间段和消息类型的聊天室历史消息。 |
success |
V2NIMSuccessCallback |
是 | - | 查询成功回调,返回 V2NIMChatroomMessage 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 查询失败回调,返回错误码。 |
objective-c- (void)getMessageList:(V2NIMChatroomMessageListOption *)option
success:(nullable V2NIMChatroomMessageListCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomMessageListOption * |
是 | - | 聊天室消息查询选项,支持查询指定时间段和消息类型的聊天室历史消息。 |
success |
V2NIMChatroomMessageListCallback |
是 | - | 查询成功回调,可自定义设置。 |
failure |
V2NIMFailureCallback |
是 | - | 查询失败回调,返回错误码。 |
cppvirtual void getMessageList(V2NIMChatroomMessageListOption option,
V2NIMSuccessCallback<nstd::vector<V2NIMChatroomMessage>> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomMessageListOption |
是 | - | 聊天室消息查询选项,支持查询指定时间段和消息类型的聊天室历史消息。 |
success |
V2NIMSuccessCallback |
是 | - | 查询成功回调,返回 V2NIMChatroomMessage 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 查询失败回调,返回错误码。 |
typescriptgetMessageList(option: V2NIMChatroomMessageListOption): Promise<V2NIMChatroomMessage[]>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomMessageListOption |
是 | - | 聊天室消息查询选项,支持查询指定时间段和消息类型的聊天室历史消息。 |
typescriptgetMessageList(option: V2NIMChatroomMessageListOption): Promise<V2NIMChatroomMessage[]>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomMessageListOption |
是 | - | 聊天室消息查询选项,支持查询指定时间段和消息类型的聊天室历史消息。 |
示例代码
java// 通过实例 ID 获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomMessageListOption option = new V2NIMChatroomMessageListOption();
// 设置查询数量
option.setLimit(100);
// 设置消息查询起始时间
option.setBeginTime(0L);
// 设置消息查询方向
option.setDirection(V2NIMMessageQueryDirection.V2NIM_QUERY_DIRECTION_DESC);
// 设置查询的消息类型,如果列表为空,表示查询所有类型的消息
List<V2NIMMessageType> messageTypes = getMessageTypes();
option.setMessageTypes(messageTypes);
v2ChatroomService.getMessageList(option, new V2NIMSuccessCallback<List<V2NIMChatroomMessage>>() {
@Override
public void onSuccess(List<V2NIMChatroomMessage> v2NIMChatroomMessages) {
//查询成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
//查询失败
}
});
objective-c// 通过实例 ID 获取聊天室服务
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomMessageListOption *option = [[V2NIMChatroomMessageListOption alloc] init];
// 设置查询数量
option.limit = 100;
// 设置消息查询起始时间
option.beginTime = 0L;
// 设置消息查询方向
option.direction = V2NIM_QUERY_DIRECTION_DESC;
// 设置查询的消息类型,如果列表为空,表示查询所有类型的消息
option.messageTypes = @[
@(V2NIM_MESSAGE_TYPE_TEXT),
@(V2NIM_MESSAGE_TYPE_IMAGE),
@(V2NIM_MESSAGE_TYPE_LOCATION),
@(V2NIM_MESSAGE_TYPE_NOTIFICATION),
@(V2NIM_MESSAGE_TYPE_FILE),
@(V2NIM_MESSAGE_TYPE_TIP),
@(V2NIM_MESSAGE_TYPE_CUSTOM)
];
[service getMessageList:option
success:^(NSArray<V2NIMChatroomMessage *> *messages)
{
// 查询成功
}
failure:^(V2NIMError *error)
{
// 查询失败
}];
cppV2NIMChatroomMessageListOption option;
option.beginTime = 0;
option.limit = 10;
chatroomService.getMessageList(
option,
[](nstd::vector<V2NIMChatroomMessage> messages) {
// get message list succeeded
},
[](V2NIMError error) {
// get message list failed, handle error
});
typescriptconst messageArr = await chatroom.V2NIMChatroomService.getMessageList({
// 0 是降序查找。从最新的消息开始查询
direction: V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC,
// 查询开始时间
beginTime: 0,
limit: 100
})
typescriptconst messages: V2NIMChatroomMessage[] = await this.chatroomClient.chatroomService.getMessageList({
// 0 是降序查找。从最新的消息开始查询
direction: V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC,
// 查询开始时间
beginTime: 0,
limit: 100
})
返回值
无返回值
Promise<V2NIMChatroomMessage[]>:消息列表
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调,包含V2NIMChatroomMessage
列表。 - 请求失败,返回
V2NIMFailureCallback
回调,包含聊天室消息相关错误码。
- 请求成功,返回
V2NIMChatroomMessageListCallback
回调,可自定义设置。 - 请求失败,返回
V2NIMFailureCallback
回调,包含聊天室消息相关错误码。
无
getMessageListByTag
接口描述
分页获取指定标签的所有聊天室历史消息。
该方法用于分页获取聊天室消息数据,直到获取聊天室全量消息,获取到的消息不包括已删除消息。
参数说明
javavoid getMessageListByTag(V2NIMChatroomTagMessageOption messageOption, V2NIMSuccessCallback<List<V2NIMChatroomMessage>> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
messageOption |
V2NIMChatroomTagMessageOption |
是 | - | 按标签查询聊天室消息选项 |
success |
V2NIMSuccessCallback |
是 | - | 查询成功回调,返回 V2NIMChatroomMessage 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 查询失败回调,返回错误码。 |
objective-c- (void)getMessageListByTag:(V2NIMChatroomTagMessageOption *)option
success:(nullable V2NIMChatroomMessageListCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
messageOption |
V2NIMChatroomTagMessageOption * |
是 | - | 按标签查询聊天室消息选项 |
success |
V2NIMChatroomMessageListCallback |
是 | - | 查询成功回调,返回 V2NIMChatroomMessage 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 查询失败回调,返回错误码。 |
cppvirtual void getMessageListByTag(V2NIMChatroomTagMessageOption messageOption,
V2NIMSuccessCallback<nstd::vector<V2NIMChatroomMessage>> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
messageOption |
V2NIMChatroomTagMessageOption |
是 | - | 按标签查询聊天室消息选项 |
success |
V2NIMSuccessCallback |
是 | - | 查询成功回调,返回 V2NIMChatroomMessage 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 查询失败回调,返回错误码。 |
typescriptgetMessageListByTag(messageOption: V2NIMChatroomTagMessageOption): Promise<V2NIMChatroomMessage[]>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
messageOption |
V2NIMChatroomTagMessageOption |
是 | - | 按标签查询聊天室消息选项 |
typescriptgetMessageListByTag(messageOption: V2NIMChatroomTagMessageOption): Promise<V2NIMChatroomMessage[]>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
messageOption |
V2NIMChatroomTagMessageOption |
是 | - | 按标签查询聊天室消息选项 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomTagMessageOption messageOption = new V2NIMChatroomTagMessageOption();
// tag 列表
List<String> tags = getTags();
// 设置查询的 tag 列表,必传字段,传 null 或者 size 为 0,会返回参数错误
messageOption.setTags(tags);
// 设置查询数量
messageOption.setLimit(100);
List<V2NIMMessageType> messageTypes = getMessageTypes();
// 设置查询的消息类型,如果列表为空,表示查询所有类型的消息
messageOption.setMessageTypes(messageTypes);
messageOption.setDirection(V2NIMMessageQueryDirection.V2NIM_QUERY_DIRECTION_DESC);
// 设置查询开始时间,首次传0,单位毫秒
messageOption.setBeginTime(0L);
// 设置查询结束时间,默认0表示当前时间,单位毫秒
messageOption.setEndTime(0L);
v2ChatroomService.getMessageListByTag(messageOption, new V2NIMSuccessCallback<List<V2NIMChatroomMessage>>() {
@Override
public void onSuccess(List<V2NIMChatroomMessage> v2NIMChatroomMessages) {
// 查询成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 查询失败
}
});
objective-c// 通过实例ID获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomTagMessageOption *messageOption = [[V2NIMChatroomTagMessageOption alloc] init];
// 设置查询的 tag 列表,必传字段,传 null 或者 size 为 0,会返回参数错误
messageOption.tags = @[@"tag1", @"tag2"];
// 设置查询数量
messageOption.limit = 100;
// 设置查询的消息类型,如果列表为空,表示查询所有类型的消息
messageOption.messageTypes = @[@(V2NIM_MESSAGE_TYPE_TEXT), @(V2NIM_MESSAGE_TYPE_FILE)];
// 设置查询方向
messageOption.direction = V2NIM_QUERY_DIRECTION_DESC;
// 设置查询开始时间,单位秒
messageOption.beginTime = 0;
// 设置查询结束时间,默认0表示当前时间,单位秒
messageOption.endTime = 0;
[service getMessageListByTag:messageOption
success:^(NSArray<V2NIMChatroomMessage *> *messages)
{
// 查询成功
}
failure:^(V2NIMError *error)
{
// 查询失败
}];
cppV2NIMChatroomTagMessageOption messageOption;
messageOption.tags = {"tag1", "tag2"};
messageOption.limit = 10;
chatroomService.getMessageListByTag(
messageOption,
[](nstd::vector<V2NIMChatroomMessage> messages) {
// get message list by tag succeeded
},
[](V2NIMError error) {
// get message list by tag failed, handle error
});
typescriptconst messages = await chatroom.V2NIMChatroomService.getMessageListByTag({
tags: ['tag1', 'tag2'], // 查询的 tags
limit: 100,
direction: V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC
})
typescriptconst messages = await this.chatroomClient.chatroomService.getMessageListByTag({
tags: ['tag1', 'tag2'], //查询的tags
limit: 100,
direction: V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC
})
返回值
无返回值
Promise<V2NIMChatroomMessage[]>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调,包含V2NIMChatroomMessage
列表。 - 请求失败,返回
V2NIMFailureCallback
回调,包含聊天室消息相关错误码。
- 请求成功,返回
V2NIMChatroomMessageListCallback
回调,可自定义设置。 - 请求失败,返回
V2NIMFailureCallback
回调,包含聊天室消息相关错误码。
无
kickMember
接口描述
将聊天室成员踢出聊天室。
本地端或多端同步踢出聊天室成员成功后:
- 被踢方收到被踢出聊天室回调
onChatroomKicked
,以及退出聊天室回调onChatroomExited
()。 - 聊天室内所有成员收到一条通知类消息,类型为
V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_KICKED(7)
。
- 仅允许聊天室创建者和管理员调用该接口,否则返回错误码 109432。
- 如果被踢方为管理员,则仅允许聊天室创建者操作,否则返回错误码 109427。
参数说明
javavoid kickMember(String accountId, String notificationExtension, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
String | 是 | - | 踢出聊天室的成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
notificationExtension |
String | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 踢出成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 踢出失败回调,返回错误码。 |
objective-c- (void)kickMember:(NSString *)accountId
notificationExtension:(nullable NSString *)notificationExtension
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
NSString * | 是 | - | 踢出聊天室的成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
notificationExtension |
nullable NSString * | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 踢出成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 踢出失败回调,返回错误码。 |
cppvirtual void kickMember(nstd::string accountId,
nstd::string notificationExtension,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
nstd::string | 是 | - | 踢出聊天室的成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
notificationExtension |
nstd::string | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 踢出成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 踢出失败回调,返回错误码。 |
typescriptkickMember(accountId: string, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 踢出聊天室的成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
typescriptkickMember(accountId: string, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 踢出聊天室的成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 被踢的成员ID
String accountId = "test";
// 设置通知扩展字段,可不传
String notificationExtension = "xxx";
v2ChatroomService.kickMember(accountId, notificationExtension, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 踢出成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 踢出失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
// 被踢的成员 ID
NSString *accountId = @"accountId";
// 设置通知扩展字段,可不传
NSString *notificationExtension = @"xxx";
[service kickMember:accountId
notificationExtension:notificationExtension
success:^() {
// 踢出成功
}
failure:^(V2NIMError *error) {
// 踢出失败
}];
cppchatroomService.kickMember(
"accountId",
"notificationExtension",
[]() {
// kick member succeeded
},
[](V2NIMError error) {
// kick member failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.kickMember('account', 'notificationExtension')
typescriptawait this.chatroomClient.chatroomService.kickMember('account', 'notificationExtension')
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;踢出聊天室成功,返回onChatroomKicked
回调和onChatroomExited
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
踢出聊天室成功,返回 onChatroomKicked
回调和 onChatroomExited
回调。
getMemberListByOption
接口描述
分页获取所有聊天室成员列表。
参数说明
javavoid getMemberListByOption(V2NIMChatroomMemberQueryOption queryOption, V2NIMSuccessCallback<V2NIMChatroomMemberListResult> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
queryOption |
V2NIMChatroomMemberQueryOption |
是 | - | 聊天室成员分页查询选项 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回 V2NIMChatroomMemberListResult 。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
objective-c- (void)getMemberListByOption:(V2NIMChatroomMemberQueryOption *)queryOption
success:(nullable V2NIMChatroomMemberListResultCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
queryOption |
V2NIMChatroomMemberQueryOption * |
是 | - | 聊天室成员分页查询选项 |
success |
V2NIMChatroomMemberListResultCallback |
是 | - | 获取成功回调,可自定义设置。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
cppvirtual void getMemberListByOption(V2NIMChatroomMemberQueryOption queryOption,
V2NIMSuccessCallback<V2NIMChatroomMemberListResult> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
queryOption |
V2NIMChatroomMemberQueryOption |
是 | - | 聊天室成员分页查询选项 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回 V2NIMChatroomMemberListResult 。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
typescriptgetMemberListByOption(option: V2NIMChatroomMemberQueryOption): Promise<V2NIMChatroomMemberListResult>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
queryOption |
V2NIMChatroomMemberQueryOption |
是 | - | 聊天室成员分页查询选项 |
typescriptgetMemberListByOption(option: V2NIMChatroomMemberQueryOption): Promise<V2NIMChatroomMemberListResult>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
queryOption |
V2NIMChatroomMemberQueryOption |
是 | - | 聊天室成员分页查询选项 |
示例代码
java// 通过实例 ID 获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomMemberQueryOption queryOption = new V2NIMChatroomMemberQueryOption();
// 设置需要查询的成员类型,如果列表为空,表示查询所有类型的成员
List<V2NIMChatroomMemberRole> memberRoles = getMemberRoles();
queryOption.setMemberRoles(memberRoles);
// 是否只返回黑名单成员, 默认false
queryOption.setOnlyBlocked(false);
// 是否只返回禁言用户, 默认false
queryOption.setOnlyChatBanned(false);
// 是否只返回在线成员, 默认false
queryOption.setOnlyOnline(false);
// 设置查询数量
queryOption.setLimit(100);
// 设置分页标识,首页传"",下一页传上次返回的 pageToken
queryOption.setPageToken("");
v2ChatroomService.getMemberListByOption(queryOption, new V2NIMSuccessCallback<V2NIMChatroomMemberListResult>() {
@Override
public void onSuccess(V2NIMChatroomMemberListResult v2NIMChatroomMemberListResult) {
// 查询成功
List<V2NIMChatroomMember> memberList = v2NIMChatroomMemberListResult.getMemberList();
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 查询失败
}
});
objective-c// 通过实例 ID 获取聊天室服务
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomMemberQueryOption *queryOption = [[V2NIMChatroomMemberQueryOption alloc] init];
// 设置需要查询的成员类型,如果列表为空,表示查询所有类型的成员
queryOption.memberRoles = @[@(V2NIM_CHATROOM_MEMBER_ROLE_NORMAL_GUEST), @(V2NIM_CHATROOM_MEMBER_ROLE_ANONYMOUS_GUEST)];
// 是否只返回黑名单成员, 默认false
queryOption.onlyBlocked = NO;
// 是否只返回禁言用户, 默认false
queryOption.onlyChatBanned = NO;
// 是否只返回在线成员, 默认false
queryOption.onlyOnline = NO;
// 设置查询数量
queryOption.limit = 100;
// 设置分页标识,首页传"",下一页传上次返回的 pageToken
queryOption.pageToken = @"";
[service getMemberListByOption:queryOption
success:^(V2NIMChatroomMemberListResult *result)
{
// 查询成功
}
failure:^(V2NIMError *error)
{
// 查询失败
}];
cppV2NIMChatroomMemberQueryOption queryOption;
queryOption.pageToken = 0; // first page
queryOption.limit = 10;
chatroomService.getMemberListByOption(
queryOption,
[](V2NIMChatroomMemberListResult result) {
// get member list succeeded
},
[](V2NIMError error) {
// get member list failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.getMemberListByOption({
// 普通成员
memberRoles: [V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_NORMAL],
onlyBlocked: false,
onlyChatBanned: false,
onlyOnline: false,
limit: 100
})
typescriptawait this.chatroomClient.chatroomService.getMemberListByOption({
// 普通成员
memberRoles: [V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_NORMAL],
onlyBlocked: false,
onlyChatBanned: false,
onlyOnline: false,
limit: 100
})
返回值
无返回值
Promise<V2NIMChatroomMemberListResult
> 聊天室成员查询结果
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调,包含V2NIMChatroomMemberListResult
。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
- 请求成功,返回
V2NIMChatroomMemberListResultCallback
回调,可自定义设置。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
无
getMemberByIds
接口描述
批量获取指定聊天室成员列表。
- 单次查询数量上限为 200。
- 返回聊天室成员信息按照输入
accountIds
顺序排序。
参数说明
javavoid getMemberByIds(List<String> accountIds, V2NIMSuccessCallback<List<V2NIMChatroomMember>> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountIds |
List |
是 | - | 如果输入为空/数量为 0/数量超过 200,则返回 191004 参数错误。 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回 [V2NIMChatroomMember ] 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
objective-c- (void)getMemberByIds:(NSArray<NSString *> *)accountIds
success:(nullable V2NIMChatroomMemberListCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountIds |
NSArray<NSString *> * | 是 | - | 如果输入为空/数量为 0/数量超过 200,则返回 191004 参数错误。 |
success |
V2NIMChatroomMemberListCallback |
是 | - | 获取成功回调,可自定义设置。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
cppvirtual void getMemberByIds(nstd::vector<nstd::string> accountIds,
V2NIMSuccessCallback<nstd::vector<V2NIMChatroomMember>> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountIds |
nstd::vector<\nstd::string> | 是 | - | 如果输入为空/数量为 0/数量超过 200,则返回 191004 参数错误。 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回 [V2NIMChatroomMember ] 列表。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
typescriptgetMemberByIds(accountIds: string[]): Promise<V2NIMChatroomMember[]>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountIds |
string[] | 是 | - | 如果输入为空/数量为 0/数量超过 200,则返回 191004 参数错误。 |
typescriptgetMemberByIds(accountIds: string[]): Promise<V2NIMChatroomMember[]>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountIds |
string[] | 是 | - | 如果输入为空/数量为 0/数量超过 200,则返回 191004 参数错误。 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 待查询的账号列表,为空或者 size==0,或者 size>200,返回参数错误
List<String> accountIds = getAccountIds();
v2ChatroomService.getMemberByIds(accountIds, new V2NIMSuccessCallback<List<V2NIMChatroomMember>>() {
@Override
public void onSuccess(List<V2NIMChatroomMember> v2NIMChatroomMembers) {
// 查询成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 查询失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
// 待查询的账号列表,为空或者 size==0,或者 size>200,返回参数错误
NSArray<NSString *> *accountIds = @[@"accountId0", @"accountId1", @"accountId2"];
[service getMemberByIds:accountIds
success:^(NSArray<V2NIMChatroomMember *> *members) {
// 获取成功
}
failure:^(V2NIMError *error) {
// 获取失败
}];
cppchatroomService.getMemberByIds(
{"accountId1", "accountId2"},
[](nstd::vector<V2NIMChatroomMember> members) {
// get members by account ids succeeded
},
[](V2NIMError error) {
// get members by account ids failed, handle error
});
typescriptgetMemberByIds(accountIds: string[]): Promise<V2NIMChatroomMember[]>
typescriptconst members = await this.chatroomClient.chatroomService.getMemberByIds(['accid1', 'accid2'])
返回值
无返回值
Promise<V2NIMChatroomMember[]> 聊天室信息列表
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调,包含V2NIMChatroomMember
列表。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
- 请求成功,返回
V2NIMChatroomMemberListCallback
回调,可自定义设置。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
无
getMemberListByTag
接口描述
分页获取指定标签下的所有聊天室成员。
参数说明
javavoid getMemberListByTag(V2NIMChatroomTagMemberOption option, V2NIMSuccessCallback<V2NIMChatroomMemberListResult> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomTagMemberOption |
是 | - | 按标签查询聊天室成员选项 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回 V2NIMChatroomMemberListResult 。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
objective-c- (void)getMemberListByTag:(V2NIMChatroomTagMemberOption *)option
success:(nullable V2NIMChatroomMemberListResultCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomTagMemberOption |
是 | - | 按标签查询聊天室成员选项 |
success |
V2NIMChatroomMemberListResultCallback |
是 | - | 获取成功回调,可自定义设置。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
cppvirtual void getMemberListByTag(V2NIMChatroomTagMemberOption option,
V2NIMSuccessCallback<V2NIMChatroomMemberListResult> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomTagMemberOption |
是 | - | 按标签查询聊天室成员选项 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回 V2NIMChatroomMemberListResult 。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
typescriptgetMemberListByTag(option: V2NIMChatroomTagMemberOption): Promise<V2NIMChatroomMemberListResult>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomTagMemberOption |
是 | - | 按标签查询聊天室成员选项 |
typescriptgetMemberListByTag(option: V2NIMChatroomTagMemberOption): Promise<V2NIMChatroomMemberListResult>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
option |
V2NIMChatroomTagMemberOption |
是 | - | 按标签查询聊天室成员选项 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomTagMemberOption option = new V2NIMChatroomTagMemberOption();
// 设置查询 Tag,必传字段,如果不传,会返回参数错误
option.setTag("xxx");
// 设置查询数量
option.setLimit(100);
// 设置分页标识,首页传"",下一页传上次返回的 pageToken
option.setPageToken("");
v2ChatroomService.getMemberListByTag(option, new V2NIMSuccessCallback<V2NIMChatroomMemberListResult>() {
@Override
public void onSuccess(V2NIMChatroomMemberListResult v2NIMChatroomMemberListResult) {
// 查询成功
String pageToken = v2NIMChatroomMemberListResult.getPageToken();
List<V2NIMChatroomMember> memberList = v2NIMChatroomMemberListResult.getMemberList();
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 查询失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomTagMemberOption *option = [[V2NIMChatroomTagMemberOption alloc] init];
// 设置查询 Tag,必传字段,如果不传,会返回参数错误
option.tag = @"xxx";
// 设置查询数量
option.limit = 100;
// 设置分页标识,首页传"",下一页传上次返回的 pageToken
option.pageToken = @"";
[service getMemberListByTag:option
success:^(V2NIMChatroomMemberListResult *result)
{
// 获取成功
}
failure:^(V2NIMError *error)
{
// 获取失败
}];
cppV2NIMChatroomTagMemberOption option;
option.tag = "tag1";
option.pageToken = "";
option.limit = 10;
chatroomService.getMemberListByTag(
option,
[](V2NIMChatroomMemberListResult result) {
// get member list by tag succeeded
},
[](V2NIMError error) {
// get member list by tag failed, handle error
});
typescriptconst result = await chatroom.V2NIMChatroom.getMemberListByTag({
tag: 'abc', // 查询的 tag
limit: 100
})
typescriptconst result: V2NIMChatroomMemberListResult = await this.chatroomClient.chatroomService.getMemberListByTag({
tag: 'abc', // 查询的 tag
limit: 100
})
返回值
无返回值
Promise<V2NIMChatroomMemberListResult
> 聊天室成员查询结果
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调,包含V2NIMChatroomMemberListResult
。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
- 请求成功,返回
V2NIMChatroomMemberListResultCallback
回调,可自定义设置。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
无
getMemberCountByTag
接口描述
获取指定标签下的聊天室成员人数。
调用前请确保指定标签存在。
参数说明
javavoid getMemberCountByTag(String tag, V2NIMSuccessCallback<Long> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
tag |
String | 是 | - | 聊天室标签 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回成员人数。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
objective-c- (void)getMemberCountByTag:(NSString *)tag
success:(nullable V2NIMChatroomMemberCountCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
tag |
NSString * | 是 | - | 聊天室标签 |
success |
V2NIMChatroomMemberCountCallback |
是 | - | 获取成功回调,可自定义设置。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
cppvirtual void getMemberCountByTag(nstd::string tag, V2NIMSuccessCallback<uint64_t> success, V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
tag |
nstd::string | 是 | - | 聊天室标签 |
success |
V2NIMSuccessCallback |
是 | - | 获取成功回调,返回成员人数。 |
failure |
V2NIMFailureCallback |
是 | - | 获取失败回调,返回错误码。 |
typescriptgetMemberCountByTag(tag: string): Promise<number>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
tag |
string | 是 | - | 聊天室标签 |
typescriptgetMemberCountByTag(tag: string): Promise<number>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
tag |
string | 是 | - | 聊天室标签 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 查询的 tag,必传字段,传 null 或者 "",会返回参数错误
String tag = "xxx";
v2ChatroomService.getMemberCountByTag(tag, new V2NIMSuccessCallback<Long>() {
@Override
public void onSuccess(Long count) {
// 查询成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 查询失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
// 查询的 tag,必传字段,传 null 或者 "",会返回参数错误
NSString *tag = @"xxx";
[service getMemberCountByTag:tag
success:^(NSInteger memberCount)
{
// 获取成功
}
failure:^(V2NIMError *error)
{
// 获取失败
}];
cppchatroomService.getMemberCountByTag(
"tag1",
[](uint64_t count) {
// get member count by tag succeeded
},
[](V2NIMError error) {
// get member count by tag failed, handle error
});
typescriptconst count = await chatroom.V2NIMChatroomService.getMemberCountByTag('tagName')
typescriptconst count = await this.chatroomClient.chatroomService.getMemberCountByTag('tagName')
返回值
聊天室成员人数
Promise
相关回调
无
updateMemberRole
接口描述
更新聊天室成员角色类型。
本地端或多端同步更新聊天室成员角色类型成功后,聊天室内所有成员收到成员角色类型变更回调 onChatroomMemberRoleUpdated
及通知类消息,消息类型为 V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_ROLE_UPDATE(18)
。
- 仅允许聊天室创建者和管理员调用该接口,否则返回错误码 109432。
- 如果变更为管理员、或将管理员变更为其他角色,则仅允许聊天室创建者操作,否则返回错误码 109427。
- 不允许操作虚构用户和匿名游客。
参数说明
javavoid updateMemberRole(String accountId, V2NIMChatroomMemberRoleUpdateParams updateParams, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
String | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
updateParams |
V2NIMChatroomMemberRoleUpdateParams |
是 | - | 聊天室成员更新参数。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
objective-c- (void)updateMemberRole:(NSString *)accountId
updateParams:(V2NIMChatroomMemberRoleUpdateParams *)updateParams
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
NSString * | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
updateParams |
V2NIMChatroomMemberRoleUpdateParams * |
是 | - | 聊天室成员更新参数。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
cppvirtual void updateMemberRole(nstd::string accountId,
V2NIMChatroomMemberRoleUpdateParams upadateParams,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
nstd::string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
updateParams |
V2NIMChatroomMemberRoleUpdateParams |
是 | - | 聊天室成员更新参数。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
typescriptupdateMemberRole(accountId: string, updateParams: V2NIMChatroomMemberRoleUpdateParams): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
updateParams |
V2NIMChatroomMemberRoleUpdateParams |
是 | - | 聊天室成员更新参数。 |
typescriptupdateMemberRole(accountId: string, updateParams: V2NIMChatroomMemberRoleUpdateParams): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 |
updateParams |
V2NIMChatroomMemberRoleUpdateParams |
是 | - | 聊天室成员更新参数。 |
示例代码
java// 通过实例 ID 获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 被操作的账号 ID
String accountId = "test";
V2NIMChatroomMemberRoleUpdateParams updateParams = new V2NIMChatroomMemberRoleUpdateParams();
// 设置成员角色,必传字段,如果不传,会返回参数错误
// 不支持设置为
// V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_CREATOR
// V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_ANONYMOUS_GUEST
// V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_VIRTUAL
updateParams.setMemberRole(V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_MANAGER);
// 设置成员等级,可不传
updateParams.setMemberLevel(1);
// 设置通知扩展字段,可不传
updateParams.setNotificationExtension("xxx");
v2ChatroomService.updateMemberRole(accountId, updateParams, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
//更新成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
//更新失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:instanceId] getChatroomService];
// 被操作的账号 ID
NSString *accountId = @"test";
V2NIMChatroomMemberRoleUpdateParams *updateParams = [[V2NIMChatroomMemberRoleUpdateParams alloc] init];
// 设置成员角色,必传字段,如果不传,会返回参数错误
// 不支持设置为
// V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_CREATOR
// V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_ANONYMOUS_GUEST
// V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_VIRTUAL
updateParams.memberRole = V2NIM_CHATROOM_MEMBER_ROLE_MANAGER;
// 设置成员等级,可不传
updateParams.memberLevel = 1;
// 设置通知扩展字段,可不传
updateParams.notificationExtension = @"xxx";
[service updateMemberRole:accountId
updateParams:updateParams
success:^()
{
// 更新成功
}
failure:^(V2NIMError *error)
{
// 更新失败
}];
cppV2NIMChatroomMemberRoleUpdateParams updateParams;
updateParams.memberRole = V2NIM_CHATROOM_MEMBER_ROLE_MANAGER;
chatroomService.updateMemberRole(
"accountId",
updateParams,
[]() {
// update member role succeeded
},
[](V2NIMError error) {
// update member role failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.updateMemberRole('accid', {
// 设置为管理员
memberRole: V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_MANAGER,
// 用户登记
memberLevel: 10,
// 通知的扩展字段
notificationExtension: 'ps'
})
typescriptawait this.chatroomClient.chatroomService.updateMemberRole('accid', {
// 设置为管理员
memberRole: V2NIMChatroomMemberRole.V2NIM_CHATROOM_MEMBER_ROLE_MANAGER,
// 用户登记
memberLevel: 10,
// 通知的扩展字段
notificationExtension: 'ps'
})
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;更新成功,返回onChatroomMemberRoleUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含群组相关错误码。
更新成功,返回 onChatroomMemberRoleUpdated
回调。
setMemberBlockedStatus
接口描述
设置聊天室成员黑名单状态。聊天室黑名单用户与聊天室服务器断开连接,无法收发聊天室消息。
本地端或多端同步设置聊天室成员黑名单状态成功后:
- 聊天室内所有成员收到成员信息变更回调
onChatroomMemberInfoUpdated
。 - 将成员加入黑名单后(设置
blocked
参数为true
),被拉黑方收到被踢回调onChatroomKicked
;所有聊天室成员会收到聊天室通知消息,通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_BLOCK_ADDED(2)
。 - 将成员从黑名单移除后(设置
blocked
参数为false
),所有聊天室成员收到聊天室通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_BLOCK_REMOVED(3)
。
- 仅允许聊天室创建者和管理员调用该接口,否则返回错误码 109432。
- 如果被操作方为管理员,则仅允许聊天室创建者操作,否则返回错误码 109427。
- 不允许操作虚构用户和匿名游客。
参数说明
javavoid setMemberBlockedStatus(String accountId, boolean blocked,String notificationExtension, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
String | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
blocked |
boolean | 是 | - | 是否加入黑名单: |
notificationExtension |
String | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
objective-c- (void)setMemberBlockedStatus:(NSString *)accountId
blocked:(BOOL)blocked
notificationExtension:(nullable NSString *)notificationExtension
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
NSString * | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
blocked |
BOOL | 是 | - | 是否加入黑名单: |
notificationExtension |
nullable NSString * | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
cppvirtual void setMemberBlockedStatus(nstd::string accountId,
bool blocked,
nstd::string notificationExtension,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
nstd::string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
blocked |
bool | 是 | - | 是否加入黑名单: |
notificationExtension |
nstd::string | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
typescriptsetMemberBlockedStatus(accountId: string, blocked: boolean, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
blocked |
boolean | 是 | - | 是否加入黑名单: |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
typescriptsetMemberBlockedStatus(accountId: string, blocked: boolean, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
blocked |
boolean | 是 | - | 是否加入黑名单: |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
示例代码
java// 通过实例 ID 获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 被操作的账号 ID
String accountId = "test";
// 设置黑名单状态
boolean blocked = true;
// 设置通知扩展字段,可不传
String notificationExtension = "xxx";
v2ChatroomService.setMemberBlockedStatus(accountId, blocked, notificationExtension, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 设置成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 设置失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
// 被操作的账号 ID
NSString *accountId = @"test";
// 设置黑名单状态
BOOL blocked = YES;
// 设置通知扩展字段,可不传
NSString *notificationExtension = @"xxx";
[service setMemberBlockedStatus:accountId
blocked:blocked
notificationExtension:notificationExtension
success:^()
{
// 设置成功
}
failure:^(V2NIMError *error)
{
// 设置失败
}];
cppchatroomService.setMemberBlockedStatus(
"accountId",
true,
"notificationExtension",
[]() {
// set member blocked status succeeded
},
[](V2NIMError error) {
// set member blocked status failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.setMemberBlockedStatus('accountId', true, 'extension')
typescriptawait this.chatroomClient.chatroomService.setMemberBlockedStatus('accid', true, 'extension')
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;设置成功,返回onChatroomMemberInfoUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
设置成功,返回 onChatroomMemberInfoUpdated
回调。
setMemberChatBannedStatus
接口描述
设置聊天室成员禁言状态。聊天室禁言用户用户无法在聊天室发消息。
本地端或多端同步设置聊天室成员禁言状态成功后:
- 被禁言成员:收到禁言状态变更回调
onSelfChatBannedUpdated
。 - 聊天室内所有成员:
- 收到成员信息变更回调
onChatroomMemberInfoUpdated
。 - 将成员禁言后(设置
chatBanned
参数为true
),所有聊天室成员会收到聊天室通知消息,通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_CHAT_BANNED_ADDED(4)
;将成员解除禁言后(设置chatBanned
参数为false
),所有聊天室成员收到聊天室通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_CHAT_BANNED_REMOVED(5)
。
- 收到成员信息变更回调
- 仅允许聊天室创建者和管理员调用该接口,否则返回错误码 109432。
- 如果被操作方为管理员,则仅允许聊天室创建者操作,否则返回错误码 109427。
- 不允许操作虚构用户和匿名游客。
参数说明
javavoid setMemberChatBannedStatus(String accountId, boolean chatBanned,String notificationExtension, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
String | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
chatBanned |
boolean | 是 | - | 是否为禁言状态 |
notificationExtension |
String | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
objective-c- (void)setMemberChatBannedStatus:(NSString *)accountId
chatBanned:(BOOL)chatBanned
notificationExtension:(nullable NSString *)notificationExtension
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
NSString * | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
chatBanned |
BOOL | 是 | - | 是否为禁言状态 |
notificationExtension |
nullable NSString * | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
cpp virtual void setMemberChatBannedStatus(nstd::string accountId,
bool chatBanned,
nstd::string notificationExtension,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
nstd::string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
chatBanned |
bool | 是 | - | 是否为禁言状态 |
notificationExtension |
nstd::string | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
typescriptsetMemberChatBannedStatus(accountId: string, chatBanned: boolean, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
chatBanned |
boolean | 是 | - | 是否为禁言状态 |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
typescriptsetMemberChatBannedStatus(accountId: string, chatBanned: boolean, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
chatBanned |
boolean | 是 | - | 是否为禁言状态 |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 被操作的账号ID
String accountId = "test";
// 设置禁言状态
boolean chatBanned = true;
// 设置通知扩展字段,可不传
String notificationExtension = "xxx";
v2ChatroomService.setMemberChatBannedStatus(accountId, chatBanned, notificationExtension, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 设置成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 设置失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
// 被操作的账号 ID
NSString *accountId = @"test";
//设置禁言状态
BOOL chatBanned = YES;
// 设置通知扩展字段,可不传
NSString *notificationExtension = @"xxx";
[service setMemberChatBannedStatus:accountId
chatBanned:chatBanned
notificationExtension:notificationExtension
success:^()
{
// 设置成功
}
failure:^(V2NIMError *error)
{
// 设置失败
}];
cppchatroomService.setMemberChatBannedStatus(
"accountId",
true,
"notificationExtension",
[]() {
// set member chat banned status succeeded
},
[](V2NIMError error) {
// set member chat banned status failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.setMemberChatBannedStatus('accid', true, 'extension')
typescriptawait this.chatroomClient.chatroomService.setMemberChatBannedStatus('accid', true, 'extension')
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;设置成功,返回onSelfChatBannedUpdated
和onChatroomMemberInfoUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
设置成功,返回 onChatroomMemberInfoUpdated
回调。
setMemberTempChatBanned
接口描述
设置聊天室成员临时禁言状态。
被临时禁言后,无法在聊天室发送消息。临时禁言结束后,恢复发送消息权限。
本地端或多端同步设置聊天室成员临时禁言状态成功后:
- 被禁言成员:收到临时禁言状态变更回调
onSelfTempChatBannedUpdated
。 - 聊天室内所有成员:
- 收到成员信息变更回调
onChatroomMemberInfoUpdated
。 - 将成员临时禁言后(
tempChatBannedDuration
不为 0),所有聊天室成员会收到聊天室通知消息,通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_TEMP_CHAT_BANNED_ADDED(8)
;将成员解除临时禁言后(tempChatBannedDuration
为 0),所有聊天室成员收到聊天室通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_TEMP_CHAT_BANNED_REMOVED(9)
。
- 收到成员信息变更回调
- 仅允许聊天室创建者和管理员调用该接口,否则返回错误码 109432。
- 如果被操作方为管理员,则仅允许聊天室创建者操作,否则返回错误码 109427。
- 不允许操作虚构用户和匿名游客。
参数说明
javavoid setMemberTempChatBanned(String accountId, long tempChatBannedDuration,boolean notificationEnabled,String notificationExtension, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
String | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
tempChatBannedDuration |
long | 是 | - | 临时禁言时长(秒)。不可超过 30 天。 设置为 0 表示解除临时禁言。 |
notificationEnabled |
boolean | 是 | - | 操作后是否需要通知 |
notificationExtension |
String | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
objective-c- (void)setMemberTempChatBanned:(NSString *)accountId
tempChatBannedDuration:(NSInteger)tempChatBannedDuration
notificationEnabled:(BOOL)notificationEnabled
notificationExtension:(nullable NSString *)notificationExtension
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
NSString * | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
tempChatBannedDuration |
NSInteger | 是 | - | 临时禁言时长(秒)。不可超过 30 天。 设置为 0 表示解除临时禁言。 |
notificationEnabled |
BOOL | 是 | - | 操作后是否需要通知 |
notificationExtension |
nullable NSString * | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
cppvirtual void setMemberTempChatBanned(nstd::string accountId,
uint64_t tempChatBannedDuration,
bool notificationEnabled,
nstd::string notificationExtension,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
nstd::string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
tempChatBannedDuration |
long | 是 | - | 临时禁言时长(秒)。不可超过 30 天。 设置为 0 表示解除临时禁言。 |
notificationEnabled |
bool | 是 | - | 操作后是否需要通知 |
notificationExtension |
nstd::string | 否 | null | 本次操作生成的通知中的扩展字段 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
typescriptsetMemberTempChatBanned(accountId: string, tempChatBannedDuration: number, notificationEnabled: boolean, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
tempChatBannedDuration |
number | 是 | - | 临时禁言时长(秒)。不可超过 30 天。 设置为 0 表示解除临时禁言。 |
notificationEnabled |
boolean | 是 | - | 操作后是否需要通知 |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
typescriptsetMemberTempChatBanned(accountId: string, tempChatBannedDuration: number, notificationEnabled: boolean, notificationExtension?: string): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
accountId |
string | 是 | - | 聊天室用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。 不允许传入虚构用户和匿名游客的用户账号。 |
tempChatBannedDuration |
number | 是 | - | 临时禁言时长(秒)。不可超过 30 天。 设置为 0 表示解除临时禁言。 |
notificationEnabled |
boolean | 是 | - | 操作后是否需要通知 |
notificationExtension |
string | 否 | null | 本次操作生成的通知中的扩展字段 |
示例代码
java// 通过实例 ID 获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
// 被操作的账号 ID
String accountId = "test";
// 设置临时禁言时长,单位:秒,单次最大:30天,取消则设置为:0
long tempChatBannedDuration = 1000L;
// 是否需要发送广播通知,true:通知,false:不通知
boolean notificationEnabled = true;
// 设置通知扩展字段,可不传
String notificationExtension = "xxx";
v2ChatroomService.setMemberTempChatBanned(accountId, tempChatBannedDuration, notificationEnabled, notificationExtension, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 设置成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 设置失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
// 被操作的账号 ID
NSString *accountId = @"test";
// 设置临时禁言时长,单位:秒,单次最大:30天,取消则设置为:0
long tempChatBannedDuration = 1000L;
// 是否需要发送广播通知,true:通知,false:不通知
BOOL notificationEnabled = YES;
// 设置通知扩展字段,可不传
NSString *notificationExtension = @"xxx";
[service setMemberTempChatBanned:accountId
tempChatBannedDuration:tempChatBannedDuration
notificationEnabled:notificationEnabled
notificationExtension:notificationExtension
success:^()
{
// 设置成功
}
failure:^(V2NIMError *error)
{
// 设置失败
}];
cppchatroomService.setMemberTempChatBanned(
"accountId",
60,
true,
"notificationExtension",
[]() {
// set member temp chat banned succeeded
},
[](V2NIMError error) {
// set member temp chat banned failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.setMemberTempChatBanned('accid', 60 * 1000, true, 'extension')
typescriptawait this.chatroomClient.chatroomService.setMemberTempChatBanned('accid', 60 * 1000, true, 'extension')
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;设置成功,返回onSelfTempChatBannedUpdated
和onChatroomMemberInfoUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
设置成功,返回 onChatroomMemberInfoUpdated
回调。
setTempChatBannedByTag
接口描述
设置聊天室成员临时禁言状态。
被临时禁言后,无法在聊天室发送消息。临时禁言结束后,恢复发送消息权限。
本地端或多端同步设置聊天室成员临时禁言状态成功后:
- 被禁言成员:收到临时禁言状态变更回调
onSelfTempChatBannedUpdated
。 - 聊天室内所有成员:
- 收到成员信息变更回调
onChatroomMemberInfoUpdated
。 - 将成员临时禁言后(
tempChatBannedDuration
不为 0),所有聊天室成员会收到聊天室通知消息,通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_TEMP_CHAT_BANNED_ADDED(8)
;将成员解除临时禁言后(tempChatBannedDuration
为 0),所有聊天室成员收到聊天室通知消息类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_TEMP_CHAT_BANNED_REMOVED(9)
。
- 收到成员信息变更回调
- 仅允许聊天室创建者和管理员调用该接口,否则返回错误码 109432。
- 如果被操作方为管理员,则仅允许聊天室创建者操作,否则返回错误码 109427。
- 不允许操作虚构用户和匿名游客。
参数说明
javavoid setTempChatBannedByTag(V2NIMChatroomTagTempChatBannedParams params, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
params |
V2NIMChatroomTagTempChatBannedParams |
是 | - | 聊天室成员临时禁言标签参数 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
objective-c- (void)setTempChatBannedByTag:(V2NIMChatroomTagTempChatBannedParams *)params
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
params |
V2NIMChatroomTagTempChatBannedParams |
是 | - | 聊天室成员临时禁言标签参数 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
cppvirtual void setTempChatBannedByTag(V2NIMChatroomTagTempChatBannedParams params,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
params |
V2NIMChatroomTagTempChatBannedParams |
是 | - | 聊天室成员临时禁言标签参数 |
success |
V2NIMSuccessCallback |
是 | - | 设置成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 设置失败回调,返回错误码。 |
typescriptsetTempChatBannedByTag(params: V2NIMChatroomTagTempChatBannedParams): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
params |
V2NIMChatroomTagTempChatBannedParams |
是 | - | 聊天室成员临时禁言标签参数 |
typescriptsetTempChatBannedByTag(params: V2NIMChatroomTagTempChatBannedParams): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
params |
V2NIMChatroomTagTempChatBannedParams |
是 | - | 聊天室成员临时禁言标签参数 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomTagTempChatBannedParams params = new V2NIMChatroomTagTempChatBannedParams();
//设置禁言的tag,必传字段,如果不传,会返回参数错误
params.setTargetTag("xxx");
//设置禁言时长,单位:秒,单次最大:30天,取消则设置为:0
params.setDuration(1000);
//是否需要通知,true:通知,false:不通知
params.setNotificationEnabled(true);
//设置通知扩展字段,可不传
params.setNotificationExtension("xxx");
v2ChatroomService.setTempChatBannedByTag(params, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
//设置成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
//设置失败
}
});
objective-c// 通过实例ID获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomTagTempChatBannedParams *params = [[V2NIMChatroomTagTempChatBannedParams alloc] init];
//设置禁言的tag,必传字段,如果不传,会返回参数错误
params.targetTag = @"xxx";
//设置禁言时长,单位:秒,单次最大:30天,取消则设置为:0
params.duration = 1000;
//是否需要通知,true:通知,false:不通知
params.notificationEnabled = YES;
//设置通知扩展字段,可不传
params.notificationExtension = @"xxx";
[service setTempChatBannedByTag:params
success:^()
{
// 设置成功
}
failure:^(V2NIMError *error)
{
// 设置失败
}];
cppV2NIMChatroomTagTempChatBannedParams params;
params.tags = "tag1";
params.duration = 60;
params.notificationEnabled = true;
params.notificationExtension = "notificationExtension";
chatroomService.setTempChatBannedByTag(
params,
[]() {
// set temp chat banned by tag succeeded
},
[](V2NIMError error) {
// set temp chat banned by tag failed, handle error
});
typescriptawait chatroomV2.V2NIMChatroomService.setTempChatBannedByTag(
{
"targetTag": "ccc", // 被禁言 tag
"notifyTargetTags": "{tag: \"ccc\"}", // 接收通知的目标表达式
"duration": 1000, // 禁言时长
"notificationEnabled": true // 是否通知
}
)
typescriptawait this.chatroomClient.chatroomService.setTempChatBannedByTag(
{
"targetTag": "ccc", // 被禁言 tag
"notifyTargetTags": "{tag: \"ccc\"}", // 接收通知的目标表达式
"duration": 1000, // 禁言时长
"notificationEnabled": true // 是否通知
}
)
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;设置成功,返回onSelfTempChatBannedUpdated
和onChatroomMemberInfoUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
设置成功,返回 onChatroomMemberInfoUpdated
回调。
updateSelfMemberInfo
接口描述
更新本人的聊天室成员信息。
本地端或多端同步更新成功后,聊天室内所有成员会收到:
- 成员信息变更回调
onChatroomMemberInfoUpdated
- 若
notificationEnabled
设置为 true,还会收到类型为V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_MEMBER_INFO_UPDATED(10)
的聊天室通知消息。
参数说明
javavoid updateSelfMemberInfo(V2NIMChatroomSelfMemberUpdateParams updateParams, V2NIMAntispamConfig antispamConfig,V2NIMSuccessCallback<Void> success, V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomSelfMemberUpdateParams |
是 | - | 本人聊天室成员信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
objective-c- (void)updateSelfMemberInfo:(V2NIMChatroomSelfMemberUpdateParams *)updateParams
antispamConfig:(nullable V2NIMAntispamConfig *)antispamConfig
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomSelfMemberUpdateParams |
是 | - | 本人聊天室成员信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
cppvirtual void updateSelfMemberInfo(V2NIMChatroomSelfMemberUpdateParams updateParams,
V2NIMAntispamConfig antispamConfig,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomSelfMemberUpdateParams |
是 | - | 本人聊天室成员信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
typescriptupdateSelfMemberInfo(updateParams: V2NIMChatroomSelfMemberUpdateParams, antispamConfig?: V2NIMAntispamConfig): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomSelfMemberUpdateParams |
是 | - | 本人聊天室成员信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
typescriptupdateSelfMemberInfo(updateParams: V2NIMChatroomSelfMemberUpdateParams, antispamConfig?: V2NIMAntispamConfig): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomSelfMemberUpdateParams |
是 | - | 本人聊天室成员信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomSelfMemberUpdateParams updateParams = new V2NIMChatroomSelfMemberUpdateParams();
// 设置聊天室中显示的昵称
updateParams.setRoomNick("xxx");
// 设置头像
updateParams.setRoomAvatar("xxx");
// 设置成员扩展字段
updateParams.setServerExtension("xxx");
// 以上三个字段至少需要设置一个,否则会返回参数错误
// 设置是否需要通知
updateParams.setNotificationEnabled(true);
// 设置本次操作生成的通知中的扩展字段
updateParams.setNotificationExtension("xxx");
// 设置更新信息持久化, 只针对固定成员身份生效
updateParams.setPersistence(true);
// 反垃圾配置,可不传
V2NIMAntispamConfig antispamConfig = new V2NIMAntispamConfig();
v2ChatroomService.updateSelfMemberInfo(updateParams, antispamConfig, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 更新成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 更新失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomSelfMemberUpdateParams *updateParams = [[V2NIMChatroomSelfMemberUpdateParams alloc] init];
// 设置聊天室中显示的昵称
updateParams.roomNick = @"xxx";
// 设置头像
updateParams.roomAvatar = @"xxx";
// 设置成员扩展字段
updateParams.serverExtension = @"xxx";
// 以上三个字段至少需要设置一个,否则会返回参数错误
// 设置是否需要通知
updateParams.notificationEnabled = YES;
// 设置本次操作生成的通知中的扩展字段
updateParams.notificationExtension = @"xxx";
// 设置更新信息持久化, 只针对固定成员身份生效
updateParams.persistence = YES;
// 反垃圾配置,可不传
V2NIMAntispamConfig *antispamConfig = [[V2NIMAntispamConfig alloc] init];
[service updateSelfMemberInfo:updateParams
antispamConfig:antispamConfig
success:^()
{
// 更新成功
}
failure:^(V2NIMError *error)
{
// 更新失败
}];
cppV2NIMChatroomSelfMemberUpdateParams updateParams;
updateParams.roomNick = "roomNick";
V2NIMAntispamConfig antispamConfig;
chatroomService.updateSelfMemberInfo(
updateParams,
antispamConfig,
[]() {
// update self member info succeeded
},
[](V2NIMError error) {
// update self member info failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.updateSelfMemberInfo({
roomNick: 'nick', // 聊天室昵称
roomAvatar: 'https://www.xxx.com/1.jpg', // 头像
serverExtension: 'extension', // 扩展字段
notificationEnabled: true, // 是否通知
persistence: true // 是否持久化。若为否,则信息在下线后失效
})
typescriptawait this.chatroomClient.chatroomService.updateSelfMemberInfo({
roomNick: 'nick', // 聊天室昵称
roomAvatar: 'https://www.xxx.com/1.jpg', // 头像
serverExtension: 'extension', //扩展字段
notificationEnabled: true, //是否通知
persistence: true //是否持久化。若为否,则信息在下线后失效
})
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;更新成功,返回onChatroomMemberInfoUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
更新成功,返回 onChatroomMemberInfoUpdated
回调。
updateChatroomInfo
接口描述
更新聊天室信息。
本地端或多端同步更新成功后,聊天室内所有成员会收到聊天室信息变更回调 onChatroomInfoUpdated
,以及聊天室通知消息,通知消息类型为 V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_ROOM_INFO_UPDATED(6)
。
参数说明
javavoid updateChatroomInfo(V2NIMChatroomUpdateParams updateParams, V2NIMAntispamConfig antispamConfig,V2NIMSuccessCallback<Void> success, V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomUpdateParams |
是 | - | 聊天室信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
objective-c- (void)updateChatroomInfo:(V2NIMChatroomUpdateParams *)updateParams
antispamConfig:(nullable V2NIMAntispamConfig *)antispamConfig
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomUpdateParams * |
是 | - | 聊天室信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
cppvirtual void updateChatroomInfo(V2NIMChatroomUpdateParams updateParams,
V2NIMAntispamConfig antispamConfig,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomUpdateParams |
是 | - | 聊天室信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
typescriptupdateChatroomInfo(updateParams: V2NIMChatroomUpdateParams, antispamConfig?: V2NIMAntispamConfig): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomUpdateParams |
是 | - | 聊天室信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
typescriptupdateChatroomInfo(updateParams: V2NIMChatroomUpdateParams, antispamConfig?: V2NIMAntispamConfig): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomUpdateParams |
是 | - | 聊天室信息更新参数 |
antispamConfig |
V2NIMAntispamConfig |
否 | null | 易盾反垃圾相关配置。 |
示例代码
java// 通过实例ID获取聊天室实例
V2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomUpdateParams updateParams = new V2NIMChatroomUpdateParams();
// 设置聊天室名称
updateParams.setRoomName("xxx");
// 设置聊天室公告
updateParams.setAnnouncement("xxx");
// 设置聊天室扩展字段
updateParams.setServerExtension("xxx");
// 设置聊天室直播地址
updateParams.setLiveUrl("xxx");
// 以上四个字段至少需要设置一个,否则会返回参数错误
// 设置是否需要通知
updateParams.setNotificationEnabled(true);
// 设置本次操作生成的通知中的扩展字段
updateParams.setNotificationExtension("xxx");
// 反垃圾配置,可不传
V2NIMAntispamConfig antispamConfig = new V2NIMAntispamConfig();
v2ChatroomService.updateChatroomInfo(updateParams, antispamConfig, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 更新成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 更新失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomUpdateParams *updateParams = [[V2NIMChatroomUpdateParams alloc] init];
// 设置聊天室名称
updateParams.roomName = @"xxx";
// 设置聊天室公告
updateParams.announcement = @"xxx";
// 设置聊天室扩展字段
updateParams.serverExtension = @"xxx";
// 设置聊天室直播地址
updateParams.liveUrl = @"xxx";
// 以上四个字段至少需要设置一个,否则会返回参数错误
// 设置是否需要通知
updateParams.notificationEnabled = true;
// 设置本次操作生成的通知中的扩展字段
updateParams.notificationExtension = @"xxx";
// 反垃圾配置,可不传
V2NIMAntispamConfig *antispamConfig = [[V2NIMAntispamConfig alloc] init];
[service updateChatroomInfo:updateParams
antispamConfig:antispamConfig
success:^()
{
// 设置成功
}
failure:^(V2NIMError *error)
{
// 设置失败
}];
cppV2NIMChatroomUpdateParams updateParams;
updateParams.roomName = "roomName";
V2NIMAntispamConfig antispamConfig;
chatroomService.updateChatroomInfo(
updateParams,
antispamConfig,
[]() {
// update chatroom info succeeded
},
[](V2NIMError error) {
// update chatroom info failed, handle error
});
typescriptawait chatroom.V2NIMChatroomService.updateChatroomInfo(
{
roomName: 'name',
annoucement: 'announcement',
serverExtension: 'serverExtension',
notificationEnabled: true,
notificationExtension: 'notificationExtension'
}
)
typescriptawait this.chatroomClient.chatroomService.updateChatroomInfo(
{
roomName: 'name',
annoucement: 'announcement',
serverExtension: 'serverExtension',
notificationEnabled: true,
notificationExtension: 'notificationExtension'
}
)
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;更新成功,返回onChatroomInfoUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
更新成功,返回 onChatroomMemberInfoUpdated
回调。
updateChatroomLocationInfo
接口描述
更新聊天室空间坐标信息。
参数说明
javavoid updateChatroomLocationInfo(V2NIMChatroomLocationConfig locationConfig, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
locationConfig |
V2NIMChatroomLocationConfig |
是 | - | 聊天室坐标信息配置参数 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
objective-c- (void)updateChatroomLocationInfo:(V2NIMChatroomLocationConfig *)locationConfig
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
locationConfig |
V2NIMChatroomLocationConfig * |
是 | - | 聊天室坐标信息配置参数 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
cppvirtual void updateChatroomLocationInfo(V2NIMChatroomLocationConfig locationConfig,
V2NIMSuccessCallback<void> success,
V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
locationConfig |
V2NIMChatroomLocationConfig |
是 | - | 聊天室坐标信息配置参数 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
typescriptupdateChatroomLocationInfo(locationConfig: V2NIMChatroomLocationConfig): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
locationConfig |
V2NIMChatroomLocationConfig |
是 | - | 聊天室坐标信息配置参数 |
typescriptupdateChatroomLocationInfo(locationConfig: V2NIMChatroomLocationConfig): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
locationConfig |
V2NIMChatroomLocationConfig |
是 | - | 聊天室坐标信息配置参数 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomLocationConfig locationConfig = new V2NIMChatroomLocationConfig();
V2NIMLocationInfo locationInfo = new V2NIMLocationInfo(0.0, 0.0, 0,0);
locationConfig.setLocationInfo(locationInfo);
locationConfig.setDistance(100);
// 以上两个字段必填,否则会返回参数错误
v2ChatroomService.updateChatroomLocationInfo(locationConfig, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 更新成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 更新失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomLocationConfig *locationConfig = [[V2NIMChatroomLocationConfig alloc] init];
V2NIMLocationInfo *locationInfo = [[V2NIMLocationInfo alloc] init];
locationConfig.locationInfo = locationInfo;
locationConfig.distance = 100;
// 以上两个字段必填,否则会返回参数错误
[service updateChatroomLocationInfo:locationConfig
success:^()
{
// 更新成功
}
failure:^(V2NIMError *error)
{
// 更新失败
}];
cppV2NIMChatroomLocationConfig locationConfig;
locationConfig.locationInfo.x = 1.0;
locationConfig.locationInfo.y = 1.0;
locationConfig.locationInfo.z = 1.0;
locationConfig.distance = 100;
chatroomService.updateChatroomLocationInfo(
locationConfig,
[]() {
// update chatroom location info succeeded
},
[](V2NIMError error) {
// update chatroom location info failed, handle error
});
typescriptawait chatroomV2.V2NIMChatroomService.updateChatroomLocationInfo(
{
"locationInfo": {
"x": 33,
"y": 44,
"z": 55
},
"distance": 77
}
)
typescriptawait this.chatroomClient.chatroomService.updateChatroomLocationInfo(
{
"locationInfo": {
"x": 33,
"y": 44,
"z": 55
},
"distance": 77
}
)
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
无
updateChatroomTags
接口描述
批量更新聊天室标签信息。
本地端或多端同步更新成功后,聊天室内所有成员会收到聊天室标签信息变更回调 onChatroomTagsUpdated
,以及聊天室通知消息,通知消息类型为 V2NIMChatroomMessageNotificationType.V2NIM_CHATROOM_MESSAGE_NOTIFICATION_TYPE_TAGS_UPDATE(17)
。
参数说明
javavoid updateChatroomTags(V2NIMChatroomTagsUpdateParams updateParams, V2NIMSuccessCallback<Void> success,
V2NIMFailureCallback failure);
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomTagsUpdateParams |
是 | - | 聊天室标签信息更新参数 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
objective-c- (void)updateChatroomTags:(V2NIMChatroomTagsUpdateParams *)updateParams
success:(nullable V2NIMSuccessCallback)success
failure:(nullable V2NIMFailureCallback)failure;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomTagsUpdateParams |
是 | - | 聊天室标签信息更新参数 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
cppvirtual void updateChatroomTags(V2NIMChatroomTagsUpdateParams updateParams, V2NIMSuccessCallback<void> success, V2NIMFailureCallback failure) = 0;
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomTagsUpdateParams |
是 | - | 聊天室标签信息更新参数 |
success |
V2NIMSuccessCallback |
是 | - | 更新成功回调 |
failure |
V2NIMFailureCallback |
是 | - | 更新失败回调,返回错误码。 |
typescriptupdateChatroomTags(updateParams: V2NIMChatroomtagsUpdateParams): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomTagsUpdateParams |
是 | - | 聊天室标签信息更新参数 |
typescriptupdateChatroomTags(updateParams: V2NIMChatroomtagsUpdateParams): Promise<void>
参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
---|---|---|---|---|
updateParams |
V2NIMChatroomTagsUpdateParams |
是 | - | 聊天室标签信息更新参数 |
示例代码
javaV2NIMChatroomClient v2ChatroomClient = V2NIMChatroomClient.getInstance(instanceId);
V2NIMChatroomService v2ChatroomService = v2ChatroomClient.getChatroomService();
V2NIMChatroomTagsUpdateParams updateParams = new V2NIMChatroomTagsUpdateParams();
// tag 列表
List<String> tags = getTags();
updateParams.setTags(tags);
updateParams.setNotifyTargetTags("xxx");
// 以上两个字段至少需要设置一个,否则会返回参数错误
v2ChatroomService.updateChatroomTags(updateParams, new V2NIMSuccessCallback<Void>() {
@Override
public void onSuccess(Void unused) {
// 更新成功
}
}, new V2NIMFailureCallback() {
@Override
public void onFailure(V2NIMError error) {
// 更新失败
}
});
objective-c// 通过实例 ID 获取聊天室实例
id <V2NIMChatroomService> service = [[V2NIMChatroomClient getInstance:1] getChatroomService];
V2NIMChatroomTagsUpdateParams *updateParams = [[V2NIMChatroomTagsUpdateParams alloc] init];
// tag 列表
NSArray<NSString *> *tags = @[ @"tag0", @"tag1" ]];
updateParams.tags = tags;
updateParams.notifyTargetTags = @"xxx";
// 以上两个字段至少需要设置一个,否则会返回参数错误
[service updateChatroomTags:updateParams
success:^()
{
// 更新成功
}
failure:^(V2NIMError *error)
{
// 更新失败
}];
cppV2NIMChatroomTagsUpdateParams updateParams;
updateParams.tags = {"tag1", "tag2"};
updateParams.notifyTargetTags = R"({"tag": "tag1"})";
chatroomService.updateChatroomTags(
updateParams,
[]() {
// update chatroom tags succeeded
},
[](V2NIMError error) {
// update chatroom tags failed, handle error
});
typescriptawait chatroomV2.V2NIMChatroomService.updateChatroomTags(
{
"tags": [
"tag1",
"tag2"
],
"notifyTargetTags": "{tag: \"tag1\"}",
"notificationEnabled": true,
"notificationExtension": "notificationExtension"
}
)
typescriptawait this.chatroomClient.chatroomService.updateChatroomTags(
{
"tags": [
"tag1",
"tag2"
],
"notifyTargetTags": "{tag: \"tag1\"}",
"notificationEnabled": true,
"notificationExtension": "notificationExtension"
}
)
返回值
无返回值
Promise<void>
相关回调
- 请求成功,返回
V2NIMSuccessCallback
回调;更新成功,返回onChatroomTagsUpdated
回调。 - 请求失败,返回
V2NIMFailuerCallback
回调,包含聊天室相关错误码。
更新成功,返回 onChatroomTagsUpdated
回调。