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

fix : FCM Notification -> data 방식으로 변환 #66

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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 @@ -10,6 +10,8 @@
import springwebsocket.webchat.member.entity.Member;
import springwebsocket.webchat.member.repository.springdata.SpringDataJpaMemberRepository;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@RequiredArgsConstructor
Expand All @@ -23,28 +25,27 @@ public String sendNotificationByToken(FCMNotificationRequestDto requestDto) {
Optional<Member> member = jpaMemberRepository.findByEmail(requestDto.getTargetUserEmail());
if (member.isPresent()) {
if (member.get().getFirebaseToken() != null) {
Notification notification = Notification.builder()
.setTitle(requestDto.getTitle())
.setBody(requestDto.getBody())
.build();
Map<String, String> data = new HashMap<>();
data.put("title", requestDto.getTitle());
data.put("body", requestDto.getBody());

Message message = Message.builder()
.setToken(member.get().getFirebaseToken())
.setNotification(notification)
.putAllData(data)
.build();

try {
firebaseMessaging.send(message);
return "알림을 성공적으로 전송했습니다. targetUserId = " + requestDto.getTargetUserEmail();
return "알림을 성공적으로 전송했습니다. targetUserEmail = " + requestDto.getTargetUserEmail();
} catch (FirebaseMessagingException e) {
e.printStackTrace();
return "알림 보내기를 실패하였습니다. targeetUserId = " + requestDto.getTargetUserEmail();
return "알림 보내기를 실패하였습니다. targetUserEmail = " + requestDto.getTargetUserEmail();
}
}else {
return "서버에 저장된 해당 유저의 FirebaseToken이 존재하지 않습니다. targetUserId = " + requestDto.getTargetUserEmail();
return "서버에 저장된 해당 유저의 FirebaseToken이 존재하지 않습니다. targetUserEmail = " + requestDto.getTargetUserEmail();
}
}else {
return "해당 유저가 존재하지 않습니다. targetUserId = " + requestDto.getTargetUserEmail();
return "해당 유저가 존재하지 않습니다. targetUserEmail = " + requestDto.getTargetUserEmail();
}
}
}
Loading