Skip to content

Commit

Permalink
Merge pull request #49 from Team-Wable/feat/#48
Browse files Browse the repository at this point in the history
[FEAT] 대댓글 좋아요 기능 개발
  • Loading branch information
Hong0329 authored Nov 17, 2024
2 parents df3f4e9 + 08a5111 commit ccfd546
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,40 +199,75 @@ public void likeComment(Long memberId, Long commentId, CommentLikedRequestDto co
.build();
CommentLiked savedCommentLiked = commentLikedRepository.save(commentLiked);

if(triggerMember != targetMember) { ////자신 게시물에 대한 좋아요 누르면 알림 발생 x
//노티 엔티티와 연결
Notification notification = Notification.builder()
.notificationTargetMember(targetMember)
.notificationTriggerMemberId(triggerMember.getId())
.notificationTriggerType(commentLikedRequestDto.notificationTriggerType())
.notificationTriggerId(commentId) //에러수정을 위한 notificationTriggerId에 답글id 저장, 알림 조회시 답글id로 게시글id 반환하도록하기
.isNotificationChecked(false)
.notificationText(comment.getCommentText())
.build();
Notification savedNotification = notificationRepository.save(notification);
if(triggerMember != targetMember) {
if(comment.getParentCommentId().equals(-1L)) {
Notification notification = Notification.builder()
.notificationTargetMember(targetMember)
.notificationTriggerMemberId(triggerMember.getId())
.notificationTriggerType(commentLikedRequestDto.notificationTriggerType())
.notificationTriggerId(commentId) //에러수정을 위한 notificationTriggerId에 답글id 저장, 알림 조회시 답글id로 게시글id 반환하도록하기
.isNotificationChecked(false)
.notificationText(comment.getCommentText())
.build();
Notification savedNotification = notificationRepository.save(notification);


if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 답글을 좋아합니다.";
targetMember.increaseFcmBadge();
FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder()
.validateOnly(false)
.message(FcmMessageDto.Message.builder()
.notificationDetails(FcmMessageDto.NotificationDetails.builder()
.title(FcmMessageTitle)
.body("")
.build())
.token(targetMember.getFcmToken())
.data(FcmMessageDto.Data.builder()
.name("commentLike")
.description("답글 좋아요 푸시 알림")
.relateContentId(String.valueOf(contentId))
.build())
.badge(targetMember.getFcmBadge())
.build())
if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 댓글을 좋아합니다.";
targetMember.increaseFcmBadge();
FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder()
.validateOnly(false)
.message(FcmMessageDto.Message.builder()
.notificationDetails(FcmMessageDto.NotificationDetails.builder()
.title(FcmMessageTitle)
.body("")
.build())
.token(targetMember.getFcmToken())
.data(FcmMessageDto.Data.builder()
.name("commentLike")
.description("댓글 좋아요 푸시 알림")
.relateContentId(String.valueOf(contentId))
.build())
.badge(targetMember.getFcmBadge())
.build())
.build();

fcmService.sendMessage(commentLikeFcmMessage);
}
} else {
Notification notification = Notification.builder()
.notificationTargetMember(targetMember)
.notificationTriggerMemberId(triggerMember.getId())
.notificationTriggerType("childCommentLiked")
.notificationTriggerId(commentId)
.isNotificationChecked(false)
.notificationText(comment.getCommentText())
.build();
Notification savedNotification = notificationRepository.save(notification);


fcmService.sendMessage(commentLikeFcmMessage);
if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 답글을 좋아합니다.";
targetMember.increaseFcmBadge();
FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder()
.validateOnly(false)
.message(FcmMessageDto.Message.builder()
.notificationDetails(FcmMessageDto.NotificationDetails.builder()
.title(FcmMessageTitle)
.body("")
.build())
.token(targetMember.getFcmToken())
.data(FcmMessageDto.Data.builder()
.name("childCommentLike")
.description("답글 좋아요 푸시 알림")
.relateContentId(String.valueOf(contentId))
.build())
.badge(targetMember.getFcmBadge())
.build())
.build();

fcmService.sendMessage(commentLikeFcmMessage);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ private long refineNotificationTriggerId (String triggerType, Long triggerId, No
}
//todo 추후에 인기글 -> 불꽃, 정보 -> 확성기, 시스템 -> wable로고, 사용자 -> 프로필 사진
private String profileUrl(Long notificationId, String triggerType){
if(triggerType.equals("comment") || triggerType.equals("commentLiked") || triggerType.equals("contentLiked")){
if(triggerType.equals("comment") || triggerType.equals("commentLiked") || triggerType.equals("contentLiked")
|| triggerType.equals("childCommentLiked") || triggerType.equals("childComment")){
Notification notification = notificationRepository.findNotificationById(notificationId);
Member triggerMember = memberRepository.findMemberByIdOrThrow(notification.getNotificationTriggerMemberId());
return triggerMember.getProfileUrl();
Expand Down

0 comments on commit ccfd546

Please sign in to comment.