-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 앱 내 푸시알림 구현 #274
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
Merged
[FEAT] 앱 내 푸시알림 구현 #274
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
a17d943
[CHORE] firebase-admin 의존성 추가
Kim-TaeUk a1963af
[FEAT] FirebaseMessaging bean 등록을 위한 FCMConfig 추가
Kim-TaeUk aa387cf
[FEAT] Firebase SDK 인증 설정을 위한 GoogleCredentials 생성
Kim-TaeUk 9135d7e
[FEAT] Firebase SDK 초기화를 위한 FirebaseOptions 추가
Kim-TaeUk ad89ffa
[FEAT] Firebase SDK 초기화를 위한 FirebaseOptions 추가
Kim-TaeUk eac6dd4
[FEAT] Spring Bean으로 FirebaseMessaging 등록
Kim-TaeUk 3a130ac
[REFACTOR] Firebase 설정 경로 @Value를 통해 외부에서 주입하도록 수정
Kim-TaeUk c5440d4
[FEAT] FCM message 전송을 위한 FCMService 추가
Kim-TaeUk 8460aa8
[CHORE] FirebaseMessaging Bean 의존성 주입
Kim-TaeUk a5cbdb1
[CHORE] FCM key file gitignore에 추가
Kim-TaeUk 330334c
[FEAT] Message에 필요한 AndroidConfig 추가
Kim-TaeUk a19323a
[FEAT] Message에 필요한 ApsConfig 추가
Kim-TaeUk c23cfc7
[FEAT] specific device에 대한 Message 생성 로직 추가
Kim-TaeUk 3e4710c
[FEAT] FCM에 specific device에 대한 Message 전송 로직 추가
Kim-TaeUk 6286ced
[CHORE] logging을 위한 Slf4j 추가
Kim-TaeUk 4a19453
[FEAT] firebaseMessaging.send()에서 발생하는 Exception 처리
Kim-TaeUk c93d9b4
[COMMENT] FirebaseMessagingException logging 외 추가 처리 작업 가능성 코멘트 추가
Kim-TaeUk db4b1f3
[REFACTOR] Message 생성 로직 method로 분리
Kim-TaeUk 97de844
[REFACTOR] Message 생성부 try문 밖으로 분리
Kim-TaeUk c77a256
[CHORE] logging을 위한 Slf4j 추가
Kim-TaeUk 1658b73
[FIX] FirebaseMessaging Bean 등록 실패 시, 예외 throw 및 logging 추가
Kim-TaeUk 43bf246
[FEAT] 푸시 알림 지원을 위한 FCM token 컬럼 User 엔티티에 추가
Kim-TaeUk 9584af6
[FEAT] FCM token 등록 요청 처리를 위한 FCMTokenRequest DTO 추가
Kim-TaeUk bd0a14a
[FEAT] UserController에 FCM token 등록 엔드포인트 추가
Kim-TaeUk b2b108c
[FEAT] User 엔티티에 FCM token 업데이트 메서드 추가
Kim-TaeUk 41d366a
[FEAT] UserService에 FCM token 등록 로직 추가
Kim-TaeUk bf1fffc
[FEAT] FCMTokenRequest에 @NotBlank 유효성 검사를 추가
Kim-TaeUk 97542c4
[FIX] 수정된 데이터 포맷에 맞게 수정
Kim-TaeUk fe18600
[CHORE] FCMService Bean 의존성 주입
Kim-TaeUk b674512
[FEAT] feed 작성자(알림 보낼 대상)의 fcm token 획득
Kim-TaeUk 7cb57cb
[FEAT] 연결 작품이 있는 경우와 없는 경우로 로직 분리
Kim-TaeUk 0f8f705
[FEAT] 연결 작품이 없는 경우 sendPushMessage 로직 추가
Kim-TaeUk b089751
[FEAT] 연결 작품이 있는 경우 sendPushMessage 로직 추가
Kim-TaeUk 9806c62
[REFACTOR] 좋아요 발생 시 push 전송 로직 메서드로 분리
Kim-TaeUk b9723a9
[REFACTOR] 연결 작품에 따른 title 설정 로직 메서드로 분리
Kim-TaeUk dfad14f
[FIX] 정책에 맞게 title 길이 조건 반영
Kim-TaeUk 40129f1
[REFACTOR] sendPushMessage()의 파라미터 inline
Kim-TaeUk 1d6b803
[CHORE] FCMService Bean 의존성 주입
Kim-TaeUk 77000ec
[CHORE] NovelService Bean 의존성 주입
Kim-TaeUk 6ba337f
[FEAT] 지금 뜨는 수다글 선정 시 push 전송 로직 추가
Kim-TaeUk 4d34e2f
[REFACTOR] 작품 연결 여부에 따라 달라지는 notification body 생섬 부분 메서드로 분리
Kim-TaeUk c12aa73
[FIX] 정책에 맞게 UX라이팅 수정
Kim-TaeUk bd68395
[CHORE] FCMService Bean 의존성 주입
Kim-TaeUk 486f3fb
[FIX] CommentService의 createComment() 메서드 시그니처 변경
Kim-TaeUk e103d45
[CHORE] NovelService Bean 의존성 주입
Kim-TaeUk 5830760
[FEAT] 내 글에 댓글 남겼을 때 sendPushMessage 로직 추가
Kim-TaeUk b8e657c
[REMOVE] 불필요한 주석 제거
Kim-TaeUk f1d7585
[RENAME] 내 글에 댓글 남겼을 때 푸시 발송 메서드 rename
Kim-TaeUk 2f30455
[FEAT] multiple devices에 대한 Message 생성 로직 추가 - Multicast Message
Kim-TaeUk f9c1136
[FEAT] firebaseMessaging.sendMulticast()에서 발생하는 Exception 처리
Kim-TaeUk d137357
[FEAT] 내가 댓글 단 글에 새로운 댓글이 달린 경우 sendMulticastPushMessage 로직 추가
Kim-TaeUk ea961fa
[RENAME] from sendMulticastMessage to sendMulticastPushMessage
Kim-TaeUk 497b8cc
[FIX] FCM 알림 대상에서 본인은 제외
Kim-TaeUk 9ce4c1a
[FEAT] FCM 메시지 처리를 위한 FCMMessageRequest DTO 추가
Kim-TaeUk 6451275
[REFACTOR] FCM message 처리 시 FCMNotificationRequest DTO로 간소화
Kim-TaeUk c6e96f6
[FIX] UX 라이팅에서 누락된 이모지 추가
Kim-TaeUk 7605b98
[FIX] 중복 체크를 통한 동일 push 중복 전송 방지
Kim-TaeUk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -44,3 +44,5 @@ src/main/generated/ | |
|
|
||
| ## Apple Login Key File ## | ||
| *.p8 | ||
|
|
||
| /src/main/resources/websoso-fcm.json | ||
This file contains hidden or 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 hidden or 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/websoso/WSSServer/dto/user/FCMTokenRequest.java
This file contains hidden or 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,9 @@ | ||
| package org.websoso.WSSServer.dto.user; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record FCMTokenRequest( | ||
| @NotBlank(message = "FCM Token 값은 null 이거나, 공백일 수 없습니다.") | ||
| String fcmToken | ||
| ) { | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/websoso/WSSServer/notification/FCMConfig.java
This file contains hidden or 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,41 @@ | ||
| package org.websoso.WSSServer.notification; | ||
|
|
||
| import com.google.auth.oauth2.GoogleCredentials; | ||
| import com.google.firebase.FirebaseApp; | ||
| import com.google.firebase.FirebaseOptions; | ||
| import com.google.firebase.messaging.FirebaseMessaging; | ||
| import java.io.IOException; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.io.ClassPathResource; | ||
|
|
||
| @Slf4j | ||
| @Configuration | ||
| public class FCMConfig { | ||
|
|
||
| @Value("${fcm.key-path}") | ||
| private String firebaseConfigPath; | ||
|
|
||
| @Bean | ||
| public FirebaseMessaging firebaseMessaging() { | ||
| try { | ||
| GoogleCredentials googleCredentials = GoogleCredentials | ||
| .fromStream(new ClassPathResource(firebaseConfigPath).getInputStream()); | ||
|
|
||
| FirebaseOptions firebaseOptions = FirebaseOptions.builder() | ||
| .setCredentials(googleCredentials) | ||
| .build(); | ||
|
|
||
| if (FirebaseApp.getApps().isEmpty()) { | ||
| FirebaseApp.initializeApp(firebaseOptions); | ||
| } | ||
|
|
||
| return FirebaseMessaging.getInstance(); | ||
| } catch (IOException e) { | ||
| log.error("[FirebaseMessaging] Failed to initialize FirebaseMessaging", e); | ||
| throw new IllegalStateException("Failed to initialize FirebaseMessaging due to firebase key file", e); | ||
| } | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/websoso/WSSServer/notification/FCMService.java
This file contains hidden or 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,83 @@ | ||
| package org.websoso.WSSServer.notification; | ||
|
|
||
| import com.google.firebase.messaging.ApnsConfig; | ||
| import com.google.firebase.messaging.Aps; | ||
| import com.google.firebase.messaging.ApsAlert; | ||
| import com.google.firebase.messaging.FirebaseMessaging; | ||
| import com.google.firebase.messaging.FirebaseMessagingException; | ||
| import com.google.firebase.messaging.Message; | ||
| import com.google.firebase.messaging.MulticastMessage; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.websoso.WSSServer.notification.dto.FCMMessageRequest; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class FCMService { | ||
|
|
||
| private final FirebaseMessaging firebaseMessaging; | ||
|
|
||
| public void sendPushMessage(String targetFCMToken, FCMMessageRequest fcmMessageRequest) { | ||
| Message message = createMessage(targetFCMToken, fcmMessageRequest); | ||
|
|
||
| try { | ||
| firebaseMessaging.send(message); | ||
| } catch (FirebaseMessagingException e) { | ||
| log.error("[FirebaseMessagingException] exception ", e); | ||
| // TODO: discord로 알림 추가 혹은 후속 작업 논의 후 추가 | ||
| } | ||
| } | ||
|
|
||
| private Message createMessage(String targetFCMToken, FCMMessageRequest fcmMessageRequest) { | ||
| ApnsConfig apnsConfig = ApnsConfig.builder() | ||
| .setAps(Aps.builder() | ||
| .setAlert(ApsAlert.builder() | ||
| .setTitle(fcmMessageRequest.title()) | ||
| .setBody(fcmMessageRequest.body()) | ||
| .build()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| return Message.builder() | ||
| .setToken(targetFCMToken) | ||
| .putData("title", fcmMessageRequest.title()) | ||
| .putData("body", fcmMessageRequest.body()) | ||
| .putData("feedId", fcmMessageRequest.feedId()) | ||
| .putData("view", fcmMessageRequest.view()) | ||
Kim-TaeUk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .setApnsConfig(apnsConfig) | ||
| .build(); | ||
| } | ||
|
|
||
| public void sendMulticastPushMessage(List<String> targetFCMTokens, FCMMessageRequest fcmMessageRequest) { | ||
| MulticastMessage multicastMessage = createMulticastMessage(targetFCMTokens, fcmMessageRequest); | ||
| try { | ||
| firebaseMessaging.sendMulticast(multicastMessage); | ||
| } catch (Exception e) { | ||
| log.error("[FirebaseMessagingException] exception ", e); | ||
| // TODO: discord로 알림 추가 혹은 후속 작업 논의 후 추가 | ||
| } | ||
| } | ||
|
|
||
| private MulticastMessage createMulticastMessage(List<String> targetFCMTokens, FCMMessageRequest fcmMessageRequest) { | ||
| ApnsConfig apnsConfig = ApnsConfig.builder() | ||
| .setAps(Aps.builder() | ||
| .setAlert(ApsAlert.builder() | ||
| .setTitle(fcmMessageRequest.title()) | ||
| .setBody(fcmMessageRequest.body()) | ||
| .build()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| return MulticastMessage.builder() | ||
| .addAllTokens(targetFCMTokens) | ||
| .putData("title", fcmMessageRequest.title()) | ||
| .putData("body", fcmMessageRequest.body()) | ||
| .putData("feedId", fcmMessageRequest.feedId()) | ||
| .putData("view", fcmMessageRequest.view()) | ||
| .setApnsConfig(apnsConfig) | ||
| .build(); | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
src/main/java/org/websoso/WSSServer/notification/dto/FCMMessageRequest.java
This file contains hidden or 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,13 @@ | ||
| package org.websoso.WSSServer.notification.dto; | ||
|
|
||
| public record FCMMessageRequest( | ||
| String title, | ||
| String body, | ||
| String feedId, | ||
| String view | ||
| ) { | ||
|
|
||
| public static FCMMessageRequest of(String title, String body, String feedId, String view) { | ||
| return new FCMMessageRequest(title, body, feedId, view); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.