diff --git a/src/main/java/com/devkor/ifive/nadab/domain/comment/application/CommentQueryService.java b/src/main/java/com/devkor/ifive/nadab/domain/comment/application/CommentQueryService.java index 5ef5500..a5d7b32 100644 --- a/src/main/java/com/devkor/ifive/nadab/domain/comment/application/CommentQueryService.java +++ b/src/main/java/com/devkor/ifive/nadab/domain/comment/application/CommentQueryService.java @@ -55,13 +55,13 @@ public CommentListResponse getComments(Long dailyReportId, Long currentUserId, L } Long nextCursor = hasNext ? comments.get(comments.size() - 1).getId() : null; - Map subCountMap = buildSubCountMap(comments, excludedUserIds, currentUserId, reportOwnerId); + Map subCountMap = buildSubCountMap(comments, excludedUserIds, currentUserId); List commentIds = comments.stream().map(Comment::getId).toList(); Set likedCommentIds = commentIds.isEmpty() ? Set.of() : new HashSet<>(commentLikeRepository.findLikedCommentIds(commentIds, currentUserId)); Set commentIdsWithLikes = commentIds.isEmpty() ? Set.of() - : new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(commentIds)); + : new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(commentIds, excludedUserIds)); List responses = comments.stream() .map(c -> { @@ -127,7 +127,7 @@ public CommentListResponse getSubComments(Long parentCommentId, Long currentUser Set likedSubCommentIds = subCommentIds.isEmpty() ? Set.of() : new HashSet<>(commentLikeRepository.findLikedCommentIds(subCommentIds, currentUserId)); Set subCommentIdsWithLikes = subCommentIds.isEmpty() ? Set.of() - : new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(subCommentIds)); + : new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(subCommentIds, excludedUserIds)); List responses = subComments.stream() .map(c -> { @@ -157,31 +157,14 @@ public CommentListResponse getSubComments(Long parentCommentId, Long currentUser return new CommentListResponse(responses, nextCursor, hasNext); } - private Map buildSubCountMap(List comments, List excludedUserIds, - Long currentUserId, Long reportOwnerId) { + private Map buildSubCountMap(List comments, List excludedUserIds, Long currentUserId) { if (comments.isEmpty()) { return Map.of(); } List parentIds = comments.stream().map(Comment::getId).toList(); - // 현재 사용자가 비밀 대댓글을 열람할 수 있는 부모 댓글 ID 목록 - // - 리포트 소유자: 모든 부모 댓글의 비밀 대댓글 열람 가능 - // - 그 외: 자신이 작성한 부모 댓글의 비밀 대댓글만 열람 가능 - List visibleSecretParentIds; - if (currentUserId.equals(reportOwnerId)) { - visibleSecretParentIds = parentIds; - } else { - visibleSecretParentIds = comments.stream() - .filter(c -> c.getAuthor().getId().equals(currentUserId)) - .map(Comment::getId) - .toList(); - if (visibleSecretParentIds.isEmpty()) { - visibleSecretParentIds = List.of(-1L); - } - } - return commentRepository.countVisibleSubCommentsByParentIds( - parentIds, excludedUserIds, currentUserId, visibleSecretParentIds) + parentIds, excludedUserIds, currentUserId) .stream() .collect(Collectors.toMap(SubCommentCountDto::parentCommentId, SubCommentCountDto::count)); } diff --git a/src/main/java/com/devkor/ifive/nadab/domain/comment/core/repository/CommentRepository.java b/src/main/java/com/devkor/ifive/nadab/domain/comment/core/repository/CommentRepository.java index d7b5127..124cc6a 100644 --- a/src/main/java/com/devkor/ifive/nadab/domain/comment/core/repository/CommentRepository.java +++ b/src/main/java/com/devkor/ifive/nadab/domain/comment/core/repository/CommentRepository.java @@ -88,18 +88,12 @@ and not exists ( select 1 from ContentReport cr where cr.reporter.id = :currentUserId and cr.comment = c ) - and ( - c.secret = false - or c.author.id = :currentUserId - or c.parentComment.id in :visibleSecretParentIds - ) group by c.parentComment.id """) List countVisibleSubCommentsByParentIds( @Param("parentIds") List parentIds, @Param("excludedUserIds") List excludedUserIds, - @Param("currentUserId") Long currentUserId, - @Param("visibleSecretParentIds") List visibleSecretParentIds + @Param("currentUserId") Long currentUserId ); @Query(""" diff --git a/src/main/java/com/devkor/ifive/nadab/domain/dailyreport/application/FeedQueryService.java b/src/main/java/com/devkor/ifive/nadab/domain/dailyreport/application/FeedQueryService.java index 306d374..2f19efd 100644 --- a/src/main/java/com/devkor/ifive/nadab/domain/dailyreport/application/FeedQueryService.java +++ b/src/main/java/com/devkor/ifive/nadab/domain/dailyreport/application/FeedQueryService.java @@ -11,6 +11,7 @@ import com.devkor.ifive.nadab.domain.like.core.repository.DailyReportLikeRepository; import com.devkor.ifive.nadab.domain.moderation.application.SharingSuspensionService; import com.devkor.ifive.nadab.domain.moderation.core.repository.ContentReportRepository; +import com.devkor.ifive.nadab.domain.moderation.core.repository.UserBlockRepository; import com.devkor.ifive.nadab.domain.user.core.entity.DefaultProfileType; import com.devkor.ifive.nadab.domain.user.infra.ProfileImageUrlBuilder; import com.devkor.ifive.nadab.global.shared.util.TodayDateTimeProvider; @@ -19,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -36,6 +38,7 @@ public class FeedQueryService { private final ProfileImageUrlBuilder profileImageUrlBuilder; private final ContentReportRepository contentReportRepository; private final SharingSuspensionService sharingSuspensionService; + private final UserBlockRepository userBlockRepository; public FeedListResponse getFeeds(Long userId) { LocalDate today = TodayDateTimeProvider.getTodayDate(); @@ -97,7 +100,8 @@ private FeedListResponse toFeedListResponse(Long userId, Optional myFee reportIdsWithLikes = Set.of(); } else { likedReportIds = new HashSet<>(dailyReportLikeRepository.findLikedReportIds(allReportIds, userId)); - reportIdsWithLikes = new HashSet<>(dailyReportLikeRepository.findReportIdsWithLikes(allReportIds)); + reportIdsWithLikes = new HashSet<>( + dailyReportLikeRepository.findReportIdsWithLikes(allReportIds, getExcludedUserIds(userId))); } FeedResponse myReport = myFeedDto @@ -135,6 +139,17 @@ private FeedResponse toFeedResponse(FeedDto dto, Set likedReportIds, Set getExcludedUserIds(Long userId) { + List blocked = userBlockRepository.findBlockedUserIdsBidirectional(userId); + List suspended = sharingSuspensionService.getAllActiveSuspendedUserIds(); + + Set combined = new HashSet<>(blocked); + combined.addAll(suspended); + combined.remove(userId); + + return combined.isEmpty() ? List.of(-1L) : new ArrayList<>(combined); + } + private String buildProfileUrl(String profileImageKey, DefaultProfileType defaultProfileType) { if (profileImageKey != null) { return profileImageUrlBuilder.buildUrl(profileImageKey); diff --git a/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/CommentLikeRepository.java b/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/CommentLikeRepository.java index 4a55d77..079f119 100644 --- a/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/CommentLikeRepository.java +++ b/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/CommentLikeRepository.java @@ -27,8 +27,13 @@ public interface CommentLikeRepository extends JpaRepository select distinct l.comment.id from CommentLike l where l.comment.id in :commentIds + and l.user.id not in :excludedUserIds + and l.user.deletedAt is null """) - List findCommentIdsWithLikes(@Param("commentIds") List commentIds); + List findCommentIdsWithLikes( + @Param("commentIds") List commentIds, + @Param("excludedUserIds") List excludedUserIds + ); @Query(""" select l.user diff --git a/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/DailyReportLikeRepository.java b/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/DailyReportLikeRepository.java index 9c3ab37..634df2a 100644 --- a/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/DailyReportLikeRepository.java +++ b/src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/DailyReportLikeRepository.java @@ -27,8 +27,13 @@ public interface DailyReportLikeRepository extends JpaRepository findReportIdsWithLikes(@Param("reportIds") List reportIds); + List findReportIdsWithLikes( + @Param("reportIds") List reportIds, + @Param("excludedUserIds") List excludedUserIds + ); @Query(""" select l.user