Skip to content

Conversation

@david-parkk
Copy link
Contributor

@david-parkk david-parkk commented Jan 1, 2026

#️⃣ 연관된 이슈

closes #377

📝작업 내용

  • 메세지 예외 처리

작업 상세 내용

FCM 토큰을 보유하지 않은 사용자의 경우, FCM Push 처리 중지

💬리뷰 요구사항

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요.

Summary by CodeRabbit

버그 수정

  • 알람 전송 조건 강화
    • 사용자의 FCM 토큰 등록 여부를 사전에 확인한 후 알람을 발송합니다. 토큰이 없는 사용자에게의 불필요한 전송 시도가 제거되어 안정성이 향상되었습니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 1, 2026

워크스루

FCM 알림 송수신 로직에 토큰 존재 여부 확인 단계를 추가합니다. AlarmService의 notifyAlarm 메서드가 기존 sendToUsers 대신 새로운 sendToUsersIfTokenExists 메서드를 호출하도록 변경되었습니다.

변경사항

코호트 / 파일 변경 요약
FcmService 메서드 추가
src/main/java/ku_rum/backend/domain/alarm/application/FcmService.java
새로운 공개 메서드 sendToUsersIfTokenExists() 추가. 현재 사용자 조회 후 UserFcmToken 존재 여부를 확인하고, 토큰이 없으면 로깅하여 종료, 있으면 기존 sendToUsers()로 위임
AlarmService 호출 변경
src/main/java/ku_rum/backend/domain/alarm/application/AlarmService.java
notifyAlarm() 메서드에서 fcmService.sendToUsers()의 호출을 fcmService.sendToUsersIfTokenExists()로 변경

예상 코드 리뷰 난이도

🎯 2 (Simple) | ⏱️ ~10 분

관련 가능성 있는 PR

  • [Fix] FCM Gradle + Function #361: FcmService의 FCM 송신 동작을 수정하는 PR (멀티캐스트 API 사용 업데이트)으로, 동일한 서비스 클래스의 관련 변경
  • [Fix] FCM 로깅 #359: FcmService 클래스에서 sendToUsers/sendToTopic에 로깅 및 에러 처리를 추가하는 PR으로, 동일한 메서드 체계의 관련 변경
  • [Feat] Notification 추가 #362: FcmService의 메시지 송신 동작을 수정하는 PR (Notification 페이로드 추가)으로, 동일한 메서드 호출 흐름의 관련 변경

🐰 친구 요청이 떠도는 그 순간,
토큰을 확인하고 조용히 속삭여,
null은 문제 없도록 다독여주고,
알림은 안전하게 날아가네요!
버그야 다시 인사하지 마라~! 🎯✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 제목은 메세지 예외 처리라는 작업 내용을 반영하고 있으며, 코드 변경의 주요 목적인 FCM 토큰 부재 시 처리 개선을 나타냅니다.
Description check ✅ Passed PR 설명이 필수 템플릿 항목들(연관 이슈, 작업 내용, 상세 내용)을 모두 포함하고 있으며 충실하게 작성되어 있습니다.
Linked Issues check ✅ Passed 코드 변경은 #377의 목표인 FCM 알림 처리 개선을 직접 다루고 있으며, 토큰 부재 시 예외 발생을 방지하는 구체적인 솔루션을 구현합니다.
Out of Scope Changes check ✅ Passed 모든 코드 변경이 #377 이슈 해결(FCM 토큰 부재 시 처리)과 직접 관련되어 있으며, 범위를 벗어난 변경이 없습니다.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d560a0 and 1335990.

📒 Files selected for processing (2)
  • src/main/java/ku_rum/backend/domain/alarm/application/AlarmService.java
  • src/main/java/ku_rum/backend/domain/alarm/application/FcmService.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/main/java/ku_rum/backend/domain/alarm/application/AlarmService.java (1)

60-72: 변경 사항 확인 완료, 단 FcmService 구현 검증 필요

알림 비활성화 체크 후 FCM 전송 시 토큰 존재 여부를 확인하는 새로운 메서드로 변경한 것은 적절합니다. 다만 FcmService.sendToUsersIfTokenExists 구현에 심각한 로직 오류가 있어 함께 수정이 필요합니다 (FcmService.java 리뷰 참고).

Comment on lines +39 to +49
public void sendToUsersIfTokenExists(FcmDirectDto fcmDirectDto) {
User user = userService.getUser();
Optional<UserFcmToken> token = userFcmTokenRepository.findByUser(user);

if (token.isEmpty()) {
log.info("FCM 토큰이 존재하지 않는 유저입니다. userId={}", user.getId());
return;
}

sendToUsers(fcmDirectDto);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

치명적 결함: 잘못된 사용자의 토큰을 확인하고 있습니다

현재 구현은 수신자가 아닌 현재 인증된 사용자의 FCM 토큰을 확인합니다.

문제점:

  • Line 40: userService.getUser()는 현재 인증된 사용자(예: 친구 요청을 보낸 사용자 A)를 반환합니다
  • 하지만 알림을 받아야 하는 사용자는 fcmDirectDto.userIds()에 포함된 수신자들(예: 친구 요청을 받는 사용자 B)입니다
  • 따라서 잘못된 사용자의 토큰 존재 여부를 확인하여 수신자가 토큰이 없어도 전송을 시도하거나, 반대로 수신자는 토큰이 있는데 전송하지 않을 수 있습니다

예시 시나리오:

  1. 사용자 A(토큰 있음)가 사용자 B(토큰 없음)에게 친구 요청
  2. 현재 코드는 A의 토큰을 확인 → 존재함 → sendToUsers 호출
  3. sendToUsers는 B에게 전송 시도 → B는 토큰이 없어서 예외 발생 (Line 122)
  4. 원래 의도한 예외 방지가 작동하지 않음
🔎 수정 제안

수신자 목록에서 토큰이 있는 사용자들에게만 전송하도록 변경:

 public void sendToUsersIfTokenExists(FcmDirectDto fcmDirectDto) {
-    User user = userService.getUser();
-    Optional<UserFcmToken> token = userFcmTokenRepository.findByUser(user);
+    List<User> users = userQueryService.getUsersByIds(fcmDirectDto.userIds());
+    List<UserFcmToken> userFcmTokens = userFcmTokenRepository.findByUserIn(users);
 
-    if (token.isEmpty()) {
-        log.info("FCM 토큰이 존재하지 않는 유저입니다. userId={}", user.getId());
+    if (userFcmTokens.isEmpty()) {
+        log.info("FCM 토큰이 존재하지 않는 유저입니다. userIds={}", fcmDirectDto.userIds());
         return;
     }
 
     sendToUsers(fcmDirectDto);
 }

참고: 이렇게 수정하면 일부 사용자만 토큰이 없는 경우에도 Line 122의 validateUserToken에서 예외가 발생합니다. 토큰이 있는 사용자에게만 전송하려면 추가 필터링 로직이 필요합니다.

Committable suggestion skipped: line range outside the PR's diff.

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

Test Results

 38 files   38 suites   11s ⏱️
156 tests 156 ✅ 0 💤 0 ❌
157 runs  157 ✅ 0 💤 0 ❌

Results for commit 1335990.

@kmw10693 kmw10693 merged commit badc48a into develop Jan 1, 2026
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 2, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

친구 요청시 알림이 제대로 생성되지 않는 버그

3 participants