Skip to content
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 @@ -55,13 +55,13 @@ public CommentListResponse getComments(Long dailyReportId, Long currentUserId, L
}
Long nextCursor = hasNext ? comments.get(comments.size() - 1).getId() : null;

Map<Long, Long> subCountMap = buildSubCountMap(comments, excludedUserIds, currentUserId, reportOwnerId);
Map<Long, Long> subCountMap = buildSubCountMap(comments, excludedUserIds, currentUserId);

List<Long> commentIds = comments.stream().map(Comment::getId).toList();
Set<Long> likedCommentIds = commentIds.isEmpty() ? Set.of()
: new HashSet<>(commentLikeRepository.findLikedCommentIds(commentIds, currentUserId));
Set<Long> commentIdsWithLikes = commentIds.isEmpty() ? Set.of()
: new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(commentIds));
: new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(commentIds, excludedUserIds));

List<CommentResponse> responses = comments.stream()
.map(c -> {
Expand Down Expand Up @@ -127,7 +127,7 @@ public CommentListResponse getSubComments(Long parentCommentId, Long currentUser
Set<Long> likedSubCommentIds = subCommentIds.isEmpty() ? Set.of()
: new HashSet<>(commentLikeRepository.findLikedCommentIds(subCommentIds, currentUserId));
Set<Long> subCommentIdsWithLikes = subCommentIds.isEmpty() ? Set.of()
: new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(subCommentIds));
: new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(subCommentIds, excludedUserIds));

List<CommentResponse> responses = subComments.stream()
.map(c -> {
Expand Down Expand Up @@ -157,31 +157,14 @@ public CommentListResponse getSubComments(Long parentCommentId, Long currentUser
return new CommentListResponse(responses, nextCursor, hasNext);
}

private Map<Long, Long> buildSubCountMap(List<Comment> comments, List<Long> excludedUserIds,
Long currentUserId, Long reportOwnerId) {
private Map<Long, Long> buildSubCountMap(List<Comment> comments, List<Long> excludedUserIds, Long currentUserId) {
if (comments.isEmpty()) {
return Map.of();
}
List<Long> parentIds = comments.stream().map(Comment::getId).toList();

// 현재 사용자가 비밀 대댓글을 열람할 수 있는 부모 댓글 ID 목록
// - 리포트 소유자: 모든 부모 댓글의 비밀 대댓글 열람 가능
// - 그 외: 자신이 작성한 부모 댓글의 비밀 대댓글만 열람 가능
List<Long> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubCommentCountDto> countVisibleSubCommentsByParentIds(
@Param("parentIds") List<Long> parentIds,
@Param("excludedUserIds") List<Long> excludedUserIds,
@Param("currentUserId") Long currentUserId,
@Param("visibleSecretParentIds") List<Long> visibleSecretParentIds
@Param("currentUserId") Long currentUserId
);

@Query("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -97,7 +100,8 @@ private FeedListResponse toFeedListResponse(Long userId, Optional<FeedDto> 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
Expand Down Expand Up @@ -135,6 +139,17 @@ private FeedResponse toFeedResponse(FeedDto dto, Set<Long> likedReportIds, Set<L
);
}

private List<Long> getExcludedUserIds(Long userId) {
List<Long> blocked = userBlockRepository.findBlockedUserIdsBidirectional(userId);
List<Long> suspended = sharingSuspensionService.getAllActiveSuspendedUserIds();

Set<Long> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public interface CommentLikeRepository extends JpaRepository<CommentLike, Long>
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<Long> findCommentIdsWithLikes(@Param("commentIds") List<Long> commentIds);
List<Long> findCommentIdsWithLikes(
@Param("commentIds") List<Long> commentIds,
@Param("excludedUserIds") List<Long> excludedUserIds
);

@Query("""
select l.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public interface DailyReportLikeRepository extends JpaRepository<DailyReportLike
select distinct l.dailyReport.id
from DailyReportLike l
where l.dailyReport.id in :reportIds
and l.user.id not in :excludedUserIds
and l.user.deletedAt is null
""")
List<Long> findReportIdsWithLikes(@Param("reportIds") List<Long> reportIds);
List<Long> findReportIdsWithLikes(
@Param("reportIds") List<Long> reportIds,
@Param("excludedUserIds") List<Long> excludedUserIds
);

@Query("""
select l.user
Expand Down
Loading