This commit is contained in:
heavyrain.lee
2019-05-23 07:26:57 +08:00
parent 3ef973ffc5
commit 5a338cdba1
15 changed files with 152 additions and 20 deletions
@@ -23,7 +23,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.internal.StringUtil;
import cn.wildfirechat.common.ErrorCode;
@Route(APIPath.User_Status)
@Route(APIPath.User_Update_Block_Status)
@HttpMethod("POST")
public class BlockUserAction extends AdminAction {
@@ -20,7 +20,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.util.internal.StringUtil;
import cn.wildfirechat.common.ErrorCode;
@Route(APIPath.User_Online_Status)
@Route(APIPath.User_Get_Online_Status)
@HttpMethod("POST")
public class CheckUserOnlineAction extends AdminAction {
@@ -16,7 +16,7 @@ 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 cn.wildfirechat.pojos.InputDismissGroupMember;
import cn.wildfirechat.pojos.InputDismissGroup;
import io.moquette.persistence.RPCCenter;
import io.moquette.persistence.TargetEntry;
import io.netty.buffer.ByteBuf;
@@ -40,7 +40,7 @@ public class DismissGroupAction extends AdminAction {
@Override
public boolean action(Request request, Response response) {
if (request.getNettyRequest() instanceof FullHttpRequest) {
InputDismissGroupMember inputDismissGroup = getRequestBody(request.getNettyRequest(), InputDismissGroupMember.class);
InputDismissGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputDismissGroup.class);
if (inputDismissGroup.isValide()) {
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.AddGroupMemberTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
@Override
@@ -25,7 +25,7 @@ import win.liyufan.im.IMTopic;
import java.util.Base64;
import java.util.concurrent.Executor;
@Route(APIPath.Get_User_Token)
@Route(APIPath.User_Get_Token)
@HttpMethod("POST")
public class GetIMTokenAction extends AdminAction {
@@ -23,7 +23,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.internal.StringUtil;
import cn.wildfirechat.common.ErrorCode;
@Route(APIPath.Get_User_Info)
@Route(APIPath.User_Get_Info)
@HttpMethod("POST")
public class GetUserAction extends AdminAction {
@@ -18,7 +18,7 @@ import com.xiaoleilu.loServer.handler.Response;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
@Route(APIPath.User_Status_List)
@Route(APIPath.User_Get_Blocked_List)
@HttpMethod("POST")
public class GetUserBlockListAction extends AdminAction {
@@ -22,7 +22,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.internal.StringUtil;
import cn.wildfirechat.common.ErrorCode;
@Route(APIPath.User_Check_Status)
@Route(APIPath.User_Check_Block_Status)
@HttpMethod("POST")
public class GetUserBlockStatusAction extends AdminAction {
@@ -28,7 +28,7 @@ import win.liyufan.im.IMTopic;
import java.util.concurrent.Executor;
@Route(APIPath.Group_Owner)
@Route(APIPath.Group_Transfer)
@HttpMethod("POST")
public class TransferGroupAction extends AdminAction {
@@ -14,7 +14,7 @@ import io.netty.util.internal.StringUtil;
import java.util.List;
public class InputDismissGroupMember extends InputGroupBase {
public class InputDismissGroup extends InputGroupBase {
private String group_id;
@@ -20,6 +20,10 @@ public class InputGroupBase {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public List<Integer> getTo_lines() {
return to_lines;
}
@@ -0,0 +1,24 @@
/*
* 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 java.util.List;
public class OutputUserBlockStatusList {
private List<InputOutputUserBlockStatus> statusList;
public List<InputOutputUserBlockStatus> getStatusList() {
return statusList;
}
public void setStatusList(List<InputOutputUserBlockStatus> statusList) {
this.statusList = statusList;
}
}
@@ -14,12 +14,12 @@ public interface APIPath {
String Sensitive_Del = "/admin/sensitive/del";
String Sensitive_Query = "/admin/sensitive/query";
String Get_User_Token = "/admin/user/token";
String User_Status = "/admin/user/status";
String Get_User_Info = "/admin/user/info";
String User_Status_List = "/admin/user/statuslist";
String User_Check_Status = "/admin/user/checkstatus";
String User_Online_Status = "/admin/user/onlinestatus";
String User_Get_Token = "/admin/user/get_token";
String User_Update_Block_Status = "/admin/user/update_block_status";
String User_Get_Info = "/admin/user/get_info";
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
String User_Check_Block_Status = "/admin/user/check_block_status";
String User_Get_Online_Status = "/admin/user/onlinestatus";
String Friend_Status = "/admin/friend/status";
@@ -29,9 +29,9 @@ public interface APIPath {
String Msg_Recall = "/admin/message/recall";
String Group_Dismiss = "/admin/group/del";
String Group_Transfer = "/admin/group/transfer";
String Group_Member_Add = "/admin/group/member/add";
String Group_Member_Kickoff = "/admin/group/member/del";
String Group_Owner = "/admin/group/owner";
String Channel_Message_Send = "/channel/message/send";
@@ -0,0 +1,71 @@
package cn.wildfirechat.sdk;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.sdk.model.IMResult;
import java.util.ArrayList;
import java.util.List;
public class GroupAdmin {
public static IMResult<OutputCreateGroupResult> createGroup(String operator, PojoGroupInfo group_info, List<PojoGroupMember> members, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Create_Group;
PojoGroup pojoGroup = new PojoGroup();
pojoGroup.setGroup_info(group_info);
pojoGroup.setMembers(members);
InputCreateGroup createGroup = new InputCreateGroup();
createGroup.setGroup(pojoGroup);
createGroup.setOperator(operator);
createGroup.setTo_lines(to_lines);
createGroup.setNotify_message(notify_message);
return HttpUtils.httpJsonPost(path, createGroup, OutputCreateGroupResult.class);
}
public static IMResult<Void> dismissGroup(String operator, String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Dismiss;
InputDismissGroup dismissGroup = new InputDismissGroup();
dismissGroup.setOperator(operator);
dismissGroup.setGroup_id(groupId);
dismissGroup.setTo_lines(to_lines);
dismissGroup.setNotify_message(notify_message);
return HttpUtils.httpJsonPost(path, dismissGroup, Void.class);
}
public static IMResult<Void> transferGroup(String operator, String groupId, String newOwner, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Transfer;
InputTransferGroup transferGroup = new InputTransferGroup();
transferGroup.setGroup_id(groupId);
transferGroup.setNew_owner(newOwner);
transferGroup.setTo_lines(to_lines);
transferGroup.setNotify_message(notify_message);
return HttpUtils.httpJsonPost(path, transferGroup, Void.class);
}
public static IMResult<Void> addGroupMembers(String operator, String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Member_Add;
InputAddGroupMember addGroupMember = new InputAddGroupMember();
addGroupMember.setGroup_id(groupId);
List<PojoGroupMember> members = new ArrayList<>();
for (String mid : groupMemberIds) {
PojoGroupMember m = new PojoGroupMember();
m.setMember_id(mid);
members.add(m);
}
addGroupMember.setMembers(members);
addGroupMember.setTo_lines(to_lines);
addGroupMember.setNotify_message(notify_message);
return HttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public static IMResult<Void> kickoffGroupMembers(String operator, String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Member_Kickoff;
InputKickoffGroupMember kickoffGroupMember = new InputKickoffGroupMember();
kickoffGroupMember.setGroup_id(groupId);
kickoffGroupMember.setMembers(groupMemberIds);
kickoffGroupMember.setTo_lines(to_lines);
kickoffGroupMember.setNotify_message(notify_message);
return HttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
}
}
@@ -54,7 +54,10 @@ public class HttpUtils {
post.setHeader("timestamp", "" + timestamp);
post.setHeader("sign", sign);
String jsonStr = new Gson().toJson(object);
String jsonStr = null;
if (object != null) {
jsonStr = new Gson().toJson(object);
}
LOG.info("http request content: {}", jsonStr);
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
@@ -4,9 +4,11 @@ import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.sdk.model.IMResult;
import java.util.List;
public class UserAdmin {
public static IMResult<InputOutputUserInfo> getUserByName(String mobile) throws Exception {
String path = APIPath.Get_User_Info;
String path = APIPath.User_Get_Info;
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, mobile);
return HttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
}
@@ -17,8 +19,36 @@ public class UserAdmin {
}
public static IMResult<OutputGetIMTokenData> getUserToken(String userId, String clientId) throws Exception {
String path = APIPath.Get_User_Token;
String path = APIPath.User_Get_Token;
InputGetToken getToken = new InputGetToken(userId, clientId);
return HttpUtils.httpJsonPost(path, getToken, OutputGetIMTokenData.class);
}
public static IMResult<Void> updateUserBlockStatus(String userId, int block) throws Exception {
String path = APIPath.User_Update_Block_Status;
InputOutputUserBlockStatus blockStatus = new InputOutputUserBlockStatus(userId, block);
return HttpUtils.httpJsonPost(path, blockStatus, Void.class);
}
public static IMResult<OutputUserStatus> checkUserBlockStatus(String userId) throws Exception {
String path = APIPath.User_Update_Block_Status;
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null);
return HttpUtils.httpJsonPost(path, getUserInfo, OutputUserStatus.class);
}
public static IMResult<OutputUserBlockStatusList> getBlockedList() throws Exception {
String path = APIPath.User_Get_Blocked_List;
return HttpUtils.httpJsonPost(path, null, OutputUserBlockStatusList.class);
}
//not implement
// public static IMResult<OutputUserBlockStatusList> getUserOnlineStatus(String userId) throws Exception {
// String path = APIPath.User_Get_Online_Status;
// InputGetUserInfo inputGetUserInfo = new InputGetUserInfo(userId, null);
// return HttpUtils.httpJsonPost(path, null, OutputUserBlockStatusList.class);
// }
}