Skip to content
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
@@ -1,10 +1,12 @@
package org.websoso.WSSServer.dto.notification;

import static org.websoso.WSSServer.domain.common.NotificationTypeGroup.NOTICE;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Set;
import org.websoso.WSSServer.domain.Notification;
import org.websoso.WSSServer.domain.common.NotificationTypeGroup;

public record NotificationInfo(
Long notificationId,
Expand All @@ -23,15 +25,15 @@ public record NotificationInfo(
private static final String DATE_PATTERN = "yyyy.MM.dd";

static public NotificationInfo of(Notification notification, Boolean isRead) {
Set<String> validNoticeTypes = Set.of("공지", "이벤트");
return new NotificationInfo(
notification.getNotificationId(),
notification.getNotificationType().getNotificationTypeImage(),
notification.getNotificationTitle(),
notification.getNotificationBody(),
formatCreatedDate(notification.getCreatedDate()),
isRead,
validNoticeTypes.contains(notification.getNotificationType().getNotificationTypeName()),
NotificationTypeGroup.isTypeInGroup(notification.getNotificationType().getNotificationTypeName(),
NOTICE),
notification.getFeedId()
);
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/websoso/WSSServer/notification/FCMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.google.firebase.messaging.ApnsConfig;
import com.google.firebase.messaging.Aps;
import com.google.firebase.messaging.ApsAlert;
import com.google.firebase.messaging.BatchResponse;
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 com.google.firebase.messaging.SendResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -55,7 +57,17 @@ private Message createMessage(String targetFCMToken, FCMMessageRequest fcmMessag
public void sendMulticastPushMessage(List<String> targetFCMTokens, FCMMessageRequest fcmMessageRequest) {
MulticastMessage multicastMessage = createMulticastMessage(targetFCMTokens, fcmMessageRequest);
try {
firebaseMessaging.sendEachForMulticast(multicastMessage);
BatchResponse batchResponse = firebaseMessaging.sendEachForMulticast(multicastMessage);
// 푸시알림 전송 실패한 메시지 로그 기록
List<SendResponse> responses = batchResponse.getResponses();
for (int i = 0; i < responses.size(); i++) {
if (responses.get(i).isSuccessful()) {
log.info("[FCM 전송 성공] Token: {}", targetFCMTokens.get(i));
} else {
log.error("[FCM 전송 실패] Token: {} - Error: {}", targetFCMTokens.get(i),
responses.get(i).getException().getMessage());
}
}
} catch (Exception e) {
log.error("[FirebaseMessagingException] exception ", e);
// TODO: discord로 알림 추가 혹은 후속 작업 논의 후 추가
Expand Down
Loading