Skip to content

Commit 89636b6

Browse files
committed
Merge branch 'dev' of https://github.com/CommitField/commitField into Feature/89
2 parents 9f8aa67 + cc18b69 commit 89636b6

File tree

8 files changed

+36
-12
lines changed

8 files changed

+36
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ jobs:
2121
id: create_tag
2222
uses: mathieudutour/github-tag-action@v6.1
2323
with:
24-
github_token: ${{ secrets.TOKEN_GITHUB }}
24+
github_token: ${{ secrets.GITHUB_TOKEN }}
2525
- name: Create Release
2626
id: create_release
2727
uses: actions/create-release@v1
2828
env:
29-
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030
with:
3131
tag_name: ${{ steps.create_tag.outputs.new_tag }}
3232
release_name: Release ${{ steps.create_tag.outputs.new_tag }}
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
registry: ghcr.io
4848
username: ${{ github.actor }}
49-
password: ${{ secrets.TOKEN_GITHUB }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
5050
- name: set lower case owner name
5151
run: |
5252
echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}

src/main/java/cmf/commitField/domain/chat/chatMessage/controller/response/ChatMsgResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@AllArgsConstructor
1111
@Builder
1212
public class ChatMsgResponse {
13+
private Long chatMsgId;
1314
private Long roomId;
1415
//사용자(user)
1516
private String from;

src/main/java/cmf/commitField/domain/chat/chatMessage/service/ChatMessageServiceImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class ChatMessageServiceImpl implements ChatMessageService {
3333
private final ChatMessageCustomRepository chatMessageCustomRepository;
3434
private final UserChatRoomRepository userChatRoomRepository;
3535

36+
// 커밋용 주석
37+
3638
@Override
3739
@Transactional
3840
public ChatMsgResponse sendMessage(ChatMsgRequest message, Long userId, Long roomId) {
@@ -48,14 +50,19 @@ public ChatMsgResponse sendMessage(ChatMsgRequest message, Long userId, Long roo
4850
.user(findUser)
4951
.chatRoom(chatRoom)
5052
.build();
51-
// Response
53+
54+
// 메시지 저장
55+
ChatMsg savedMsg = chatMessageRepository.save(chatMsg);
56+
57+
// Response - 메시지 ID 추가
5258
ChatMsgResponse response = ChatMsgResponse.builder()
59+
.chatMsgId(savedMsg.getId()) // 저장된 메시지의 ID 추가
5360
.roomId(roomId)
5461
.from(findUser.getNickname())
5562
.message(message.getMessage())
5663
.sendAt(chatMsg.getCreatedAt())
5764
.build();
58-
chatMessageRepository.save(chatMsg);
65+
5966
return response;
6067
}
6168

@@ -86,4 +93,4 @@ public List<ChatMsgDto> getRoomChatMsgList(Long roomId, Long userId, Long lastId
8693
}
8794
return chatMsgDtos;
8895
}
89-
}
96+
}

src/main/java/cmf/commitField/global/config/RedisConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public class RedisConfig {
2828
@Bean
2929
public RedissonClient redissonClient() {
3030
Config config = new Config();
31+
String redisAddress = "redis://" + host + ":" + port;
3132
config.useSingleServer()
32-
.setAddress("redis://127.0.0.1:6379")
33+
.setAddress(redisAddress)
3334
.setPassword(password); // 비밀번호 추가
3435
return Redisson.create(config);
3536
}

src/main/java/cmf/commitField/global/websocket/ChatWebSocketHandler.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ private void handleChatMessage(WebSocketSession session, JsonNode jsonNode) {
173173
Long roomId = jsonNode.get("roomId").asLong();
174174
Long userId = jsonNode.get("userId").asLong();
175175
String message = jsonNode.get("message").asText();
176+
String from = jsonNode.has("from") ? jsonNode.get("from").asText() : null;
177+
178+
log.info("채팅 메시지: roomId={}, userId={}, message={}, from={}", roomId, userId, message, from);
176179

177180
if (message == null || message.trim().isEmpty()) {
178181
sendErrorMessage(session, "메시지 내용이 비어있습니다.");
179182
return;
180183
}
181184

182-
log.info("채팅 메시지: roomId={}, userId={}, message={}", roomId, userId, message);
183-
184185
// 사용자 정보 검증
185186
User user = userRepository.findById(userId).orElse(null);
186187
if (user == null) {
@@ -194,8 +195,20 @@ private void handleChatMessage(WebSocketSession session, JsonNode jsonNode) {
194195
ChatMsgRequest chatMsgRequest = new ChatMsgRequest(message);
195196
ChatMsgResponse response = chatMessageService.sendMessage(chatMsgRequest, userId, roomId);
196197

197-
// 메시지 포맷 변환하여 전송
198-
String messageJson = objectMapper.writeValueAsString(response);
198+
// 웹소켓 메시지 포맷 생성 (클라이언트와 일치시킴)
199+
Map<String, Object> wsMessage = new HashMap<>();
200+
wsMessage.put("type", "CHAT");
201+
wsMessage.put("roomId", roomId);
202+
wsMessage.put("userId", userId);
203+
wsMessage.put("chatMsgId", response.getChatMsgId()); // DB에 저장된 메시지 ID 추가
204+
wsMessage.put("from", response.getFrom());
205+
wsMessage.put("nickname", response.getFrom()); // 클라이언트 호환성을 위해 두 필드 모두 설정
206+
wsMessage.put("message", message);
207+
wsMessage.put("sendAt", response.getSendAt().toString());
208+
209+
// 메시지 JSON 변환
210+
String messageJson = objectMapper.writeValueAsString(wsMessage);
211+
log.info("Broadcasting message: {}", messageJson);
199212

200213
// 해당 채팅방의 모든 세션에 메시지 브로드캐스트
201214
broadcastMessageToRoom(roomId, messageJson);
@@ -223,9 +236,11 @@ private void broadcastMessageToRoom(Long roomId, String message) {
223236
for (WebSocketSession session : roomSessions) {
224237
try {
225238
if (session.isOpen()) {
239+
log.debug("Broadcasting to session {}", session.getId());
226240
session.sendMessage(new TextMessage(message));
227241
} else {
228242
failedSessions.add(session);
243+
log.debug("Session closed, adding to failed sessions: {}", session.getId());
229244
}
230245
} catch (IOException e) {
231246
log.error("메시지 브로드캐스트 중 오류: {}", e.getMessage());

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ spring:
3333
frontUrl: "http://${custom.dev.cookieDomain}:5173"
3434
backUrl: "http://${custom.dev.cookieDomain}:${server.port}"
3535
prod:
36-
cookieDomain: cmf.seoez.site
36+
cookieDomain: cmfd.seoez.site
3737
frontUrl: "https://www.${custom.prod.cookieDomain}/"
3838
backUrl: "https://api.${custom.prod.cookieDomain}/"
3939
site:
795 KB
Loading
32.4 KB
Loading

0 commit comments

Comments
 (0)