Skip to content

Commit a7fc885

Browse files
authored
fix(social): 대댓글 카운트·좋아요 아이콘 노출 정합성 수정 (#175)
visibleSubCommentCount ↔ 대댓글 목록 불일치를 해결하기 위해 (countVisibleSubCommentsByParentIds에서 비밀 필터 절 제거하여 마스킹되어 노출되는 비밀 대댓글까지 카운트에 포함, CommentQueryService.buildSubCountMap의 visibleSecretParentIds 계산 로직 제거, hasLikes ↔ 좋아요 리스트 불일치를 해결하기 위해 findReportIdsWithLikes / findCommentIdsWithLikes에 user.idnot in :excludedUserIds + user.deletedAt is null 필터 추가, FeedQueryService에 getExcludedUserIds 헬퍼 + UserBlockRepository 주입 추가
1 parent fcfa5f9 commit a7fc885

5 files changed

Lines changed: 34 additions & 32 deletions

File tree

src/main/java/com/devkor/ifive/nadab/domain/comment/application/CommentQueryService.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public CommentListResponse getComments(Long dailyReportId, Long currentUserId, L
5555
}
5656
Long nextCursor = hasNext ? comments.get(comments.size() - 1).getId() : null;
5757

58-
Map<Long, Long> subCountMap = buildSubCountMap(comments, excludedUserIds, currentUserId, reportOwnerId);
58+
Map<Long, Long> subCountMap = buildSubCountMap(comments, excludedUserIds, currentUserId);
5959

6060
List<Long> commentIds = comments.stream().map(Comment::getId).toList();
6161
Set<Long> likedCommentIds = commentIds.isEmpty() ? Set.of()
6262
: new HashSet<>(commentLikeRepository.findLikedCommentIds(commentIds, currentUserId));
6363
Set<Long> commentIdsWithLikes = commentIds.isEmpty() ? Set.of()
64-
: new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(commentIds));
64+
: new HashSet<>(commentLikeRepository.findCommentIdsWithLikes(commentIds, excludedUserIds));
6565

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

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

160-
private Map<Long, Long> buildSubCountMap(List<Comment> comments, List<Long> excludedUserIds,
161-
Long currentUserId, Long reportOwnerId) {
160+
private Map<Long, Long> buildSubCountMap(List<Comment> comments, List<Long> excludedUserIds, Long currentUserId) {
162161
if (comments.isEmpty()) {
163162
return Map.of();
164163
}
165164
List<Long> parentIds = comments.stream().map(Comment::getId).toList();
166165

167-
// 현재 사용자가 비밀 대댓글을 열람할 수 있는 부모 댓글 ID 목록
168-
// - 리포트 소유자: 모든 부모 댓글의 비밀 대댓글 열람 가능
169-
// - 그 외: 자신이 작성한 부모 댓글의 비밀 대댓글만 열람 가능
170-
List<Long> visibleSecretParentIds;
171-
if (currentUserId.equals(reportOwnerId)) {
172-
visibleSecretParentIds = parentIds;
173-
} else {
174-
visibleSecretParentIds = comments.stream()
175-
.filter(c -> c.getAuthor().getId().equals(currentUserId))
176-
.map(Comment::getId)
177-
.toList();
178-
if (visibleSecretParentIds.isEmpty()) {
179-
visibleSecretParentIds = List.of(-1L);
180-
}
181-
}
182-
183166
return commentRepository.countVisibleSubCommentsByParentIds(
184-
parentIds, excludedUserIds, currentUserId, visibleSecretParentIds)
167+
parentIds, excludedUserIds, currentUserId)
185168
.stream()
186169
.collect(Collectors.toMap(SubCommentCountDto::parentCommentId, SubCommentCountDto::count));
187170
}

src/main/java/com/devkor/ifive/nadab/domain/comment/core/repository/CommentRepository.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,12 @@ and not exists (
8888
select 1 from ContentReport cr
8989
where cr.reporter.id = :currentUserId and cr.comment = c
9090
)
91-
and (
92-
c.secret = false
93-
or c.author.id = :currentUserId
94-
or c.parentComment.id in :visibleSecretParentIds
95-
)
9691
group by c.parentComment.id
9792
""")
9893
List<SubCommentCountDto> countVisibleSubCommentsByParentIds(
9994
@Param("parentIds") List<Long> parentIds,
10095
@Param("excludedUserIds") List<Long> excludedUserIds,
101-
@Param("currentUserId") Long currentUserId,
102-
@Param("visibleSecretParentIds") List<Long> visibleSecretParentIds
96+
@Param("currentUserId") Long currentUserId
10397
);
10498

10599
@Query("""

src/main/java/com/devkor/ifive/nadab/domain/dailyreport/application/FeedQueryService.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.devkor.ifive.nadab.domain.like.core.repository.DailyReportLikeRepository;
1212
import com.devkor.ifive.nadab.domain.moderation.application.SharingSuspensionService;
1313
import com.devkor.ifive.nadab.domain.moderation.core.repository.ContentReportRepository;
14+
import com.devkor.ifive.nadab.domain.moderation.core.repository.UserBlockRepository;
1415
import com.devkor.ifive.nadab.domain.user.core.entity.DefaultProfileType;
1516
import com.devkor.ifive.nadab.domain.user.infra.ProfileImageUrlBuilder;
1617
import com.devkor.ifive.nadab.global.shared.util.TodayDateTimeProvider;
@@ -19,6 +20,7 @@
1920
import org.springframework.transaction.annotation.Transactional;
2021

2122
import java.time.LocalDate;
23+
import java.util.ArrayList;
2224
import java.util.HashSet;
2325
import java.util.List;
2426
import java.util.Optional;
@@ -36,6 +38,7 @@ public class FeedQueryService {
3638
private final ProfileImageUrlBuilder profileImageUrlBuilder;
3739
private final ContentReportRepository contentReportRepository;
3840
private final SharingSuspensionService sharingSuspensionService;
41+
private final UserBlockRepository userBlockRepository;
3942

4043
public FeedListResponse getFeeds(Long userId) {
4144
LocalDate today = TodayDateTimeProvider.getTodayDate();
@@ -97,7 +100,8 @@ private FeedListResponse toFeedListResponse(Long userId, Optional<FeedDto> myFee
97100
reportIdsWithLikes = Set.of();
98101
} else {
99102
likedReportIds = new HashSet<>(dailyReportLikeRepository.findLikedReportIds(allReportIds, userId));
100-
reportIdsWithLikes = new HashSet<>(dailyReportLikeRepository.findReportIdsWithLikes(allReportIds));
103+
reportIdsWithLikes = new HashSet<>(
104+
dailyReportLikeRepository.findReportIdsWithLikes(allReportIds, getExcludedUserIds(userId)));
101105
}
102106

103107
FeedResponse myReport = myFeedDto
@@ -135,6 +139,17 @@ private FeedResponse toFeedResponse(FeedDto dto, Set<Long> likedReportIds, Set<L
135139
);
136140
}
137141

142+
private List<Long> getExcludedUserIds(Long userId) {
143+
List<Long> blocked = userBlockRepository.findBlockedUserIdsBidirectional(userId);
144+
List<Long> suspended = sharingSuspensionService.getAllActiveSuspendedUserIds();
145+
146+
Set<Long> combined = new HashSet<>(blocked);
147+
combined.addAll(suspended);
148+
combined.remove(userId);
149+
150+
return combined.isEmpty() ? List.of(-1L) : new ArrayList<>(combined);
151+
}
152+
138153
private String buildProfileUrl(String profileImageKey, DefaultProfileType defaultProfileType) {
139154
if (profileImageKey != null) {
140155
return profileImageUrlBuilder.buildUrl(profileImageKey);

src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/CommentLikeRepository.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ public interface CommentLikeRepository extends JpaRepository<CommentLike, Long>
2727
select distinct l.comment.id
2828
from CommentLike l
2929
where l.comment.id in :commentIds
30+
and l.user.id not in :excludedUserIds
31+
and l.user.deletedAt is null
3032
""")
31-
List<Long> findCommentIdsWithLikes(@Param("commentIds") List<Long> commentIds);
33+
List<Long> findCommentIdsWithLikes(
34+
@Param("commentIds") List<Long> commentIds,
35+
@Param("excludedUserIds") List<Long> excludedUserIds
36+
);
3237

3338
@Query("""
3439
select l.user

src/main/java/com/devkor/ifive/nadab/domain/like/core/repository/DailyReportLikeRepository.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ public interface DailyReportLikeRepository extends JpaRepository<DailyReportLike
2727
select distinct l.dailyReport.id
2828
from DailyReportLike l
2929
where l.dailyReport.id in :reportIds
30+
and l.user.id not in :excludedUserIds
31+
and l.user.deletedAt is null
3032
""")
31-
List<Long> findReportIdsWithLikes(@Param("reportIds") List<Long> reportIds);
33+
List<Long> findReportIdsWithLikes(
34+
@Param("reportIds") List<Long> reportIds,
35+
@Param("excludedUserIds") List<Long> excludedUserIds
36+
);
3237

3338
@Query("""
3439
select l.user

0 commit comments

Comments
 (0)