支持获取用户群组指定群成员类型
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.InputGetUserGroupByType;
|
||||
import cn.wildfirechat.pojos.InputUserId;
|
||||
import cn.wildfirechat.pojos.OutputGroupIds;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
@Route(APIPath.Get_User_Groups_By_Type)
|
||||
@HttpMethod("POST")
|
||||
public class GetUserGroupsByTypeAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserGroupByType input = getRequestBody(request.getNettyRequest(), InputGetUserGroupByType.class);
|
||||
if (input != null
|
||||
&& (!StringUtil.isNullOrEmpty(input.getUserId()))) {
|
||||
|
||||
Set<String> groupIds = messagesStore.getUserGroupIds(input.getUserId(), input.getGroupMemberTypes());
|
||||
OutputGroupIds outputGroupIds = new OutputGroupIds();
|
||||
outputGroupIds.setGroupIds(new ArrayList<>(groupIds));
|
||||
RestResult result = RestResult.ok(outputGroupIds);
|
||||
setResponseContent(result, response);
|
||||
} else {
|
||||
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1845,6 +1845,45 @@ public class DatabaseStore {
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<String> getUserGroupIds(String userId, List<Integer> memberTypes) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select _gid from t_group_member where _mid = ? ";
|
||||
if(!memberTypes.isEmpty()) {
|
||||
sql += " and _type in (";
|
||||
for (int i = 0; i < memberTypes.size(); i++) {
|
||||
if(i > 0) {
|
||||
sql += ",";
|
||||
}
|
||||
sql += memberTypes.get(i);
|
||||
}
|
||||
sql += ")";
|
||||
}
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
statement.setString(1, userId);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
Set<String> out = new HashSet<>();
|
||||
while (rs.next()) {
|
||||
String uid = rs.getString(1);
|
||||
out.add(uid);
|
||||
}
|
||||
return out;
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, RDBS_Exception);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, rs);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Set<String> getCommonGroupIds(String userId1, String userId2) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
@@ -1944,6 +1944,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return databaseStore.getUserGroupIds(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getUserGroupIds(String userId, List<Integer> memberTypes) {
|
||||
return databaseStore.getUserGroupIds(userId, memberTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCommonGroupIds(String userId1, String userId2) {
|
||||
return databaseStore.getCommonGroupIds(userId1, userId2);
|
||||
|
||||
@@ -119,6 +119,7 @@ public interface IMessagesStore {
|
||||
List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests, String fromUser, boolean isAdmin);
|
||||
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
||||
Set<String> getUserGroupIds(String userId);
|
||||
Set<String> getUserGroupIds(String userId, List<Integer> types);
|
||||
Set<String> getCommonGroupIds(String userId1, String userId2);
|
||||
ErrorCode getGroupMembers(String fromUser, String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
||||
WFCMessage.GroupMember getGroupMember(String groupId, String memberId);
|
||||
|
||||
@@ -77,6 +77,7 @@ public interface APIPath {
|
||||
String Group_Mute_Member = "/admin/group/manager/mute";
|
||||
String Group_Allow_Member = "/admin/group/manager/allow";
|
||||
String Get_User_Groups = "/admin/group/of_user";
|
||||
String Get_User_Groups_By_Type = "/admin/group/of_user_by_type";
|
||||
String Group_Set_Member_Alias = "/admin/group/member/set_alias";
|
||||
String Group_Set_Member_Extra = "/admin/group/member/set_extra";
|
||||
String Get_Common_Groups = "/admin/group/common_group";
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* 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 InputGetUserGroupByType {
|
||||
private String userId;
|
||||
private List<Integer> groupMemberTypes;
|
||||
|
||||
public InputGetUserGroupByType() {
|
||||
}
|
||||
|
||||
public InputGetUserGroupByType(String userId, List<Integer> groupMemberTypes) {
|
||||
this.userId = userId;
|
||||
this.groupMemberTypes = groupMemberTypes;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public List<Integer> getGroupMemberTypes() {
|
||||
return groupMemberTypes;
|
||||
}
|
||||
|
||||
public void setGroupMemberTypes(List<Integer> groupMemberTypes) {
|
||||
this.groupMemberTypes = groupMemberTypes;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
|
||||
@@ -178,6 +179,12 @@ public class GroupAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, inputUserId, OutputGroupIds.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputGroupIds> getUserGroupsByType(String user, List</*ProtoConstants.GroupMemberType*/Integer> groupMemberType) throws Exception {
|
||||
String path = APIPath.Get_User_Groups_By_Type;
|
||||
InputGetUserGroupByType input = new InputGetUserGroupByType(user, groupMemberType);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, OutputGroupIds.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputGroupIds> getCommonGroups(String user1, String user2) throws Exception {
|
||||
String path = APIPath.Get_Common_Groups;
|
||||
StringPairPojo intput = new StringPairPojo(user1, user2);
|
||||
|
||||
@@ -388,7 +388,6 @@ public class Main {
|
||||
System.out.println("success");
|
||||
} else {
|
||||
System.out.println("send friend request success");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<Void> updateFriendStatusResult = RelationAdmin.setUserFriend("ff1", "ff2", true, "{\"from\":1}");
|
||||
@@ -657,6 +656,14 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
groupIdsIMResult = GroupAdmin.getUserGroupsByType("user2", Arrays.asList(ProtoConstants.GroupMemberType.GroupMemberType_Manager, ProtoConstants.GroupMemberType.GroupMemberType_Owner));
|
||||
if (groupIdsIMResult != null && groupIdsIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get user groups by type success");
|
||||
} else {
|
||||
System.out.println("get user groups by type failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
groupIdsIMResult = GroupAdmin.getCommonGroups("user1", "user2");
|
||||
if (groupIdsIMResult != null && groupIdsIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get user common groups success");
|
||||
|
||||
Reference in New Issue
Block a user