diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserSubscribeChannelAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserSubscribeChannelAction.java new file mode 100755 index 00000000..77123a02 --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserSubscribeChannelAction.java @@ -0,0 +1,52 @@ +/* + * 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.InputChannelId; +import cn.wildfirechat.pojos.InputSubscribeChannel; +import cn.wildfirechat.pojos.OutputBooleanValue; +import cn.wildfirechat.pojos.OutputGetChannelInfo; +import cn.wildfirechat.proto.WFCMessage; +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.netty.handler.codec.http.FullHttpRequest; +import io.netty.util.internal.StringUtil; + +@Route(APIPath.Check_User_Subscribe_Channel) +@HttpMethod("POST") +public class CheckUserSubscribeChannelAction extends AdminAction { + + @Override + public boolean isTransactionAction() { + return true; + } + + @Override + public boolean action(Request request, Response response) { + if (request.getNettyRequest() instanceof FullHttpRequest) { + InputSubscribeChannel inputSubscribeChannel = getRequestBody(request.getNettyRequest(), InputSubscribeChannel.class); + if (inputSubscribeChannel != null + && !StringUtil.isNullOrEmpty(inputSubscribeChannel.getChannelId()) + && !StringUtil.isNullOrEmpty(inputSubscribeChannel.getUserId())) { + boolean isInChannel = messagesStore.checkUserInChannel(inputSubscribeChannel.getUserId(), inputSubscribeChannel.getChannelId()); + OutputBooleanValue outputBooleanValue = new OutputBooleanValue(); + outputBooleanValue.value = isInChannel; + setResponseContent(RestResult.ok(outputBooleanValue), response); + } else { + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); + } + } + return true; + } +} diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index b62015a4..9fddf65e 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -81,6 +81,7 @@ public interface APIPath { String Destroy_Channel = "/admin/channel/destroy"; String Get_Channel_Info = "/admin/channel/get"; String Subscribe_Channel = "/admin/channel/subscribe"; + String Check_User_Subscribe_Channel = "/admin/channel/is_subscribed"; String Get_System_Setting = "/admin/system/get_setting"; String Put_System_Setting = "/admin/system/put_setting"; diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputBooleanValue.java b/common/src/main/java/cn/wildfirechat/pojos/OutputBooleanValue.java new file mode 100755 index 00000000..4c489be6 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputBooleanValue.java @@ -0,0 +1,21 @@ +/* + * 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.ArrayList; +import java.util.List; + +public class OutputBooleanValue { + public boolean value; +} + diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java index 37f1f89d..6141f6eb 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java @@ -45,7 +45,13 @@ public class GeneralAdmin { return AdminHttpUtils.httpJsonPost(path, input, Void.class); } - public static IMResult unsubscribeChannel(String channelId, String userId) throws Exception { + public static IMResult unsubscribeChannel(String channelId, String userId) throws Exception { + String path = APIPath.Check_User_Subscribe_Channel; + InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0); + return AdminHttpUtils.httpJsonPost(path, input, OutputBooleanValue.class); + } + + public static IMResult isUserSubscribedChannel(String userId, String channelId) throws Exception { String path = APIPath.Subscribe_Channel; InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0); return AdminHttpUtils.httpJsonPost(path, input, Void.class);