添加检查是否订阅频道server api

This commit is contained in:
heavyrian2012
2022-08-26 15:16:48 +08:00
parent 9fa33159c8
commit 650ffa14e2
4 changed files with 81 additions and 1 deletions
@@ -0,0 +1,52 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* 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;
}
}
@@ -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";
@@ -0,0 +1,21 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* 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;
}
@@ -45,7 +45,13 @@ public class GeneralAdmin {
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
public static IMResult<Void> unsubscribeChannel(String channelId, String userId) throws Exception {
public static IMResult<OutputBooleanValue> 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<Void> 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);