Skip to content
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

[Feat]: 친구 수락 푸시알림 Data 추가 #139

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading