Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] - [채팅방 참여자 재정의 및 귓속말 기능] #64

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class QChatRoom extends EntityPathBase<ChatRoom> {

public final StringPath chatRoomId = createString("chatRoomId");

public final ListPath<Chatter, QChatter> chatters = this.<Chatter, QChatter>createList("chatters", Chatter.class, QChatter.class, PathInits.DIRECT2);

public final NumberPath<Long> id = createNumber("id", Long.class);

public final StringPath name = createString("name");

public final ListPath<com.tasksprints.auction.domain.user.model.User, com.tasksprints.auction.domain.user.model.QUser> users = this.<com.tasksprints.auction.domain.user.model.User, com.tasksprints.auction.domain.user.model.QUser>createList("users", com.tasksprints.auction.domain.user.model.User.class, com.tasksprints.auction.domain.user.model.QUser.class, PathInits.DIRECT2);

public QChatRoom(String variable) {
super(ChatRoom.class, forVariable(variable));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tasksprints.auction.api.socket;

import com.tasksprints.auction.domain.socket.dto.MessageDto;
import com.tasksprints.auction.domain.socket.dto.MessageDto.MessageType;
import com.tasksprints.auction.domain.socket.dto.WhisperDto;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
Expand All @@ -14,13 +16,22 @@ public class ChatController {

@MessageMapping("/chat/message")
public void message(MessageDto messageDto) {
if (MessageDto.MessageType.ENTER.equals(messageDto.getType())) {
if (MessageType.ENTER.equals(messageDto.getType())) {
messageDto.setMessage(messageDto.getSender() + "님이 입장하셨습니다.");
}

if (MessageDto.MessageType.LEAVE.equals(messageDto.getType())) {
if (MessageType.LEAVE.equals(messageDto.getType())) {
messageDto.setMessage(messageDto.getSender() + "님이 퇴장하셨습니다.");
}
simpMessageSendingOperations.convertAndSend("/sub/chat/room/" + messageDto.getRoomId(), messageDto);
simpMessageSendingOperations.convertAndSend("/topic/chat/room/" + messageDto.getRoomId(), messageDto);
}

@MessageMapping("/chat/message/whisper")
public void messageToOne(WhisperDto whisperDto) {
whisperDto.setMessage("[귓속말] " + whisperDto.getSender() + " : " + whisperDto.getMessage());
simpMessageSendingOperations.convertAndSend("/whisper/" + whisperDto.getReceiver(), whisperDto);
//유저 생성 시 "/whisper/{유저 email 또는 nickname}" 경로를 구독해야 귓속말이 가능
//유저가 보낼 때 받는 사람의 경로로 메시지를 전달 -> 받는 사람만 메시지를 볼 수 있음
//답장 또한 받은 사람이 보낼 사람의 경로로 메시지를 전달해 1대 1 채팅이 되도록 함
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public class ChatRoomController {

private final ChatService chatService;

@GetMapping("/chat/room")
public String chatRoomList(Model model) {
return "/chat/room";
} //채팅방 목록 화면

@GetMapping("/chat/room/all")
@ResponseBody
public List<ChatRoom> chatRoomAll() {
Expand All @@ -32,12 +27,6 @@ public ChatRoom createChatRoom(@RequestParam("name") String name) {
return chatService.createRoom(name);
} //채팅방 생성

@GetMapping("/chat/room/enter/{chatRoomId}")
public String enterChatRoom(Model model, @PathVariable(value = "chatRoomId") String chatRoomId) {
model.addAttribute("chatRoomId", chatRoomId);
return "/chat/enter";
} //채팅방 입장 화면

@GetMapping("/chat/room/{chatRoomId}")
@ResponseBody
public ChatRoom chatRoom(@PathVariable(value = "chatRoomId") String chatRoomId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
@EnableWebSocketMessageBroker
public class WebSockConfig implements WebSocketMessageBrokerConfigurer {

/*
/topic : 채팅방 전체 메시지 (공지) 경로
/bid : bid 메시지 (주로 bid 금액 업데이트 관련) 경로
/whisper : 귓속말 경로
*/

@Override
public void configureMessageBroker(MessageBrokerRegistry brokerRegistry) {
brokerRegistry.enableSimpleBroker("/sub"); //server
brokerRegistry.setApplicationDestinationPrefixes("/pub"); //client
brokerRegistry.enableSimpleBroker("/topic", "/bid", "/whisper");
brokerRegistry.setApplicationDestinationPrefixes("/app");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public enum MessageType {
private String sender;
private String message;


public void setMessage(String s) {
this.message = s;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tasksprints.auction.domain.socket.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class WhisperDto {

private String sender; //보내는 사람 email 또는 닉네임
private String receiver; //받는 사람 email 또는 닉네임
private String message;

public void setMessage(String message) {
this.message = message;
}
}

// email 은 unique 하기때문에 sender 와 receiver 로 사용 가능
// 하지만 nickname 을 고유하게 설정해서 nickname 을 사용해도 좋을 것 같음
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tasksprints.auction.domain.socket.model;

import com.tasksprints.auction.domain.user.model.User;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -27,13 +28,13 @@ public class ChatRoom {
private String name;

@OneToMany
@Column(name = "chatterList")
private List<Chatter> chatters;
@Column(name = "users")
private List<User> users;

@Builder
public ChatRoom(String name) {
this.chatRoomId = UUID.randomUUID().toString();
this.name = name;
this.chatters = new ArrayList<>();
this.users = new ArrayList<>();
}
}

This file was deleted.

This file was deleted.

105 changes: 0 additions & 105 deletions src/main/resources/templates/chat/enter.html

This file was deleted.

Loading