修正在线状态问题

This commit is contained in:
heavyrian2012
2022-03-23 21:45:27 +08:00
parent a3f2623d7e
commit 806cd440e3
2 changed files with 20 additions and 9 deletions
@@ -751,7 +751,7 @@ public class MemorySessionStore implements ISessionsStore {
public void disableSession(String userId, String clientId) { public void disableSession(String userId, String clientId) {
Session session = sessions.get(clientId); Session session = sessions.get(clientId);
if (session != null && session.getDeleted() == 0 && (userId == null || session.getUsername().equals(userId))) { if (session != null && session.getDeleted() == 0 && (userId == null || session.getUsername().equals(userId))) {
mServer.getProcessor().processOffline(session, false); mServer.getProcessor().processOffline(session, false, null);
databaseStore.updateSessionDeleted(session.getUsername(), clientId, 1); databaseStore.updateSessionDeleted(session.getUsername(), clientId, 1);
ConcurrentSkipListSet<String> sessionSet = getUserSessionSet(session.username); ConcurrentSkipListSet<String> sessionSet = getUserSessionSet(session.username);
sessionSet.remove(clientId); sessionSet.remove(clientId);
@@ -773,7 +773,7 @@ public class MemorySessionStore implements ISessionsStore {
return; return;
} }
mServer.getProcessor().processOffline(session, true); mServer.getProcessor().processOffline(session, true, null);
ConcurrentSkipListSet<String> sessionSet = getUserSessionSet(session.username); ConcurrentSkipListSet<String> sessionSet = getUserSessionSet(session.username);
sessionSet.remove(clientID); sessionSet.remove(clientID);
@@ -620,19 +620,30 @@ public class ProtocolProcessor {
String username = NettyUtils.userName(channel); String username = NettyUtils.userName(channel);
MemorySessionStore.Session session = m_sessionsStore.getSession(clientID); MemorySessionStore.Session session = m_sessionsStore.getSession(clientID);
if(session != null) { if(session != null) {
processOffline(session, clearSession); processOffline(session, clearSession, new Runnable() {
} @Override
public void run() {
ConnectionDescriptor oldConnDescr = new ConnectionDescriptor(clientID, channel); ConnectionDescriptor oldConnDescr = new ConnectionDescriptor(clientID, channel);
if(connectionDescriptors.removeConnection(oldConnDescr)) { if(connectionDescriptors.removeConnection(oldConnDescr)) {
m_interceptor.notifyClientConnectionLost(clientID, username); m_interceptor.notifyClientConnectionLost(clientID, username);
}
}
});
} else {
ConnectionDescriptor oldConnDescr = new ConnectionDescriptor(clientID, channel);
if(connectionDescriptors.removeConnection(oldConnDescr)) {
m_interceptor.notifyClientConnectionLost(clientID, username);
}
} }
} }
public void processOffline(MemorySessionStore.Session session, boolean clearSession) { public void processOffline(MemorySessionStore.Session session, boolean clearSession, Runnable runnable) {
if(session != null) { if(session != null) {
session.refreshLastActiveTime(); session.refreshLastActiveTime();
forwardOnlineStatusEvent(session.getUsername(), session.getClientID(), session.getPlatform(), clearSession ? UserOnlineStatus.LOGOUT : UserOnlineStatus.OFFLINE, session.getAppName()); forwardOnlineStatusEvent(session.getUsername(), session.getClientID(), session.getPlatform(), clearSession ? UserOnlineStatus.LOGOUT : UserOnlineStatus.OFFLINE, session.getAppName());
if(runnable != null) {
runnable.run();
}
m_messagesStore.updateUserOnlineSetting(session, false); m_messagesStore.updateUserOnlineSetting(session, false);
} }
} }