diff --git a/broker/config/hazelcast.xml b/broker/config/hazelcast.xml index b9260a8b..de68a680 100755 --- a/broker/config/hazelcast.xml +++ b/broker/config/hazelcast.xml @@ -90,6 +90,12 @@ + + + + + + 604800 diff --git a/broker/migrate/h2/V25__create_chatroom_blacklist_manager.sql b/broker/migrate/h2/V25__create_chatroom_blacklist_manager.sql new file mode 100755 index 00000000..cf66585d --- /dev/null +++ b/broker/migrate/h2/V25__create_chatroom_blacklist_manager.sql @@ -0,0 +1,22 @@ + +DROP TABLE IF EXISTS `t_chatroom_blacklist`; +CREATE TABLE `t_chatroom_blacklist` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `_cid` varchar(64) NOT NULL, + `_uid` varchar(64) NOT NULL, + `_state` tinyint NOT NULL DEFAULT 0, + `_expired_time` bigint(20) NOT NULL, + `_dt` bigint(20) NOT NULL, + UNIQUE INDEX `cr_bl_uid_index` (`_cid`,_uid) +); + +DROP TABLE IF EXISTS `t_chatroom_manager`; +CREATE TABLE `t_chatroom_manager` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `_cid` varchar(64) NOT NULL, + `_uid` varchar(64) NOT NULL, + `_state` tinyint NOT NULL DEFAULT 0, + `_dt` bigint(20) NOT NULL, + UNIQUE INDEX `cr_man_uid_index` (`_cid`,_uid) +); + diff --git a/broker/migrate/mysql/V30__create_chatroom_blacklist_manager.sql b/broker/migrate/mysql/V30__create_chatroom_blacklist_manager.sql new file mode 100755 index 00000000..5ed4ed3c --- /dev/null +++ b/broker/migrate/mysql/V30__create_chatroom_blacklist_manager.sql @@ -0,0 +1,30 @@ + +DROP TABLE IF EXISTS `t_chatroom_blacklist`; +CREATE TABLE `t_chatroom_blacklist` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `_cid` varchar(64) NOT NULL, + `_uid` varchar(64) NOT NULL, + `_state` tinyint NOT NULL DEFAULT 0, + `_expired_time` bigint(20) NOT NULL, + `_dt` bigint(20) NOT NULL, + UNIQUE INDEX `cr_bl_uid_index` (`_cid`,_uid) +) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `t_chatroom_manager`; +CREATE TABLE `t_chatroom_manager` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `_cid` varchar(64) NOT NULL, + `_uid` varchar(64) NOT NULL, + `_state` tinyint NOT NULL DEFAULT 0, + `_dt` bigint(20) NOT NULL, + UNIQUE INDEX `cr_man_uid_index` (`_cid`,_uid) +) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_unicode_ci; + + + diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index a068fd97..2428ea65 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -5,6 +5,11 @@ public interface APIPath { String Chatroom_Destroy = "/admin/chatroom/del"; String Chatroom_Info = "/admin/chatroom/info"; String Chatroom_GetMembers = "/admin/chatroom/members"; + String Chatroom_SetBlacklist = "/admin/chatroom/set_black_status"; + String Chatroom_GetBlacklist = "/admin/chatroom/get_black_status"; + String Chatroom_SetManager = "/admin/chatroom/set_manager"; + String Chatroom_GetManagerList = "/admin/chatroom/get_manager_list"; + String Chatroom_MuteAll = "/admin/chatroom/mute_all"; String Sensitive_Add = "/admin/sensitive/add"; diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputChatroomId.java b/common/src/main/java/cn/wildfirechat/pojos/InputChatroomId.java new file mode 100644 index 00000000..b8e2007b --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputChatroomId.java @@ -0,0 +1,12 @@ +package cn.wildfirechat.pojos; + +public class InputChatroomId { + public String chatroomId; + + public InputChatroomId() { + } + + public InputChatroomId(String chatroomId) { + this.chatroomId = chatroomId; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputChatroomMute.java b/common/src/main/java/cn/wildfirechat/pojos/InputChatroomMute.java new file mode 100755 index 00000000..0ba22d32 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputChatroomMute.java @@ -0,0 +1,36 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + + +public class InputChatroomMute { + private String chatroomId; + private int status; + + public InputChatroomMute(String chatroomId, int status) { + this.chatroomId = chatroomId; + this.status = status; + } + + public String getChatroomId() { + return chatroomId; + } + + public void setChatroomId(String chatroomId) { + this.chatroomId = chatroomId; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputSetChatroomBlacklist.java b/common/src/main/java/cn/wildfirechat/pojos/InputSetChatroomBlacklist.java new file mode 100755 index 00000000..b9f0dec5 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputSetChatroomBlacklist.java @@ -0,0 +1,58 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +public class InputSetChatroomBlacklist { + private String chatroomId; + private String userId; + private int status; + private long expiredTime; + + public InputSetChatroomBlacklist() { + } + + public InputSetChatroomBlacklist(String chatroomId, String userId, int status, long expiredTime) { + this.chatroomId = chatroomId; + this.userId = userId; + this.status = status; + this.expiredTime = expiredTime; + } + + public String getChatroomId() { + return chatroomId; + } + + public void setChatroomId(String chatroomId) { + this.chatroomId = chatroomId; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public long getExpiredTime() { + return expiredTime; + } + + public void setExpiredTime(long expiredTime) { + this.expiredTime = expiredTime; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputSetChatroomManager.java b/common/src/main/java/cn/wildfirechat/pojos/InputSetChatroomManager.java new file mode 100755 index 00000000..89ac50d6 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputSetChatroomManager.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +public class InputSetChatroomManager { + private String chatroomId; + private String userId; + private int status; + + public InputSetChatroomManager() { + } + + public InputSetChatroomManager(String chatroomId, String userId, int status) { + this.chatroomId = chatroomId; + this.userId = userId; + this.status = status; + } + + public String getChatroomId() { + return chatroomId; + } + + public void setChatroomId(String chatroomId) { + this.chatroomId = chatroomId; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputChatroomBlackInfos.java b/common/src/main/java/cn/wildfirechat/pojos/OutputChatroomBlackInfos.java new file mode 100644 index 00000000..e34c40e9 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputChatroomBlackInfos.java @@ -0,0 +1,25 @@ +package cn.wildfirechat.pojos; + +import java.util.ArrayList; +import java.util.List; + +public class OutputChatroomBlackInfos { + public static class OutputChatroomBlackInfo { + public String userId; + public int state; + public long expiredTime; + + public OutputChatroomBlackInfo() { + } + + public OutputChatroomBlackInfo(String userId, int state, long expiredTime) { + this.userId = userId; + this.state = state; + this.expiredTime = expiredTime; + } + } + public List infos = new ArrayList<>(); + public void addBlackInfo(String userId, int state, long expiredTime) { + infos.add(new OutputChatroomBlackInfo(userId, state, expiredTime)); + } +} diff --git a/distribution/src/main/resources/hazelcast.xml b/distribution/src/main/resources/hazelcast.xml index 553b6907..aa8341e7 100755 --- a/distribution/src/main/resources/hazelcast.xml +++ b/distribution/src/main/resources/hazelcast.xml @@ -84,6 +84,12 @@ + + + + + + 604800 diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/ChatroomAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/ChatroomAdmin.java index 9e6bf161..f2701204 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/ChatroomAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/ChatroomAdmin.java @@ -37,6 +37,37 @@ public class ChatroomAdmin { return AdminHttpUtils.httpJsonPost(path, input, OutputStringList.class); } + //仅专业版支持 + //status:0,正常;1,禁言;2,禁止加入 + public static IMResult 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 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 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 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 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); + } - } diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 3d34e417..6e670bb9 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -575,6 +575,105 @@ public class Main { System.out.println("chatroom not destroyed!"); System.exit(-1); } + + //下面仅专业版支持 + /* + //设置用户聊天室黑名单。0正常;1禁言;2禁止加入。 + IMResult 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 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 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 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 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 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 {