Skip to content

Commit

Permalink
refactor: move mission message to another method
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed May 27, 2024
1 parent 24494c4 commit 1fb81ef
Showing 1 changed file with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,31 @@ public void onPostCreatedEvent(PostCreatedEvent postCreatedEvent) {
.setAndroidConfig(FCMNotificationUtil.buildAndroidConfig())
.build();
fcmNotificationService.sendMulticastMessage(multicastMessage);
}

if (post.getType() == PostType.SURVIVAL &&
memberPostService.isNewPostMadeMissionUnlocked(familyId)) {
// 방금 막 미션이 언락 되었다면..
HashSet<String> missionTargetFcmTokens = new HashSet<>();
for (String familyMemberId : familyMemberIds) {
missionTargetFcmTokens.addAll(memberDeviceService.getFcmTokensByMemberId(familyMemberId));
if(memberPostService.isNewPostMadeMissionUnlocked(familyId)) {
sendMissionUnlockedMessages(familyMemberIds);
}

MulticastMessage missionUnlockedMessage = MulticastMessage.builder()
.setNotification(
FCMNotificationUtil.buildNotification("열쇠를 획득해 미션 잠금이 해제되었어요!",
"사진 한 장을 더 찍을 수 있어요.")
)
.addAllTokens(missionTargetFcmTokens)
.setApnsConfig(FCMNotificationUtil.buildApnsConfig())
.setAndroidConfig(FCMNotificationUtil.buildAndroidConfig())
.build();
fcmNotificationService.sendMulticastMessage(missionUnlockedMessage);
}
}
}

private void sendMissionUnlockedMessages(List<String> familyMemberIds) {
// 방금 막 미션이 언락 되었다면..
HashSet<String> missionTargetFcmTokens = new HashSet<>();
for (String familyMemberId : familyMemberIds) {
missionTargetFcmTokens.addAll(memberDeviceService.getFcmTokensByMemberId(familyMemberId));
}

MulticastMessage missionUnlockedMessage = MulticastMessage.builder()
.setNotification(
FCMNotificationUtil.buildNotification("열쇠를 획득해 미션 잠금이 해제되었어요!",
"사진 한 장을 더 찍을 수 있어요.")
)
.addAllTokens(missionTargetFcmTokens)
.setApnsConfig(FCMNotificationUtil.buildApnsConfig())
.setAndroidConfig(FCMNotificationUtil.buildAndroidConfig())
.build();
fcmNotificationService.sendMulticastMessage(missionUnlockedMessage);
}

@Transactional(Transactional.TxType.REQUIRES_NEW)
Expand Down

0 comments on commit 1fb81ef

Please sign in to comment.