聊天室信息发送
This commit is contained in:
parent
b04783a3ba
commit
3a62a8e639
|
|
@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.websocket.*;
|
import javax.websocket.*;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
|
|
@ -75,8 +76,12 @@ public class ChatRoom {
|
||||||
if (Objects.isNull(room)) {
|
if (Objects.isNull(room)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserDetailsImpl userInfo = (UserDetailsImpl) session.getUserPrincipal();
|
Principal userPrincipal = session.getUserPrincipal();
|
||||||
if (Objects.isNull(userInfo)) {
|
if (Objects.isNull(userPrincipal)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UserDetailsImpl userInfo = (UserDetailsImpl) ((Authentication) userPrincipal).getPrincipal();
|
||||||
|
if (Objects.isNull(userInfo) || !getRoomCache().isExistUser(userInfo.getId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserMessageVo messageVo = UserMessageVo.builder()
|
UserMessageVo messageVo = UserMessageVo.builder()
|
||||||
|
|
@ -124,7 +129,7 @@ public class ChatRoom {
|
||||||
String sessionId = session.getId().toLowerCase();
|
String sessionId = session.getId().toLowerCase();
|
||||||
SESSION_CACHE.remove(sessionId);
|
SESSION_CACHE.remove(sessionId);
|
||||||
List<String> sessionList = ROOM_SESSION_MAP.get(roomId);
|
List<String> sessionList = ROOM_SESSION_MAP.get(roomId);
|
||||||
if (sessionList.size() <= 1) {
|
if (CollectionUtils.isEmpty(sessionList) || sessionList.size() <= 1) {
|
||||||
ROOM_SESSION_MAP.remove(roomId);
|
ROOM_SESSION_MAP.remove(roomId);
|
||||||
} else {
|
} else {
|
||||||
sessionList.remove(sessionId);
|
sessionList.remove(sessionId);
|
||||||
|
|
@ -143,7 +148,7 @@ public class ChatRoom {
|
||||||
String sessionId = session.getId().toLowerCase();
|
String sessionId = session.getId().toLowerCase();
|
||||||
SESSION_CACHE.remove(sessionId);
|
SESSION_CACHE.remove(sessionId);
|
||||||
List<String> sessionList = ROOM_SESSION_MAP.get(roomId);
|
List<String> sessionList = ROOM_SESSION_MAP.get(roomId);
|
||||||
if (sessionList.size() <= 1) {
|
if (CollectionUtils.isEmpty(sessionList) || sessionList.size() <= 1) {
|
||||||
ROOM_SESSION_MAP.remove(roomId);
|
ROOM_SESSION_MAP.remove(roomId);
|
||||||
} else {
|
} else {
|
||||||
sessionList.remove(sessionId);
|
sessionList.remove(sessionId);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue