Skip to content

Commit

Permalink
[Feat]: 친구 수락 푸시알림 Data 추가 (#139)
Browse files Browse the repository at this point in the history
친구 수락 푸시알림시 friendId와 type 전송

Related to: #138
  • Loading branch information
dev-Crayon authored Jun 3, 2024
1 parent 46e8b70 commit c808c65
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@ public void sendNotificationByToken(PushNotificationRequest request) {
sendMessageToFirebase(message, user.getId());
}

public void sendNotificationByTokenWithFriendData(PushNotificationRequest request) {
User user = UserServiceUtil.findUserById(userRepository, request.userId());

Message message = Message.builder()
.setToken(user.getDeviceToken())
.setNotification(
Notification.builder()
.setTitle(request.title())
.setBody(request.body())
.build()
)
.setAndroidConfig(
AndroidConfig.builder()
.setNotification(
AndroidNotification.builder()
.setTitle(request.title())
.setBody(request.body())
.setClickAction("push_click")
.build()
)
.build()
)
.setApnsConfig(
ApnsConfig.builder()
.setAps(Aps.builder()
.setCategory("push_click")
.build())
.build()
)
.putData("title", request.title())
.putData("body", request.body() == null ? "" : request.body())
.putData("type", request.type())
.putData("friendId", request.data().get("friendId"))
.build();

sendMessageToFirebase(message, user.getId());
}

private void sendMessageToFirebase(Message message, Long userId) {
try {
firebaseMessaging.send(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -150,16 +151,17 @@ public HandleFriendRequestResponse updateNoticeStatus(Long userId, Long noticeId
sender.getUsername()
));

fcmPushService.sendNotificationByToken(PushNotificationRequest.builder()
fcmPushService.sendNotificationByTokenWithFriendData(PushNotificationRequest.builder()
.userId(sender.getId())
.title(receiver.getUsername() + "님이 친구를 수락했어요")
.type("notice")
.type("share")
.data(Map.of("friendId", Long.toString(userId)))
.build());
} else {
fcmPushService.sendNotificationByToken(PushNotificationRequest.builder()
.userId(sender.getId())
.title(receiver.getUsername() + "님이 친구를 거절했어요")
.type("notice")
.type("notice")
.build());
}

Expand Down

0 comments on commit c808c65

Please sign in to comment.