update
This commit is contained in:
@@ -45,7 +45,9 @@ public class BlockUserAction extends AdminAction {
|
|||||||
result = RestResult.resultOf(errorCode);
|
result = RestResult.resultOf(errorCode);
|
||||||
response.setContent(new Gson().toJson(result));
|
response.setContent(new Gson().toJson(result));
|
||||||
|
|
||||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
if (inputUserBlock.getStatus() != 0) {
|
||||||
|
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null);
|
sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.InputGetGroup;
|
||||||
|
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.PojoGroupInfo;
|
||||||
|
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.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
@Route(APIPath.Group_Get_Info)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetGroupInfoAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class);
|
||||||
|
if (inputGetGroup != null
|
||||||
|
&& (!StringUtil.isNullOrEmpty(inputGetGroup.getGroupId()))) {
|
||||||
|
|
||||||
|
WFCMessage.GroupInfo groupInfo = messagesStore.getGroupInfo(inputGetGroup.getGroupId());
|
||||||
|
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result;
|
||||||
|
if (groupInfo == null) {
|
||||||
|
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||||
|
} else {
|
||||||
|
PojoGroupInfo pojoGroupInfo = new PojoGroupInfo();
|
||||||
|
pojoGroupInfo.setExtra(groupInfo.getExtra());
|
||||||
|
pojoGroupInfo.setName(groupInfo.getName());
|
||||||
|
pojoGroupInfo.setOwner(groupInfo.getOwner());
|
||||||
|
pojoGroupInfo.setPortrait(groupInfo.getPortrait());
|
||||||
|
pojoGroupInfo.setTarget_id(groupInfo.getTargetId());
|
||||||
|
pojoGroupInfo.setType(groupInfo.getType());
|
||||||
|
result = RestResult.ok(pojoGroupInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
} else {
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.InputGetGroup;
|
||||||
|
import cn.wildfirechat.pojos.OutputGroupMemberList;
|
||||||
|
import cn.wildfirechat.pojos.PojoGroupInfo;
|
||||||
|
import cn.wildfirechat.pojos.PojoGroupMember;
|
||||||
|
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.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Route(APIPath.Group_Member_List)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetGroupMembersAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class);
|
||||||
|
if (inputGetGroup != null
|
||||||
|
&& (!StringUtil.isNullOrEmpty(inputGetGroup.getGroupId()))) {
|
||||||
|
|
||||||
|
List<WFCMessage.GroupMember> members = new ArrayList<>();
|
||||||
|
ErrorCode errorCode = messagesStore.getGroupMembers(inputGetGroup.getGroupId(), 0, members);
|
||||||
|
|
||||||
|
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result;
|
||||||
|
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
result = RestResult.resultOf(errorCode);
|
||||||
|
} else {
|
||||||
|
OutputGroupMemberList out = new OutputGroupMemberList();
|
||||||
|
out.setMembers(new ArrayList<>());
|
||||||
|
for (WFCMessage.GroupMember member : members) {
|
||||||
|
PojoGroupMember pm = new PojoGroupMember();
|
||||||
|
pm.setMember_id(member.getMemberId());
|
||||||
|
pm.setAlias(member.getAlias());
|
||||||
|
pm.setType(member.getType());
|
||||||
|
out.getMembers().add(pm);
|
||||||
|
}
|
||||||
|
result = RestResult.ok(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
} else {
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ public class TransferGroupAction extends AdminAction {
|
|||||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
InputTransferGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputTransferGroup.class);
|
InputTransferGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputTransferGroup.class);
|
||||||
if (inputDismissGroup.isValide()) {
|
if (inputDismissGroup.isValide()) {
|
||||||
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.AddGroupMemberTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.TransferGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(byte[] result) {
|
public void onSuccess(byte[] result) {
|
||||||
ByteBuf byteBuf = Unpooled.buffer();
|
ByteBuf byteBuf = Unpooled.buffer();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ package io.moquette.imhandler;
|
|||||||
|
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
|
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
|
||||||
|
import com.hazelcast.util.StringUtil;
|
||||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
@@ -19,6 +20,13 @@ import win.liyufan.im.IMTopic;
|
|||||||
public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupRequest> {
|
public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupRequest> {
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.CreateGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.CreateGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||||
|
|
||||||
|
if (!StringUtil.isNullOrEmpty(request.getGroup().getGroupInfo().getTargetId())) {
|
||||||
|
WFCMessage.GroupInfo existGroupInfo = m_messagesStore.getGroupInfo(request.getGroup().getGroupInfo().getTargetId());
|
||||||
|
if (existGroupInfo != null) {
|
||||||
|
return ErrorCode.ERROR_CODE_GROUP_ALREADY_EXIST;
|
||||||
|
}
|
||||||
|
}
|
||||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList());
|
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList());
|
||||||
if (groupInfo != null) {
|
if (groupInfo != null) {
|
||||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
|||||||
public class TransferGroupHandler extends GroupHandler<WFCMessage.TransferGroupRequest> {
|
public class TransferGroupHandler extends GroupHandler<WFCMessage.TransferGroupRequest> {
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.TransferGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.TransferGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||||
ErrorCode errorCode = m_messagesStore.transferGroup(fromUser, request.getGroupId(), request.getNewOwner());
|
ErrorCode errorCode = m_messagesStore.transferGroup(fromUser, request.getGroupId(), request.getNewOwner(), isAdmin);
|
||||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||||
|
|||||||
@@ -913,7 +913,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode transferGroup(String operator, String groupId, String newOwner) {
|
public ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin) {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||||
|
|
||||||
@@ -924,7 +924,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
if (!isAdmin && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public interface IMessagesStore {
|
|||||||
List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests);
|
List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests);
|
||||||
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
||||||
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
||||||
ErrorCode transferGroup(String operator, String groupId, String newOwner);
|
ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
|
||||||
boolean isMemberInGroup(String member, String groupId);
|
boolean isMemberInGroup(String member, String groupId);
|
||||||
boolean isForbiddenInGroup(String member, String groupId);
|
boolean isForbiddenInGroup(String member, String groupId);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
public class InputGetGroup {
|
||||||
|
private String groupId;
|
||||||
|
|
||||||
|
public String getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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 OutputGroupMemberList {
|
||||||
|
private List<PojoGroupMember> members;
|
||||||
|
|
||||||
|
public List<PojoGroupMember> getMembers() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembers(List<PojoGroupMember> members) {
|
||||||
|
this.members = members;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,8 @@ public interface APIPath {
|
|||||||
String Create_Group = "/admin/group/create";
|
String Create_Group = "/admin/group/create";
|
||||||
String Group_Dismiss = "/admin/group/del";
|
String Group_Dismiss = "/admin/group/del";
|
||||||
String Group_Transfer = "/admin/group/transfer";
|
String Group_Transfer = "/admin/group/transfer";
|
||||||
|
String Group_Get_Info = "/admin/group/get_info";
|
||||||
|
String Group_Member_List = "/admin/group/member/list";
|
||||||
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";
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public enum ErrorCode {
|
|||||||
|
|
||||||
public static ErrorCode fromCode(int code) {
|
public static ErrorCode fromCode(int code) {
|
||||||
for (ErrorCode errorCode : ErrorCode.values()) {
|
for (ErrorCode errorCode : ErrorCode.values()) {
|
||||||
if(errorCode.code == code) {
|
if(errorCode.code == (code&0xff)) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ public class GroupAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, createGroup, OutputCreateGroupResult.class);
|
return AdminHttpUtils.httpJsonPost(path, createGroup, OutputCreateGroupResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<PojoGroupInfo> getGroupInfo(String groupId) throws Exception {
|
||||||
|
String path = APIPath.Group_Get_Info;
|
||||||
|
InputGetGroup input = new InputGetGroup();
|
||||||
|
input.setGroupId(groupId);
|
||||||
|
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, input, PojoGroupInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static IMResult<Void> dismissGroup(String operator, String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
public static IMResult<Void> dismissGroup(String operator, String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||||
String path = APIPath.Group_Dismiss;
|
String path = APIPath.Group_Dismiss;
|
||||||
InputDismissGroup dismissGroup = new InputDismissGroup();
|
InputDismissGroup dismissGroup = new InputDismissGroup();
|
||||||
@@ -38,11 +46,20 @@ public class GroupAdmin {
|
|||||||
InputTransferGroup transferGroup = new InputTransferGroup();
|
InputTransferGroup transferGroup = new InputTransferGroup();
|
||||||
transferGroup.setGroup_id(groupId);
|
transferGroup.setGroup_id(groupId);
|
||||||
transferGroup.setNew_owner(newOwner);
|
transferGroup.setNew_owner(newOwner);
|
||||||
|
transferGroup.setOperator(operator);
|
||||||
transferGroup.setTo_lines(to_lines);
|
transferGroup.setTo_lines(to_lines);
|
||||||
transferGroup.setNotify_message(notify_message);
|
transferGroup.setNotify_message(notify_message);
|
||||||
return AdminHttpUtils.httpJsonPost(path, transferGroup, Void.class);
|
return AdminHttpUtils.httpJsonPost(path, transferGroup, Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IMResult<OutputGroupMemberList> getGroupMembers(String groupId) throws Exception {
|
||||||
|
String path = APIPath.Group_Member_List;
|
||||||
|
InputGetGroup input = new InputGetGroup();
|
||||||
|
input.setGroupId(groupId);
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, input, OutputGroupMemberList.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static IMResult<Void> addGroupMembers(String operator, String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
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;
|
String path = APIPath.Group_Member_Add;
|
||||||
InputAddGroupMember addGroupMember = new InputAddGroupMember();
|
InputAddGroupMember addGroupMember = new InputAddGroupMember();
|
||||||
@@ -54,6 +71,7 @@ public class GroupAdmin {
|
|||||||
members.add(m);
|
members.add(m);
|
||||||
}
|
}
|
||||||
addGroupMember.setMembers(members);
|
addGroupMember.setMembers(members);
|
||||||
|
addGroupMember.setOperator(operator);
|
||||||
addGroupMember.setTo_lines(to_lines);
|
addGroupMember.setTo_lines(to_lines);
|
||||||
addGroupMember.setNotify_message(notify_message);
|
addGroupMember.setNotify_message(notify_message);
|
||||||
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||||
@@ -64,6 +82,7 @@ public class GroupAdmin {
|
|||||||
InputKickoffGroupMember kickoffGroupMember = new InputKickoffGroupMember();
|
InputKickoffGroupMember kickoffGroupMember = new InputKickoffGroupMember();
|
||||||
kickoffGroupMember.setGroup_id(groupId);
|
kickoffGroupMember.setGroup_id(groupId);
|
||||||
kickoffGroupMember.setMembers(groupMemberIds);
|
kickoffGroupMember.setMembers(groupMemberIds);
|
||||||
|
kickoffGroupMember.setOperator(operator);
|
||||||
kickoffGroupMember.setTo_lines(to_lines);
|
kickoffGroupMember.setTo_lines(to_lines);
|
||||||
kickoffGroupMember.setNotify_message(notify_message);
|
kickoffGroupMember.setNotify_message(notify_message);
|
||||||
return AdminHttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
|
return AdminHttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
|
||||||
|
|||||||
@@ -5,10 +5,17 @@ import cn.wildfirechat.pojos.*;
|
|||||||
import cn.wildfirechat.sdk.model.IMResult;
|
import cn.wildfirechat.sdk.model.IMResult;
|
||||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
AdminHttpUtils.init("http://localhost:18080", "123456");
|
AdminHttpUtils.init("http://localhost:18080", "123456");
|
||||||
|
|
||||||
|
|
||||||
|
//***********************************************
|
||||||
|
//**** 用户相关的API
|
||||||
|
//***********************************************
|
||||||
InputOutputUserInfo userInfo = new InputOutputUserInfo();
|
InputOutputUserInfo userInfo = new InputOutputUserInfo();
|
||||||
userInfo.setUserId("userId1");
|
userInfo.setUserId("userId1");
|
||||||
userInfo.setName("user1");
|
userInfo.setName("user1");
|
||||||
@@ -119,5 +126,80 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//***********************************************
|
||||||
|
//**** 群组相关API
|
||||||
|
//***********************************************
|
||||||
|
PojoGroupInfo groupInfo = new PojoGroupInfo();
|
||||||
|
groupInfo.setTarget_id("groupId1");
|
||||||
|
groupInfo.setOwner("user1");
|
||||||
|
groupInfo.setName("test_group");
|
||||||
|
groupInfo.setExtra("hello extra");
|
||||||
|
groupInfo.setPortrait("http://portrait");
|
||||||
|
List<PojoGroupMember> members = new ArrayList<>();
|
||||||
|
PojoGroupMember member1 = new PojoGroupMember();
|
||||||
|
member1.setMember_id(groupInfo.getOwner());
|
||||||
|
members.add(member1);
|
||||||
|
|
||||||
|
PojoGroupMember member2 = new PojoGroupMember();
|
||||||
|
member2.setMember_id("user2");
|
||||||
|
members.add(member2);
|
||||||
|
|
||||||
|
PojoGroupMember member3 = new PojoGroupMember();
|
||||||
|
member3.setMember_id("user3");
|
||||||
|
members.add(member3);
|
||||||
|
|
||||||
|
IMResult<OutputCreateGroupResult> resultCreateGroup = GroupAdmin.createGroup(groupInfo.getOwner(), groupInfo, members, null, null);
|
||||||
|
if (resultCreateGroup != null && resultCreateGroup.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("create group success");
|
||||||
|
} else {
|
||||||
|
System.out.println("create group failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IMResult<PojoGroupInfo> resultGetGroupInfo = GroupAdmin.getGroupInfo(groupInfo.getTarget_id());
|
||||||
|
if (resultGetGroupInfo != null && resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
if (groupInfo.getExtra().equals(resultGetGroupInfo.getResult().getExtra())
|
||||||
|
&& groupInfo.getName().equals(resultGetGroupInfo.getResult().getName())
|
||||||
|
&& groupInfo.getOwner().equals(resultGetGroupInfo.getResult().getOwner())) {
|
||||||
|
System.out.println("get group success");
|
||||||
|
} else {
|
||||||
|
System.out.println("group info is not expected");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("create group failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IMResult<Void> voidIMResult = GroupAdmin.transferGroup(groupInfo.getOwner(), groupInfo.getTarget_id(), "user2", null, null);
|
||||||
|
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("transfer success");
|
||||||
|
} else {
|
||||||
|
System.out.println("create group failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
resultGetGroupInfo = GroupAdmin.getGroupInfo(groupInfo.getTarget_id());
|
||||||
|
if (resultGetGroupInfo != null && resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
if ("user2".equals(resultGetGroupInfo.getResult().getOwner())) {
|
||||||
|
groupInfo.setOwner("user2");
|
||||||
|
} else {
|
||||||
|
System.out.println("group info is not expected");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("create group failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IMResult<OutputGroupMemberList> resultGetMembers = GroupAdmin.getGroupMembers(groupInfo.getTarget_id());
|
||||||
|
if (resultGetMembers != null && resultGetMembers.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("get group member success");
|
||||||
|
} else {
|
||||||
|
System.out.println("create group failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user