add chatroom api

This commit is contained in:
imhao183
2020-04-02 22:50:04 +08:00
parent 83eae385b3
commit 1047db9990
12 changed files with 379 additions and 1 deletions
@@ -37,6 +37,37 @@ public class ChatroomAdmin {
return AdminHttpUtils.httpJsonPost(path, input, OutputStringList.class);
}
//仅专业版支持
//status:0,正常;1,禁言;2,禁止加入
public static IMResult<Void> setChatroomBlacklist(String chatroomId, String userId, int status) throws Exception {
String path = APIPath.Chatroom_SetBlacklist;
InputSetChatroomBlacklist input = new InputSetChatroomBlacklist(chatroomId, userId, status, 0);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
public static IMResult<OutputChatroomBlackInfos> getChatroomBlacklist(String chatroomId) throws Exception {
String path = APIPath.Chatroom_GetBlacklist;
InputChatroomId input = new InputChatroomId(chatroomId);
return AdminHttpUtils.httpJsonPost(path, input, OutputChatroomBlackInfos.class);
}
//status: 1 set; 0 unset
public static IMResult<Void> setChatroomManager(String chatroomId, String userId, int status) throws Exception {
String path = APIPath.Chatroom_SetManager;
InputSetChatroomManager input = new InputSetChatroomManager(chatroomId, userId, status);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
public static IMResult<OutputStringList> getChatroomManagerList(String chatroomId) throws Exception {
String path = APIPath.Chatroom_GetManagerList;
InputChatroomId input = new InputChatroomId(chatroomId);
return AdminHttpUtils.httpJsonPost(path, input, OutputStringList.class);
}
public static IMResult<Void> setChatroomMute(String chatroomId, boolean mute) throws Exception {
String path = APIPath.Chatroom_MuteAll;
InputChatroomMute input = new InputChatroomMute(chatroomId, mute ? 1 : 0);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
}
@@ -575,6 +575,105 @@ public class Main {
System.out.println("chatroom not destroyed!");
System.exit(-1);
}
//下面仅专业版支持
/*
//设置用户聊天室黑名单。0正常;1禁言;2禁止加入。
IMResult<Void> voidIMResult1 = ChatroomAdmin.setChatroomBlacklist("chatroom1", "oto9o9__", 1);
if (voidIMResult1 != null && voidIMResult1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("add chatroom black success");
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}
//获取聊天室黑名单
IMResult<OutputChatroomBlackInfos> blackInfos = ChatroomAdmin.getChatroomBlacklist("chatroom1");
if (blackInfos != null && blackInfos.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && !blackInfos.getResult().infos.isEmpty()) {
boolean success = false;
for (OutputChatroomBlackInfos.OutputChatroomBlackInfo info : blackInfos.getResult().infos) {
if (info.userId.equals("oto9o9__")) {
success = true;
break;
}
}
if (success) {
System.out.println("add chatroom black success");
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}
//取消用户聊天室黑名单。0正常;1禁言;2禁止加入。
voidIMResult1 = ChatroomAdmin.setChatroomBlacklist("chatroom1", "oto9o9__", 0);
if (voidIMResult1 != null && voidIMResult1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("remove chatroom black success");
} else {
System.out.println("remove chatroom black failure");
System.exit(-1);
}
//获取聊天室黑名单
blackInfos = ChatroomAdmin.getChatroomBlacklist("chatroom1");
if (blackInfos != null && blackInfos.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
boolean success = true;
for (OutputChatroomBlackInfos.OutputChatroomBlackInfo info : blackInfos.getResult().infos) {
if (info.userId.equals("oto9o9__")) {
success = false;
break;
}
}
if (success) {
System.out.println("remove chatroom black success");
} else {
System.out.println("remove chatroom black failure");
System.exit(-1);
}
} else {
System.out.println("remove chatroom black failure");
System.exit(-1);
}
//设置聊天室管理员
IMResult<Void> voidIMResult2 = ChatroomAdmin.setChatroomManager("chatroom1", "UserId1", 1);
if (voidIMResult2 != null && voidIMResult2.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("add chatroom manager success");
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}
//获取聊天室管理员
IMResult<OutputStringList> managers = ChatroomAdmin.getChatroomManagerList("chatroom1");
if (managers != null && managers.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && !managers.getResult().getList().isEmpty() && managers.getResult().getList().contains("UserId1")) {
System.out.println("add chatroom black success");
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}
//取消聊天室管理员
IMResult<Void> voidIMResult3 = ChatroomAdmin.setChatroomManager("chatroom1", "UserId1", 0);
if (voidIMResult3 != null && voidIMResult3.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("add chatroom manager success");
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}
//获取聊天室管理员
IMResult<OutputStringList> managers2 = ChatroomAdmin.getChatroomManagerList("chatroom1");
if (managers2 != null && managers2.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && !managers2.getResult().getList().contains("UserId1")) {
System.out.println("add chatroom black success");
} else {
System.out.println("add chatroom black failure");
System.exit(-1);
}*/
}
static void testRobot() throws Exception {