diff --git a/src/main/java/com/wooyeon/yeon/chat/controller/StompController.java b/src/main/java/com/wooyeon/yeon/chat/controller/StompController.java index 9bc49e8..f71e47a 100644 --- a/src/main/java/com/wooyeon/yeon/chat/controller/StompController.java +++ b/src/main/java/com/wooyeon/yeon/chat/controller/StompController.java @@ -88,7 +88,7 @@ public void enter(StompDto stompDto, @Header("Authorization") String token) { log.info("session count = " + sessionStore.get(roomId.toString())); log.info("FCM 메시지 전송함"); try { - fcmService.sendMessageTo(FcmDto.buildRequest(loginEmail, stompDto, userRepository, matchRepository)); + fcmService.sendMessageTo(FcmDto.buildRequest(loginEmail, stompDto, roomId, userRepository, matchRepository)); } catch (IOException e) { throw new WooyeonException(ExceptionCode.FCM_SEND_FAIL_ERROR); } diff --git a/src/main/java/com/wooyeon/yeon/common/fcm/dto/FcmDto.java b/src/main/java/com/wooyeon/yeon/common/fcm/dto/FcmDto.java index a98b9b5..95e91bb 100644 --- a/src/main/java/com/wooyeon/yeon/common/fcm/dto/FcmDto.java +++ b/src/main/java/com/wooyeon/yeon/common/fcm/dto/FcmDto.java @@ -46,6 +46,8 @@ public static class Notification { public static class Data { private String name; private String description; + private int chatRoomId; + private String type; } @Getter @@ -57,6 +59,7 @@ public static class Request { String body; String email; String description; + int chatRoomId; } @Getter @@ -72,8 +75,8 @@ public static class SaveResponse { private HttpStatus status; } - public static Request buildRequest(String loginEmail , StompDto stompDto, UserRepository userRepository, - MatchRepository matchRepository) { + public static Request buildRequest(String loginEmail , StompDto stompDto, Long roomId, + UserRepository userRepository, MatchRepository matchRepository) { User user = userRepository.findOptionalByEmail(loginEmail) .orElseThrow(() -> new IllegalArgumentException(ExceptionCode.LOGIN_USER_NOT_FOUND.toString())); @@ -91,11 +94,12 @@ public static Request buildRequest(String loginEmail , StompDto stompDto, UserRe User matchUser = userRepository.findOptionalByEmail(matchUserId) .orElseThrow(() -> new IllegalArgumentException(ExceptionCode.LOGIN_USER_NOT_FOUND.toString())); - return FcmDto.Request.builder() + return Request.builder() .title(user.getUserProfile().getNickname()) .body(stompDto.getMessage()) .targetToken(matchUser.getFcmToken()) .email(loginEmail) + .chatRoomId(Integer.parseInt(String.valueOf(roomId))) .build(); } } diff --git a/src/main/java/com/wooyeon/yeon/common/fcm/service/FcmService.java b/src/main/java/com/wooyeon/yeon/common/fcm/service/FcmService.java index 473ec65..86ef80f 100644 --- a/src/main/java/com/wooyeon/yeon/common/fcm/service/FcmService.java +++ b/src/main/java/com/wooyeon/yeon/common/fcm/service/FcmService.java @@ -53,7 +53,8 @@ public void sendMessageTo(FcmDto.Request request) throws IOException { request.getTitle(), request.getBody(), request.getEmail(), - request.getDescription()); + request.getDescription(), + request.getChatRoomId()); OkHttpClient client = new OkHttpClient(); RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); @@ -82,7 +83,7 @@ public void sendMessageTo(FcmDto.Request request) throws IOException { * @return */ public String makeMessage( - String targetToken, String title, String body, String email, String description + String targetToken, String title, String body, String email, String description, int chatRoomId ) throws JsonProcessingException { FcmDto fcmMessage = FcmDto.builder() @@ -97,6 +98,8 @@ public String makeMessage( ) .data( FcmDto.Data.builder() + .type("chat") + .chatRoomId(chatRoomId) .name(email) .description(description) .build() @@ -105,7 +108,6 @@ public String makeMessage( ) .validateOnly(false) .build(); - return objectMapper.writeValueAsString(fcmMessage); }