添加获取在线用户信息和获取用户session信息的接口
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 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.MemorySessionStore;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Online_List)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetOnlineUserAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
GetOnlineUserRequest getOnlineUserRequest = getRequestBody(request.getNettyRequest(), GetOnlineUserRequest.class);
|
||||||
|
if (getOnlineUserRequest.nodeId == 1) {
|
||||||
|
GetOnlineUserResult result = messagesStore.getOnlineUsers(getOnlineUserRequest.offset, getOnlineUserRequest.count);
|
||||||
|
setResponseContent(RestResult.ok(result), response);
|
||||||
|
} else {
|
||||||
|
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.GetOnlineUserCountResult;
|
||||||
|
import cn.wildfirechat.pojos.GetUserSessionResult;
|
||||||
|
import cn.wildfirechat.pojos.InputUserId;
|
||||||
|
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.MemorySessionStore;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Online_Count)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetUserOnlineCountAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
int count = messagesStore.getOnlineUserCount();
|
||||||
|
GetOnlineUserCountResult result = new GetOnlineUserCountResult();
|
||||||
|
GetOnlineUserCountResult.Node node = new GetOnlineUserCountResult.Node();
|
||||||
|
node.node = 1;
|
||||||
|
node.count = count;
|
||||||
|
result.add(node);
|
||||||
|
|
||||||
|
setResponseContent(RestResult.ok(result), response);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.GetUserSessionResult;
|
||||||
|
import cn.wildfirechat.pojos.InputGetChatroomInfo;
|
||||||
|
import cn.wildfirechat.pojos.InputUserId;
|
||||||
|
import cn.wildfirechat.pojos.OutputStringList;
|
||||||
|
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.MemorySessionStore;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Session_List)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetUserSessionsAction 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)) {
|
||||||
|
Collection<MemorySessionStore.Session> sessions = sessionsStore.sessionForUser(userId);
|
||||||
|
GetUserSessionResult result = new GetUserSessionResult();
|
||||||
|
for (MemorySessionStore.Session session : sessions) {
|
||||||
|
boolean isOnline = sessionsStore.isClientOnline(session.getClientID());
|
||||||
|
result.userSessions.add(new GetUserSessionResult.UserSession(session.getUsername(), session.getClientID(), session.getPlatform(), session.getPushType(), session.getDeviceToken(), session.getVoipDeviceToken(), isOnline));
|
||||||
|
}
|
||||||
|
|
||||||
|
setResponseContent(RestResult.ok(result), response);
|
||||||
|
} else {
|
||||||
|
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4367,6 +4367,35 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return getChannelListener(channelId);
|
return getChannelListener(channelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOnlineUserCount() {
|
||||||
|
return m_Server.getProcessor().getConnectionDescriptors().getActiveConnectionsNo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GetOnlineUserResult getOnlineUsers(int offset, int count) {
|
||||||
|
List<String> onlineUserIds = new ArrayList<>(m_Server.getProcessor().getConnectionDescriptors().getConnectedClientIds());
|
||||||
|
GetOnlineUserResult result = new GetOnlineUserResult();
|
||||||
|
result.userClients = new ArrayList<>();
|
||||||
|
result.totalCount = onlineUserIds.size();
|
||||||
|
result.offset = offset;
|
||||||
|
|
||||||
|
if(onlineUserIds.size() > offset) {
|
||||||
|
List<String> clientIds = onlineUserIds.subList(offset, Math.min(offset+count, onlineUserIds.size()));
|
||||||
|
for (String clientId : clientIds) {
|
||||||
|
MemorySessionStore.Session session = m_Server.getStore().sessionsStore().getSession(clientId);
|
||||||
|
if(session != null) {
|
||||||
|
GetOnlineUserResult.UserClient userClient = new GetOnlineUserResult.UserClient();
|
||||||
|
userClient.userId = session.getUsername();
|
||||||
|
userClient.clientId = session.getClientID();
|
||||||
|
userClient.platform = session.getPlatform();
|
||||||
|
result.userClients.add(userClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> handleSensitiveWord(String message) {
|
public Set<String> handleSensitiveWord(String message) {
|
||||||
updateSensitiveWord();
|
updateSensitiveWord();
|
||||||
|
|||||||
@@ -615,6 +615,11 @@ public class MemorySessionStore implements ISessionsStore {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClientOnline(String clientId) {
|
||||||
|
return mServer.getProcessor().getConnectionDescriptors().isConnected(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StoredMessage inFlightAck(String clientID, int messageID) {
|
public StoredMessage inFlightAck(String clientID, int messageID) {
|
||||||
return getSession(clientID).outboundFlightMessages.remove(messageID);
|
return getSession(clientID).outboundFlightMessages.remove(messageID);
|
||||||
|
|||||||
@@ -16,13 +16,10 @@
|
|||||||
|
|
||||||
package io.moquette.spi;
|
package io.moquette.spi;
|
||||||
|
|
||||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
import cn.wildfirechat.pojos.*;
|
||||||
import cn.wildfirechat.pojos.OutputUserChatroom;
|
|
||||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import com.xiaoleilu.loServer.model.FriendData;
|
import com.xiaoleilu.loServer.model.FriendData;
|
||||||
import cn.wildfirechat.pojos.InputOutputUserBlockStatus;
|
|
||||||
import io.moquette.persistence.DatabaseStore;
|
import io.moquette.persistence.DatabaseStore;
|
||||||
import io.moquette.persistence.MemorySessionStore;
|
import io.moquette.persistence.MemorySessionStore;
|
||||||
import io.moquette.persistence.UserClientEntry;
|
import io.moquette.persistence.UserClientEntry;
|
||||||
@@ -32,10 +29,7 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the SPI to be implemented by a StorageService that handle persistence of messages
|
* Defines the SPI to be implemented by a StorageService that handle persistence of messages
|
||||||
@@ -228,6 +222,9 @@ public interface IMessagesStore {
|
|||||||
boolean checkUserInChannel(String user, String channelId);
|
boolean checkUserInChannel(String user, String channelId);
|
||||||
Collection<String> getChannelSubscriber(String channelId);
|
Collection<String> getChannelSubscriber(String channelId);
|
||||||
|
|
||||||
|
int getOnlineUserCount();
|
||||||
|
GetOnlineUserResult getOnlineUsers(int offset, int count);
|
||||||
|
|
||||||
Set<String> handleSensitiveWord(String message);
|
Set<String> handleSensitiveWord(String message);
|
||||||
boolean addSensitiveWords(List<String> words);
|
boolean addSensitiveWords(List<String> words);
|
||||||
boolean removeSensitiveWords(List<String> words);
|
boolean removeSensitiveWords(List<String> words);
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public interface ISessionsStore {
|
|||||||
*/
|
*/
|
||||||
Collection<ClientSession> getAllSessions();
|
Collection<ClientSession> getAllSessions();
|
||||||
|
|
||||||
|
boolean isClientOnline(String clientId);
|
||||||
|
|
||||||
StoredMessage inFlightAck(String clientID, int messageID);
|
StoredMessage inFlightAck(String clientID, int messageID);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -731,6 +731,10 @@ public class ProtocolProcessor {
|
|||||||
channel.flush();
|
channel.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConnectionDescriptorStore getConnectionDescriptors() {
|
||||||
|
return connectionDescriptors;
|
||||||
|
}
|
||||||
|
|
||||||
public void addInterceptHandler(InterceptHandler interceptHandler) {
|
public void addInterceptHandler(InterceptHandler interceptHandler) {
|
||||||
this.m_interceptor.addInterceptHandler(interceptHandler);
|
this.m_interceptor.addInterceptHandler(interceptHandler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public interface APIPath {
|
|||||||
String User_Kickoff_Client = "/admin/user/kickoff_client";
|
String User_Kickoff_Client = "/admin/user/kickoff_client";
|
||||||
String User_Online_Count = "/admin/user/online_count";
|
String User_Online_Count = "/admin/user/online_count";
|
||||||
String User_Online_List = "/admin/user/online_list";
|
String User_Online_List = "/admin/user/online_list";
|
||||||
|
String User_Session_List = "/admin/user/session_list";
|
||||||
String User_Application_Get_UserInfo = "/admin/user/app_get_user_info";
|
String User_Application_Get_UserInfo = "/admin/user/app_get_user_info";
|
||||||
|
|
||||||
String Friend_Update_Status = "/admin/friend/status";
|
String Friend_Update_Status = "/admin/friend/status";
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetUserSessionResult {
|
||||||
|
public static class UserSession {
|
||||||
|
public String userId;
|
||||||
|
public String clientId;
|
||||||
|
public int platform;
|
||||||
|
public int pushType;
|
||||||
|
public String deviceToken;
|
||||||
|
public String deviceVoipToken;
|
||||||
|
boolean isOnline;
|
||||||
|
|
||||||
|
public UserSession() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserSession(String userId, String clientId, int platform, int pushType, String deviceToken, String deviceVoipToken, boolean isOnline) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.clientId = clientId;
|
||||||
|
this.platform = platform;
|
||||||
|
this.pushType = pushType;
|
||||||
|
this.deviceToken = deviceToken;
|
||||||
|
this.deviceVoipToken = deviceVoipToken;
|
||||||
|
this.isOnline = isOnline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserSession> userSessions;
|
||||||
|
|
||||||
|
public GetUserSessionResult() {
|
||||||
|
userSessions = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -324,6 +324,14 @@ public class Main {
|
|||||||
System.out.println("get user online failure");
|
System.out.println("get user online failure");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMResult<GetUserSessionResult> getUserSessionResultIMResult = UserAdmin.getUserSession("hygqmws2k");
|
||||||
|
if (getUserSessionResultIMResult != null && getUserSessionResultIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("get user session success");
|
||||||
|
} else {
|
||||||
|
System.out.println("get user session failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,4 +151,9 @@ public class UserAdmin {
|
|||||||
input.setAuthCode(authCode);
|
input.setAuthCode(authCode);
|
||||||
return AdminHttpUtils.httpJsonPost(path, input, OutputApplicationUserInfo.class);
|
return AdminHttpUtils.httpJsonPost(path, input, OutputApplicationUserInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<GetUserSessionResult> getUserSession(String userId) throws Exception {
|
||||||
|
InputUserId inputUserId = new InputUserId(userId);
|
||||||
|
return AdminHttpUtils.httpJsonPost(APIPath.User_Session_List, inputUserId, GetUserSessionResult.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user