Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/disaster-tab' into dev-check
Browse files Browse the repository at this point in the history
  • Loading branch information
versatile0010 committed Nov 21, 2023
2 parents 350601d + 96d4e4f commit f85b3fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

@Slf4j
Expand Down Expand Up @@ -50,16 +51,16 @@ 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);
return member.getFcmToken();
}).toList();
}).filter(Objects::nonNull).toList();

// fcm 메세지 일괄 전송
fcmMessageProvider.sendFcmToMembers(targetMemberFcmTokens, title, message, NotificationTag.DISASTER);


log.info("위험 지역에 위치한 회원의 가족에게 알림을 보냅니다.");
// 해당 회원의 가족에게 알림을 보낸다.
String messageToFriend = "";
Expand All @@ -69,15 +70,19 @@ public void sendFcmMessagesByPresentLocation(DisasterEvent disasterEvent) {
.orElseThrow(NotFoundMemberException::new);

List<Member> friendList = member.getFriendships().stream()
.distinct().map(Friendship::getFriend).toList();
List<String> friendFcmTokens = friendList.stream().map(Member::getFcmToken).toList();
.map(Friendship::getFriend).distinct().toList();

List<String> 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("%s님이 안부를 궁금해하고 있어요.", memberName) +
String.format("걱정하고 있을 %s님을 위해 빨리 연락해주세요!", memberName),
String.format("가족 위험상태 변경 알림"),
String.format("""
%s님이 위험 지역에 있어요.
지금 바로 %s님에게 안부를 물어보세요!
""", memberName, memberName),
NotificationTag.FAMILY
);

Expand Down Expand Up @@ -108,7 +113,7 @@ public void sendFcmMessagesByPresentLocation(DisasterEvent disasterEvent) {
new NotificationEntity(member, disasterEvent.getType(), disasterEvent.getMessage(), true)
);
return isMatched ? Stream.of(member.getFcmToken()) : Stream.empty();
}).toList();
}).filter(Objects::nonNull).toList();
fcmMessageProvider.sendFcmToMembers(targetFcmListByOnboardingRegions, title, message, NotificationTag.DISASTER);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

}

0 comments on commit f85b3fd

Please sign in to comment.