-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from farmingsoon/develop
Main merge를 위한 배포
- Loading branch information
Showing
25 changed files
with
342 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/api/farmingsoon/domain/chat/dto/ChattingConnectResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.api.farmingsoon.domain.chat.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class ChattingConnectResponse { | ||
|
||
private Long connectMemberId; | ||
private final String type = "SEND"; | ||
|
||
public ChattingConnectResponse(Long connectMemberId) { | ||
this.connectMemberId = connectMemberId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/api/farmingsoon/domain/chatroom/event/ChatRoomDisConnectEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.api.farmingsoon.domain.chatroom.event; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class ChatRoomDisConnectEvent { | ||
|
||
private Long chatRoomId; | ||
private String sessionId; | ||
|
||
@Builder | ||
private ChatRoomDisConnectEvent(Long chatRoomId, String sessionId) { | ||
this.chatRoomId = chatRoomId; | ||
this.sessionId = sessionId; | ||
} | ||
} |
26 changes: 23 additions & 3 deletions
26
src/main/java/com/api/farmingsoon/domain/chatroom/listener/ChatRoomEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
package com.api.farmingsoon.domain.chatroom.listener; | ||
|
||
import com.api.farmingsoon.common.sse.SseService; | ||
import com.api.farmingsoon.domain.chat.dto.ChattingConnectResponse; | ||
import com.api.farmingsoon.domain.chat.service.ChatService; | ||
import com.api.farmingsoon.domain.chatroom.event.ChatRoomConnectEvent; | ||
import com.api.farmingsoon.domain.chatroom.service.ChatRoomRedisService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class ChatRoomEventListener { | ||
private final ChatService chatService; | ||
private final ChatRoomRedisService chatRoomRedisService; | ||
private final SimpMessagingTemplate messagingTemplate; | ||
|
||
|
||
/** | ||
* @Description | ||
* 1. 채팅방에 연결됐음을 저장 | ||
* 2. 연결된 사람의 채팅방에 안읽었던 메시지를 모두 읽음 처리 | ||
* 3. 채팅방에 상대방이 연결되었음을 알리는 알림 | ||
*/ | ||
@EventListener | ||
public void readAllChatAndSaveConnectMember(ChatRoomConnectEvent event){ | ||
chatRoomRedisService.connectChatRoom(event.getChatRoomId(), event.getSessionId()); | ||
chatService.readAllMyNotReadChatList(event.getChatRoomId(), event.getConnectMemberId()); | ||
messagingTemplate.convertAndSend("/sub/chat-room/" + event.getChatRoomId(), new ChattingConnectResponse(event.getConnectMemberId())); | ||
|
||
} | ||
|
||
@EventListener | ||
public void readAllChatMessage(ChatRoomConnectEvent event){ | ||
chatService.readAllMyNotReadChatList(event.getChatRoomId(), event.getMemberId()); | ||
public void deleteConnectMember(ChatRoomConnectEvent event){ | ||
chatRoomRedisService.disConnectChatRoom(event.getChatRoomId(), event.getSessionId()); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/api/farmingsoon/domain/chatroom/service/ChatRoomRedisService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.api.farmingsoon.domain.chatroom.service; | ||
|
||
import com.api.farmingsoon.common.redis.RedisService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatRoomRedisService { | ||
private final RedisService redisService; | ||
|
||
public void connectChatRoom(Long chatRoomId, String sessionId) { | ||
redisService.addToSet("chatRoom_" + chatRoomId, sessionId); | ||
} | ||
|
||
/** | ||
* 채팅방에 남은 사람이 한명이라면 나갈 때 키 삭제 | ||
*/ | ||
public void disConnectChatRoom(Long chatRoomId, String sessionId) { | ||
if(redisService.getSetSize("chatRoom_" + chatRoomId) == 1){ | ||
redisService.deleteData("chatRoom_" + chatRoomId); | ||
} | ||
redisService.deleteToSet("chatRoom_" + chatRoomId, sessionId); | ||
} | ||
public Long getConnectMemberSize(String key){ | ||
return redisService.getSetSize(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.