Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 대댓글 좋아요 기능 개발 #49

Merged
merged 1 commit into from
Nov 17, 2024
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
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
Loading