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

[FIX] 소소피드 댓글 목록 필터링 로직 수정 #193

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions src/main/java/org/websoso/WSSServer/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class Comment extends BaseEntity {
@Column(nullable = false)
private Long userId;

@Column(columnDefinition = "Boolean default false", nullable = false)
private Boolean isSpoiler;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "feed_id", nullable = false)
private Feed feed;
Expand Down Expand Up @@ -76,4 +79,8 @@ private Comment(String commentContent, Long userId, Feed feed) {
public void hideComment() {
this.isHidden = true;
}

public void spoiler() {
this.isSpoiler = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ public record CommentGetResponse(
LocalDate createdDate,
String commentContent,
Boolean isModified,
Boolean isMyComment
Boolean isMyComment,
Boolean isSpoiler,
Boolean isBlocked,
Boolean isHidden
) {
public static CommentGetResponse of(UserBasicInfo userBasicInfo, Comment comment, Boolean isMyComment) {
public static CommentGetResponse of(UserBasicInfo userBasicInfo, Comment comment, Boolean isMyComment,
Boolean isSpoiler, Boolean isBlocked, Boolean isHidden) {
return new CommentGetResponse(
userBasicInfo.userId(),
userBasicInfo.nickname(),
isBlocked ? null : userBasicInfo.userId(),
isBlocked ? null : userBasicInfo.nickname(),
userBasicInfo.avatarImage(),
comment.getCommentId(),
comment.getCreatedDate().toLocalDate(),
comment.getCommentContent(),
isBlocked || isHidden ? null : comment.getCommentContent(),
ChaeAg marked this conversation as resolved.
Show resolved Hide resolved
!comment.getCreatedDate().equals(comment.getModifiedDate()),
isMyComment
isMyComment,
isSpoiler,
isBlocked,
isHidden
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public record CommentsGetResponse(
Integer commentsCount,
List<CommentGetResponse> comments
) {
public static CommentsGetResponse of(Integer commentsCount, List<CommentGetResponse> comments) {
public static CommentsGetResponse of(final List<CommentGetResponse> comments) {
return new CommentsGetResponse(
commentsCount,
comments.size(),
comments
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/websoso/WSSServer/service/BlockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ public boolean isBlockedRelationship(Long firstUserId, Long secondUserId) {
return blockRepository.existsByTwoUserId(firstUserId, secondUserId);
}

public boolean isBlocked(Long blockingId, Long blockedId) {
return blockRepository.existsByBlockingIdAndBlockedId(blockingId, blockedId);
}

}
28 changes: 17 additions & 11 deletions src/main/java/org/websoso/WSSServer/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.websoso.WSSServer.domain.common.Action.DELETE;
import static org.websoso.WSSServer.domain.common.Action.UPDATE;
import static org.websoso.WSSServer.domain.common.ReportedType.IMPERTINENCE;
import static org.websoso.WSSServer.domain.common.ReportedType.SPOILER;
import static org.websoso.WSSServer.exception.error.CustomCommentError.COMMENT_NOT_FOUND;
import static org.websoso.WSSServer.exception.error.CustomCommentError.SELF_REPORT_NOT_ALLOWED;

Expand Down Expand Up @@ -53,21 +55,20 @@ public void deleteComment(Long userId, Feed feed, Long commentId) {

@Transactional(readOnly = true)
public CommentsGetResponse getComments(User user, Feed feed) {
List<Comment> comments = feed.getComments();

List<CommentGetResponse> responses = comments
List<CommentGetResponse> responses = feed.getComments()
.stream()
.map(comment -> new AbstractMap.SimpleEntry<>(
comment, userService.getUserOrException(comment.getUserId())
))
.filter(entry -> !entry.getKey().getIsHidden() && !isBlocked(entry.getValue(), user))
comment, userService.getUserOrException(comment.getUserId())))
.map(entry -> CommentGetResponse.of(
getUserBasicInfo(entry.getValue()),
entry.getKey(),
isUserCommentOwner(entry.getValue(), user)))
isUserCommentOwner(entry.getValue(), user),
entry.getKey().getIsSpoiler(),
isBlocked(user, entry.getValue()),
entry.getKey().getIsHidden()))
.toList();

return CommentsGetResponse.of(comments.size(), responses);
return CommentsGetResponse.of(responses);
}

public void createReportedComment(Feed feed, Long commentId, User user, ReportedType reportedType) {
Expand All @@ -87,7 +88,11 @@ public void createReportedComment(Feed feed, Long commentId, User user, Reported
boolean shouldHide = reportedCount >= 3;

if (shouldHide) {
comment.hideComment();
if (reportedType.equals(SPOILER)) {
comment.spoiler();
} else if (reportedType.equals(IMPERTINENCE)) {
comment.hideComment();
}
}

messageService.sendDiscordWebhookMessage(
Expand All @@ -111,7 +116,8 @@ private Boolean isUserCommentOwner(User createdUser, User user) {
return createdUser.equals(user);
}

private Boolean isBlocked(User createdFeedUser, User user) {
return blockService.isBlockedRelationship(user.getUserId(), createdFeedUser.getUserId());
private Boolean isBlocked(User user, User createdFeedUser) {
return blockService.isBlocked(user.getUserId(), createdFeedUser.getUserId());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.websoso.WSSServer.service;

import static org.websoso.WSSServer.domain.common.ReportedType.IMPERTINENCE;
import static org.websoso.WSSServer.domain.common.ReportedType.SPOILER;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.websoso.WSSServer.domain.Comment;
Expand Down Expand Up @@ -47,7 +50,14 @@ public static String formatFeedReportMessage(Feed feed, ReportedType reportedTyp

public static String formatCommentReportMessage(Comment comment, ReportedType reportedType, User user,
int reportedCount, boolean isHidden) {
String hiddenMessage = isHidden ? "해당 댓글은 숨김 처리되었습니다." : "해당 댓글는 숨김 처리되지 않았습니다.";
String hiddenMessage = "해당 댓글은 현재 숨김 처리되지 않은 상태입니다.";
if (isHidden) {
if (reportedType.equals(SPOILER)) {
hiddenMessage = "해당 댓글은 스포일러 댓글로 지정되었습니다.";
} else if (reportedType.equals(IMPERTINENCE)) {
hiddenMessage = "해당 댓글은 부적절한 내용으로 인해 숨김 처리되었습니다.";
}
}
ChaeAg marked this conversation as resolved.
Show resolved Hide resolved

return String.format(
COMMENT_REPORT_MESSAGE,
Expand Down
Loading