修改重构引入的部分问题
This commit is contained in:
+1
-1
@@ -46,7 +46,7 @@ public class AddFriendRequestAction extends AdminAction {
|
|||||||
byteBuf.writeBytes(result);
|
byteBuf.writeBytes(result);
|
||||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||||
return new Result(errorCode);
|
return new Result(errorCode);
|
||||||
});
|
}, !input.isForce());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -92,9 +92,16 @@ abstract public class AdminAction extends Action {
|
|||||||
response.setContent(new Gson().toJson(result));
|
response.setContent(new Gson().toJson(result));
|
||||||
response.send();
|
response.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendApiMessage(String fromUser, String topic, byte[] message, ApiCallback callback) {
|
protected void sendApiMessage(String fromUser, String topic, byte[] message, ApiCallback callback) {
|
||||||
ServerAPIHelper.sendRequest(fromUser, null, topic, message, new ServerAPIHelper.Callback() {
|
sendApiMessage(fromUser, null, topic, message, callback, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendApiMessage(String fromUser, String topic, byte[] message, ApiCallback callback, boolean noAdmin) {
|
||||||
|
sendApiMessage(fromUser, null, topic, message, callback, noAdmin);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendApiMessage(String fromUser, String clientId, String topic, byte[] message, ApiCallback callback, boolean noAdmin) {
|
||||||
|
ServerAPIHelper.sendRequest(fromUser, clientId, topic, message, new ServerAPIHelper.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(byte[] result) {
|
public void onSuccess(byte[] result) {
|
||||||
if(callback != null) {
|
if(callback != null) {
|
||||||
@@ -119,6 +126,6 @@ abstract public class AdminAction extends Action {
|
|||||||
ctx.executor().execute(command);
|
ctx.executor().execute(command);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, true);
|
}, !noAdmin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class GetIMTokenAction extends AdminAction {
|
|||||||
|
|
||||||
|
|
||||||
WFCMessage.GetTokenRequest getTokenRequest = WFCMessage.GetTokenRequest.newBuilder().setUserId(userId).setClientId(input.getClientId()).setPlatform(input.getPlatform() == null ? 0 : input.getPlatform()).build();
|
WFCMessage.GetTokenRequest getTokenRequest = WFCMessage.GetTokenRequest.newBuilder().setUserId(userId).setClientId(input.getClientId()).setPlatform(input.getPlatform() == null ? 0 : input.getPlatform()).build();
|
||||||
sendApiMessage(userId, IMTopic.GetTokenTopic, getTokenRequest.toByteArray(), result -> {
|
sendApiMessage(userId, input.getClientId(), IMTopic.GetTokenTopic, getTokenRequest.toByteArray(), result -> {
|
||||||
ErrorCode errorCode1 = ErrorCode.fromCode(result[0]);
|
ErrorCode errorCode1 = ErrorCode.fromCode(result[0]);
|
||||||
if (errorCode1 == ErrorCode.ERROR_CODE_SUCCESS) {
|
if (errorCode1 == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
//ba errorcode qudiao
|
//ba errorcode qudiao
|
||||||
@@ -52,7 +52,7 @@ public class GetIMTokenAction extends AdminAction {
|
|||||||
} else {
|
} else {
|
||||||
return new Result(errorCode1);
|
return new Result(errorCode1);
|
||||||
}
|
}
|
||||||
});
|
}, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -116,7 +116,10 @@ abstract public class ChannelAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void sendApiMessage(String topic, byte[] message, Callback callback) {
|
protected void sendApiMessage(String topic, byte[] message, Callback callback) {
|
||||||
ServerAPIHelper.sendRequest(channelInfo.getOwner(), null, topic, message, new ServerAPIHelper.Callback() {
|
sendApiMessage(channelInfo.getOwner(), topic, message, callback);
|
||||||
|
}
|
||||||
|
protected void sendApiMessage(String user, String topic, byte[] message, Callback callback) {
|
||||||
|
ServerAPIHelper.sendRequest(user, null, topic, message, new ServerAPIHelper.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(byte[] response) {
|
public void onSuccess(byte[] response) {
|
||||||
callback.onSuccess(response);
|
callback.onSuccess(response);
|
||||||
|
|||||||
+2
-3
@@ -19,7 +19,6 @@ import com.xiaoleilu.loServer.RestResult;
|
|||||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||||
import com.xiaoleilu.loServer.annotation.Route;
|
import com.xiaoleilu.loServer.annotation.Route;
|
||||||
import com.xiaoleilu.loServer.handler.Request;
|
import com.xiaoleilu.loServer.handler.Request;
|
||||||
import com.xiaoleilu.loServer.handler.Response;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
@@ -34,7 +33,7 @@ public class SubscriberChannelAction extends ChannelAction {
|
|||||||
public boolean action(Request request) {
|
public boolean action(Request request) {
|
||||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
InputChannelSubscribe input = getRequestBody(request.getNettyRequest(), InputChannelSubscribe.class);
|
InputChannelSubscribe input = getRequestBody(request.getNettyRequest(), InputChannelSubscribe.class);
|
||||||
if (input != null && !StringUtil.isNullOrEmpty(input.getTarget())) {
|
if (input != null && !StringUtil.isNullOrEmpty(input.getUserId())) {
|
||||||
if(input.getSubscribe() > 0 && (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Active_Subscribe) == 0) {
|
if(input.getSubscribe() > 0 && (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Active_Subscribe) == 0) {
|
||||||
response.setStatus(HttpResponseStatus.OK);
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
RestResult result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_RIGHT);
|
RestResult result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_RIGHT);
|
||||||
@@ -42,7 +41,7 @@ public class SubscriberChannelAction extends ChannelAction {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
WFCMessage.ListenChannel listenChannel = WFCMessage.ListenChannel.newBuilder().setChannelId(channelInfo.getTargetId()).setListen(input.getSubscribe()).build();
|
WFCMessage.ListenChannel listenChannel = WFCMessage.ListenChannel.newBuilder().setChannelId(channelInfo.getTargetId()).setListen(input.getSubscribe()).build();
|
||||||
sendApiMessage(IMTopic.ChannelListenTopic, listenChannel.toByteArray(), result -> {
|
sendApiMessage(input.getUserId(), IMTopic.ChannelListenTopic, listenChannel.toByteArray(), result -> {
|
||||||
ByteBuf byteBuf = Unpooled.buffer();
|
ByteBuf byteBuf = Unpooled.buffer();
|
||||||
byteBuf.writeBytes(result);
|
byteBuf.writeBytes(result);
|
||||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||||
|
|||||||
@@ -8,22 +8,16 @@
|
|||||||
|
|
||||||
package cn.wildfirechat.pojos;
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class InputChannelSubscribe {
|
public class InputChannelSubscribe {
|
||||||
private String target;
|
private String userId;
|
||||||
private int subscribe; //1,订阅;0,取消订阅
|
private int subscribe; //1,订阅;0,取消订阅
|
||||||
|
|
||||||
public String getTarget() {
|
public String getUserId() {
|
||||||
return target;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTarget(String target) {
|
public void setUserId(String userId) {
|
||||||
this.target = target;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSubscribe() {
|
public int getSubscribe() {
|
||||||
|
|||||||
@@ -2,11 +2,8 @@ package cn.wildfirechat.sdk;
|
|||||||
|
|
||||||
import cn.wildfirechat.common.APIPath;
|
import cn.wildfirechat.common.APIPath;
|
||||||
import cn.wildfirechat.pojos.*;
|
import cn.wildfirechat.pojos.*;
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
|
||||||
import cn.wildfirechat.sdk.model.IMResult;
|
import cn.wildfirechat.sdk.model.IMResult;
|
||||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
|
||||||
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
|
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
|
||||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -61,15 +58,15 @@ public class ChannelServiceApi {
|
|||||||
public IMResult<Void> subscribe(String target) throws Exception {
|
public IMResult<Void> subscribe(String target) throws Exception {
|
||||||
String path = APIPath.Channel_Subscribe;
|
String path = APIPath.Channel_Subscribe;
|
||||||
InputChannelSubscribe input = new InputChannelSubscribe();
|
InputChannelSubscribe input = new InputChannelSubscribe();
|
||||||
input.setTarget(target);
|
input.setUserId(target);
|
||||||
input.setSubscribe(1);
|
input.setSubscribe(1);
|
||||||
return httpUtils.httpJsonPost(path, input, Void.class);
|
return httpUtils.httpJsonPost(path, input, Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMResult<Void> unsubscribe(String target) throws Exception {
|
public IMResult<Void> unsubscribe(String userId) throws Exception {
|
||||||
String path = APIPath.Channel_Subscribe;
|
String path = APIPath.Channel_Subscribe;
|
||||||
InputChannelSubscribe input = new InputChannelSubscribe();
|
InputChannelSubscribe input = new InputChannelSubscribe();
|
||||||
input.setTarget(target);
|
input.setUserId(userId);
|
||||||
input.setSubscribe(0);
|
input.setSubscribe(0);
|
||||||
return httpUtils.httpJsonPost(path, input, Void.class);
|
return httpUtils.httpJsonPost(path, input, Void.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1200,7 +1200,6 @@ public class Main {
|
|||||||
System.out.println("subscribe failure");
|
System.out.println("subscribe failure");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
|
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
|
||||||
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
|
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
|
||||||
System.out.println("get subscriber done");
|
System.out.println("get subscriber done");
|
||||||
|
|||||||
Reference in New Issue
Block a user