diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java new file mode 100755 index 00000000..7a2d010b --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java @@ -0,0 +1,85 @@ +/* + * 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 com.xiaoleilu.loServer.action.admin; + + +import cn.wildfirechat.common.APIPath; +import cn.wildfirechat.common.ErrorCode; +import cn.wildfirechat.pojos.InputAddGroupMember; +import cn.wildfirechat.pojos.InputSetGroupManager; +import com.google.gson.Gson; +import com.xiaoleilu.loServer.RestResult; +import com.xiaoleilu.loServer.annotation.HttpMethod; +import com.xiaoleilu.loServer.annotation.Route; +import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; +import io.moquette.persistence.RPCCenter; +import io.moquette.persistence.TargetEntry; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpResponseStatus; +import win.liyufan.im.IMTopic; + +import java.util.concurrent.Executor; + +@Route(APIPath.Group_Set_Manager) +@HttpMethod("POST") +public class SetGroupManagerAction extends AdminAction { + + @Override + public boolean isTransactionAction() { + return true; + } + + @Override + public boolean action(Request request, Response response) { + if (request.getNettyRequest() instanceof FullHttpRequest) { + InputSetGroupManager inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputSetGroupManager.class); + if (inputAddGroupMember.isValide()) { + RPCCenter.getInstance().sendRequest(inputAddGroupMember.getOperator(), null, IMTopic.SetGroupManagerTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), inputAddGroupMember.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() { + @Override + public void onSuccess(byte[] result) { + ByteBuf byteBuf = Unpooled.buffer(); + byteBuf.writeBytes(result); + ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); + if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { + sendResponse(response, null, null); + } else { + sendResponse(response, errorCode, null); + } + } + + @Override + public void onError(ErrorCode errorCode) { + sendResponse(response, errorCode, null); + } + + @Override + public void onTimeout() { + sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null); + } + + @Override + public Executor getResponseExecutor() { + return command -> { + ctx.executor().execute(command); + }; + } + }, true); + return false; + } else { + response.setStatus(HttpResponseStatus.OK); + RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER); + response.setContent(new Gson().toJson(result)); + } + } + return true; + } +} diff --git a/common/src/main/java/cn.wildfirechat.pojos/InputSetGroupManager.java b/common/src/main/java/cn.wildfirechat.pojos/InputSetGroupManager.java new file mode 100755 index 00000000..6e78d8ab --- /dev/null +++ b/common/src/main/java/cn.wildfirechat.pojos/InputSetGroupManager.java @@ -0,0 +1,72 @@ +/* + * 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; + + +import cn.wildfirechat.proto.WFCMessage; +import io.netty.util.internal.StringUtil; + +import java.util.List; + +public class InputSetGroupManager extends InputGroupBase { + private String group_id; + private List members; + private boolean is_manager; + + public String getGroup_id() { + return group_id; + } + + public void setGroup_id(String group_id) { + this.group_id = group_id; + } + + public List getMembers() { + return members; + } + + public void setMembers(List members) { + this.members = members; + } + + public boolean isIs_manager() { + return is_manager; + } + + public void setIs_manager(boolean is_manager) { + this.is_manager = is_manager; + } + + public boolean isValide() { + if (StringUtil.isNullOrEmpty(operator) || StringUtil.isNullOrEmpty(group_id) || members == null || members.isEmpty()) { + return false; + } + return true; + } + + public WFCMessage.SetGroupManagerRequest toProtoGroupRequest() { + WFCMessage.SetGroupManagerRequest.Builder addGroupBuilder = WFCMessage.SetGroupManagerRequest.newBuilder(); + addGroupBuilder.setGroupId(group_id); + addGroupBuilder.addAllUserId(members); + addGroupBuilder.setType(is_manager ? 1 : 0); + + if (to_lines != null) { + for (Integer line : to_lines + ) { + addGroupBuilder.addToLine(line); + } + } + + if (notify_message != null) { + addGroupBuilder.setNotifyContent(notify_message.toProtoMessageContent()); + } + return addGroupBuilder.build(); + } + +} diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index 06f6b23e..e964f51e 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -36,6 +36,7 @@ public interface APIPath { String Group_Member_List = "/admin/group/member/list"; String Group_Member_Add = "/admin/group/member/add"; String Group_Member_Kickoff = "/admin/group/member/del"; + String Group_Set_Manager = "/admin/group/manager/set"; String Create_Channel = "/admin/channel/create"; diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/GroupAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/GroupAdmin.java index fe36fb46..ae58b274 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/GroupAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/GroupAdmin.java @@ -88,6 +88,20 @@ public class GroupAdmin { return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class); } + public static IMResult setGroupManager(String operator, String groupId, List groupMemberIds, boolean isManager, List to_lines, MessagePayload notify_message) throws Exception { + String path = APIPath.Group_Set_Manager; + InputSetGroupManager addGroupMember = new InputSetGroupManager(); + addGroupMember.setGroup_id(groupId); + addGroupMember.setMembers(groupMemberIds); + addGroupMember.setIs_manager(isManager); + addGroupMember.setOperator(operator); + addGroupMember.setTo_lines(to_lines); + addGroupMember.setNotify_message(notify_message); + return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class); + } + + + public static IMResult kickoffGroupMembers(String operator, String groupId, List groupMemberIds, List to_lines, MessagePayload notify_message) throws Exception { String path = APIPath.Group_Member_Kickoff; InputKickoffGroupMember kickoffGroupMember = new InputKickoffGroupMember(); diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index efbec28f..41d693f7 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -268,6 +268,24 @@ public class Main { System.exit(-1); } + voidIMResult = GroupAdmin.setGroupManager("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), true, null, null); + if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { + System.out.println("set group manager success"); + } else { + System.out.println("set group manager failure"); + System.exit(-1); + } + + voidIMResult = GroupAdmin.setGroupManager("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), false, null, null); + if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { + System.out.println("cancel group manager success"); + } else { + System.out.println("cancel group manager failure"); + System.exit(-1); + } + + + //*********************************************** //**** 消息相关功能 //***********************************************