修复部分接口
This commit is contained in:
+94
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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.*;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
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 io.netty.util.internal.StringUtil;
|
||||||
|
import win.liyufan.im.IMTopic;
|
||||||
|
import win.liyufan.im.UUIDGenerator;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
@Route(APIPath.Create_Channel)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class CreateChannelAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputCreateChannel inputCreateChannel = getRequestBody(request.getNettyRequest(), InputCreateChannel.class);
|
||||||
|
if (inputCreateChannel != null
|
||||||
|
&& !StringUtil.isNullOrEmpty(inputCreateChannel.getName())) {
|
||||||
|
|
||||||
|
|
||||||
|
if(StringUtil.isNullOrEmpty(inputCreateChannel.getTargetId())) {
|
||||||
|
inputCreateChannel.setTargetId(messagesStore.getShortUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
RPCCenter.getInstance().sendRequest(inputCreateChannel.getOwner(), null, IMTopic.CreateChannelTopic, inputCreateChannel.toProtoChannelInfo().toByteArray(), inputCreateChannel.getOwner(), 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, new OutputCreateChannel(inputCreateChannel.getTargetId()));
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ import java.util.Set;
|
|||||||
public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.INT64Buf int64Buf, Qos1PublishHandler.IMCallback callback) {
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.INT64Buf int64Buf, Qos1PublishHandler.IMCallback callback) {
|
||||||
ErrorCode errorCode = m_messagesStore.recallMessage(int64Buf.getId(), fromUser);
|
ErrorCode errorCode = m_messagesStore.recallMessage(int64Buf.getId(), fromUser, isAdmin);
|
||||||
|
|
||||||
if(errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
if(errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
|
|||||||
@@ -1134,7 +1134,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode recallMessage(long messageUid, String operatorId) {
|
public ErrorCode recallMessage(long messageUid, String operatorId, boolean isAdmin) {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
IMap<Long, MessageBundle> mIMap = hzInstance.getMap(MESSAGES_MAP);
|
IMap<Long, MessageBundle> mIMap = hzInstance.getMap(MESSAGES_MAP);
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public interface IMessagesStore {
|
|||||||
boolean isMemberInGroup(String member, String groupId);
|
boolean isMemberInGroup(String member, String groupId);
|
||||||
ErrorCode canSendMessageInGroup(String member, String groupId);
|
ErrorCode canSendMessageInGroup(String member, String groupId);
|
||||||
|
|
||||||
ErrorCode recallMessage(long messageUid, String operatorId);
|
ErrorCode recallMessage(long messageUid, String operatorId, boolean isAdmin);
|
||||||
|
|
||||||
WFCMessage.Robot getRobot(String robotId);
|
WFCMessage.Robot getRobot(String robotId);
|
||||||
void addRobot(WFCMessage.Robot robot);
|
void addRobot(WFCMessage.Robot robot);
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* 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.ProtoConstants;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
public class InputCreateChannel {
|
||||||
|
private String owner;
|
||||||
|
private String name;
|
||||||
|
private String targetId;
|
||||||
|
private String callback;
|
||||||
|
private String portrait;
|
||||||
|
private int auto;
|
||||||
|
private String secret;
|
||||||
|
private String desc;
|
||||||
|
private int status;
|
||||||
|
private String extra;
|
||||||
|
private long updateDt;
|
||||||
|
|
||||||
|
public WFCMessage.ChannelInfo toProtoChannelInfo() {
|
||||||
|
return WFCMessage.ChannelInfo.newBuilder().setOwner(owner)
|
||||||
|
.setName(name)
|
||||||
|
.setTargetId(targetId)
|
||||||
|
.setCallback(callback)
|
||||||
|
.setPortrait(portrait)
|
||||||
|
.setAutomatic(auto)
|
||||||
|
.setSecret(secret)
|
||||||
|
.setDesc(desc)
|
||||||
|
.setStatus(status)
|
||||||
|
.setExtra(extra)
|
||||||
|
.setUpdateDt(updateDt)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(String owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetId() {
|
||||||
|
return targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetId(String targetId) {
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCallback() {
|
||||||
|
return callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallback(String callback) {
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPortrait() {
|
||||||
|
return portrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPortrait(String portrait) {
|
||||||
|
this.portrait = portrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAuto() {
|
||||||
|
return auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuto(int auto) {
|
||||||
|
this.auto = auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(String secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExtra() {
|
||||||
|
return extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtra(String extra) {
|
||||||
|
this.extra = extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUpdateDt() {
|
||||||
|
return updateDt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateDt(long updateDt) {
|
||||||
|
this.updateDt = updateDt;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public class OutputCreateChannel {
|
||||||
|
private String targetId;
|
||||||
|
|
||||||
|
public OutputCreateChannel(String targetId) {
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetId() {
|
||||||
|
return targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetId(String targetId) {
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,8 @@ public interface APIPath {
|
|||||||
String Group_Member_Add = "/admin/group/member/add";
|
String Group_Member_Add = "/admin/group/member/add";
|
||||||
String Group_Member_Kickoff = "/admin/group/member/del";
|
String Group_Member_Kickoff = "/admin/group/member/del";
|
||||||
|
|
||||||
|
|
||||||
|
String Create_Channel = "/admin/channel/create";
|
||||||
String Get_System_Setting = "/admin/system/get_setting";
|
String Get_System_Setting = "/admin/system/get_setting";
|
||||||
String Put_System_Setting = "/admin/system/put_setting";
|
String Put_System_Setting = "/admin/system/put_setting";
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package cn.wildfirechat.sdk;
|
package cn.wildfirechat.sdk;
|
||||||
|
|
||||||
import cn.wildfirechat.common.APIPath;
|
import cn.wildfirechat.common.APIPath;
|
||||||
import cn.wildfirechat.pojos.InputFriendRequest;
|
import cn.wildfirechat.pojos.*;
|
||||||
import cn.wildfirechat.pojos.InputGetFriendList;
|
|
||||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
|
||||||
import cn.wildfirechat.sdk.model.IMResult;
|
import cn.wildfirechat.sdk.model.IMResult;
|
||||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||||
|
|
||||||
@@ -24,4 +22,9 @@ public class GeneralAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<OutputCreateChannel> createChannel(InputCreateChannel inputCreateChannel) throws Exception {
|
||||||
|
String path = APIPath.Create_Channel;
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, inputCreateChannel, OutputCreateChannel.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
voidIMResult = GroupAdmin.kickoffGroupMembers("user1", groupInfo.getTarget_id(), Arrays.asList("use2", "user3"), null, null);
|
voidIMResult = GroupAdmin.kickoffGroupMembers("user1", groupInfo.getTarget_id(), Arrays.asList("user3"), null, null);
|
||||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
System.out.println("kickoff group member success");
|
System.out.println("kickoff group member success");
|
||||||
} else {
|
} else {
|
||||||
@@ -328,6 +328,16 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputCreateChannel inputCreateChannel = new InputCreateChannel();
|
||||||
|
inputCreateChannel.setName("MyChannel");
|
||||||
|
IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
|
||||||
|
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("success");
|
||||||
|
} else {
|
||||||
|
System.out.println("create channel failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
//初始化机器人API
|
//初始化机器人API
|
||||||
RobotHttpUtils.init("http://localhost", "robot1", "123456");
|
RobotHttpUtils.init("http://localhost", "robot1", "123456");
|
||||||
//***********************************************
|
//***********************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user