diff --git a/mall-im/src/main/java/com/suisung/mall/im/common/websocket/service/LocalSessionManager.java b/mall-im/src/main/java/com/suisung/mall/im/common/websocket/service/LocalSessionManager.java index 72c3feeb..4e8ff23b 100644 --- a/mall-im/src/main/java/com/suisung/mall/im/common/websocket/service/LocalSessionManager.java +++ b/mall-im/src/main/java/com/suisung/mall/im/common/websocket/service/LocalSessionManager.java @@ -41,9 +41,9 @@ public class LocalSessionManager { if (userId == null || session == null) { return; } - userSessions.computeIfPresent(userId, (key, sessions) -> { - sessions.remove(session); + sessions.removeIf(webSocketSession -> + webSocketSession.getId().equals(session.getId())); return sessions.isEmpty() ? null : sessions; }); } @@ -112,13 +112,11 @@ public class LocalSessionManager { * 移除群组会话 */ public void removeGroupSession(String groupId, WebSocketSession session) { - List sessions = groupSessions.get(groupId); - if (sessions != null) { - sessions.remove(session); - if (sessions.isEmpty()) { - groupSessions.remove(groupId); - } - } + groupSessions.computeIfPresent(groupId, (key, gropSession) -> { + gropSession.removeIf(webSocketSession -> + webSocketSession.getId().equals(session.getId())); + return gropSession.isEmpty() ? null : gropSession; + }); } /**