From 96d4e4fc6ba15d18786e685dcd022b6d6a54def8 Mon Sep 17 00:00:00 2001 From: Jaehyeon Date: Wed, 22 Nov 2023 01:25:04 +0900 Subject: [PATCH] Feat: fix small bug --- .../service/DisasterEventHandler.java | 12 ++++++----- .../backend/domain/member/entity/Member.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/numberone/backend/domain/disaster/service/DisasterEventHandler.java b/src/main/java/com/numberone/backend/domain/disaster/service/DisasterEventHandler.java index 5f0b9b2a..9b5415e2 100644 --- a/src/main/java/com/numberone/backend/domain/disaster/service/DisasterEventHandler.java +++ b/src/main/java/com/numberone/backend/domain/disaster/service/DisasterEventHandler.java @@ -51,6 +51,7 @@ public void sendFcmMessagesByPresentLocation(DisasterEvent disasterEvent) { NotificationEntity savedNotificationEntity = notificationRepository.save( new NotificationEntity(member, disasterEvent.getType(), disasterEvent.getMessage(), true) ); + member.updateSafety(false); log.info("received member id: {} Notification id: {} ", member.getId(), savedNotificationEntity.getId()); log.info(title); log.info(message); @@ -60,7 +61,6 @@ public void sendFcmMessagesByPresentLocation(DisasterEvent disasterEvent) { // fcm 메세지 일괄 전송 fcmMessageProvider.sendFcmToMembers(targetMemberFcmTokens, title, message, NotificationTag.DISASTER); - log.info("위험 지역에 위치한 회원의 가족에게 알림을 보냅니다."); // 해당 회원의 가족에게 알림을 보낸다. String messageToFriend = ""; @@ -70,16 +70,18 @@ public void sendFcmMessagesByPresentLocation(DisasterEvent disasterEvent) { .orElseThrow(NotFoundMemberException::new); List friendList = member.getFriendships().stream() - .distinct().map(Friendship::getFriend).toList(); + .map(Friendship::getFriend).distinct().toList(); + List friendFcmTokens = friendList.stream().map(Member::getFcmToken).filter(Objects::nonNull).toList(); + String memberName = member.getRealName() != null ? member.getRealName() : member.getNickName(); fcmMessageProvider.sendFcmToMembers( friendFcmTokens, - String.format("긴급!"), + String.format("가족 위험상태 변경 알림"), String.format(""" - %s님이 안부를 궁금해하고 있어요. - 걱정하고 있을 %s님을 위해 빨리 연락해주세요! + %s님이 위험 지역에 있어요. + 지금 바로 %s님에게 안부를 물어보세요! """, memberName, memberName), NotificationTag.FAMILY ); diff --git a/src/main/java/com/numberone/backend/domain/member/entity/Member.java b/src/main/java/com/numberone/backend/domain/member/entity/Member.java index 5b6d513e..0a699a1b 100644 --- a/src/main/java/com/numberone/backend/domain/member/entity/Member.java +++ b/src/main/java/com/numberone/backend/domain/member/entity/Member.java @@ -13,11 +13,13 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.Hibernate; import org.hibernate.annotations.Comment; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Comment("회원 정보") @Entity @@ -158,4 +160,23 @@ public void updateLv2(String lv2) { public void updateLv3(String lv3) { this.lv3 = lv3; } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) { + return false; + } + Member that = (Member) o; + return id != null && Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return getClass().hashCode(); + } + }