添加获取用户聊天室状态的API
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.InputGetChatroomInfo;
|
||||
import cn.wildfirechat.pojos.InputUserId;
|
||||
import cn.wildfirechat.pojos.OutputStringList;
|
||||
import cn.wildfirechat.pojos.OutputUserChatroom;
|
||||
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.UserClientEntry;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Route(APIPath.Chatroom_GetUserChatroom)
|
||||
@HttpMethod("POST")
|
||||
public class GetUserChatroomAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputUserId inputUserId = getRequestBody(request.getNettyRequest(), InputUserId.class);
|
||||
String userId = inputUserId.getUserId();
|
||||
if (!StringUtil.isNullOrEmpty(userId)) {
|
||||
OutputUserChatroom outputUserChatroom = messagesStore.getUserChatroom(userId);
|
||||
|
||||
RestResult result;
|
||||
if (outputUserChatroom != null) {
|
||||
result = RestResult.ok(outputUserChatroom);
|
||||
} else {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||
}
|
||||
setResponseContent(result, response);
|
||||
} else {
|
||||
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -933,7 +933,29 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
Collection<UserClientEntry> members = chatroomMembers.get(chatroomId);
|
||||
return members;
|
||||
}
|
||||
//Todo chatroom
|
||||
|
||||
@Override
|
||||
public OutputUserChatroom getUserChatroom(String userId) {
|
||||
String chatroomId = (String) m_Server.getHazelcastInstance().getMap(USER_CHATROOM).get(userId);
|
||||
if(chatroomId != null) {
|
||||
MultiMap<String, UserClientEntry> chatroomMembers = m_Server.getHazelcastInstance().getMultiMap(CHATROOM_MEMBER_IDS);
|
||||
for (UserClientEntry userClientEntry : chatroomMembers.get(chatroomId)) {
|
||||
if(userClientEntry.userId.equals(userId)) {
|
||||
OutputUserChatroom outputUserChatroom = new OutputUserChatroom();
|
||||
outputUserChatroom.userId = userId;
|
||||
outputUserChatroom.chatroomId = chatroomId;
|
||||
outputUserChatroom.clientId = userClientEntry.clientId;
|
||||
MemorySessionStore.Session session = m_Server.getStore().sessionsStore().getSession(userClientEntry.clientId);
|
||||
if(session != null) {
|
||||
outputUserChatroom.platform = session.getPlatform();
|
||||
}
|
||||
return outputUserChatroom;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WFCMessage.PullMessageResult fetchChatroomMessage(String fromUser, String chatroomId, String exceptClientId, long fromMessageId) {
|
||||
WFCMessage.PullMessageResult.Builder builder = WFCMessage.PullMessageResult.newBuilder();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package io.moquette.spi;
|
||||
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.OutputUserChatroom;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
@@ -173,6 +174,7 @@ public interface IMessagesStore {
|
||||
|
||||
long insertChatroomMessages(String target, int line, long messageId);
|
||||
Collection<UserClientEntry> getChatroomMembers(String chatroomId);
|
||||
OutputUserChatroom getUserChatroom(String userId);
|
||||
WFCMessage.PullMessageResult fetchChatroomMessage(String fromUser, String chatroomId, String exceptClientId, long fromMessageId);
|
||||
|
||||
ErrorCode verifyToken(String userId, String token, List<String> serverIPs, List<Integer> ports);
|
||||
|
||||
@@ -5,6 +5,7 @@ public interface APIPath {
|
||||
String Chatroom_Destroy = "/admin/chatroom/del";
|
||||
String Chatroom_Info = "/admin/chatroom/info";
|
||||
String Chatroom_GetMembers = "/admin/chatroom/members";
|
||||
String Chatroom_GetUserChatroom = "/admin/chatroom/user_chatroom";
|
||||
String Chatroom_SetBlacklist = "/admin/chatroom/set_black_status";
|
||||
String Chatroom_GetBlacklist = "/admin/chatroom/get_black_status";
|
||||
String Chatroom_SetManager = "/admin/chatroom/set_manager";
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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 OutputUserChatroom {
|
||||
public String userId;
|
||||
public String chatroomId;
|
||||
public String clientId;
|
||||
public int/*ProtoConstants.Platform*/ platform;
|
||||
}
|
||||
@@ -37,6 +37,12 @@ public class ChatroomAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, input, OutputStringList.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputUserChatroom> getUserChatroom(String userId) throws Exception {
|
||||
String path = APIPath.Chatroom_GetUserChatroom;
|
||||
InputUserId input = new InputUserId(userId);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, OutputUserChatroom.class);
|
||||
}
|
||||
|
||||
//仅专业版支持
|
||||
//status:0,正常;1,禁言;2,禁止加入
|
||||
public static IMResult<Void> setChatroomBlacklist(String chatroomId, String userId, int status) throws Exception {
|
||||
|
||||
@@ -974,6 +974,14 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputUserChatroom> userChatroomIMResult = ChatroomAdmin.getUserChatroom("hygqmws2k");
|
||||
if(userChatroomIMResult != null && (userChatroomIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS || userChatroomIMResult.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST)) {
|
||||
System.out.println("get user chatroom success");
|
||||
} else {
|
||||
System.out.println("get user chatroom failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
//下面仅专业版支持
|
||||
if(commercialServer) {
|
||||
//设置用户聊天室黑名单。0正常;1禁言;2禁止加入。
|
||||
|
||||
Reference in New Issue
Block a user