Skip to content

Commit

Permalink
채팅방 현황 관리 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
gkfktkrh153 committed Mar 29, 2024
1 parent bfac17f commit 056a76b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
);
else if (StompCommand.DISCONNECT.equals(command)) {
eventPublisher.publishEvent(ChatRoomDisConnectEvent.builder()
.chatRoomId(Long.valueOf(accessor.getFirstNativeHeader("chatRoomId")))
.sessionId(accessor.getSessionId())
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public void initialize() {
public void setData(String key, Object value, Long time,TimeUnit timeUnit) {
redisTemplate.opsForValue().set(key, value.toString(), time, timeUnit);
}
public void setData(String key, Object value) {
redisTemplate.opsForValue().set(key, value.toString());
}

public Object getData(String key) {
return redisTemplate.opsForValue().get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void readAllChatAndSaveConnectMember(ChatRoomConnectEvent event){

@EventListener
public void deleteConnectMember(ChatRoomDisConnectEvent event){
chatRoomRedisService.disConnectChatRoom(event.getChatRoomId(), event.getSessionId());
chatRoomRedisService.disConnectChatRoom(event.getSessionId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ public class ChatRoomRedisService {
public void connectChatRoom(Long chatRoomId, String sessionId) {
log.info("Chatroom Connect : chatRoomId = " + chatRoomId + " sessionId = " + sessionId);
redisService.addToSet("chatRoom_" + chatRoomId, sessionId);
redisService.setData(sessionId, chatRoomId); // session에 대한 채팅방 정보 저장
}

/**
* 채팅방에 남은 사람이 한명이라면 나갈 때 키 삭제
*/
public void disConnectChatRoom(Long chatRoomId, String sessionId) {
public void disConnectChatRoom(String sessionId) {
Long chatRoomId = (Long) redisService.getData(sessionId);
if(redisService.getSetSize("chatRoom_" + chatRoomId) == 1){
redisService.deleteData("chatRoom_" + chatRoomId);
}
redisService.deleteToSet("chatRoom_" + chatRoomId, sessionId);
else {
redisService.deleteToSet("chatRoom_" + chatRoomId, sessionId);
}
log.info("Chatroom DisConnect : chatRoomId = " + chatRoomId + " sessionId = " + sessionId);
}
public Long getConnectMemberSize(String key){
Expand Down

0 comments on commit 056a76b

Please sign in to comment.