fix(comment): 부모 잠금과 비밀 답글 조회 정책을 일치시킨다

This commit is contained in:
2026-11-20 14:03:13 +09:00
parent b2c2306c66
commit 3c379a48ec
24 changed files with 1193 additions and 109 deletions
@@ -1,5 +1,6 @@
package kr.co.vividnext.sodalive.content.comment
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.core.types.dsl.CaseBuilder
import com.querydsl.core.types.dsl.Expressions
import com.querydsl.jpa.JPAExpressions
@@ -100,7 +101,8 @@ class AudioContentCommentQueryRepositoryImpl(
audioContentComment.id,
audioContentComment.member.id,
displayName,
audioContentComment.member.profileImage.prepend("/").prepend(cloudFrontHost),
audioContentComment.member.profileImage.coalesce("profile/default-profile.png")
.prepend("/").prepend(cloudFrontHost),
audioContentComment.comment,
audioContentComment.languageCode,
audioContentComment.isSecret,
@@ -152,13 +154,7 @@ class AudioContentCommentQueryRepositoryImpl(
override fun commentReplyCountByAudioContentCommentId(commentId: Long, memberId: Long): Int {
return queryFactory.select(audioContentComment.id)
.from(audioContentComment)
.where(
audioContentComment.parent.isNotNull
.and(audioContentComment.parent.id.eq(commentId))
.and(audioContentComment.isActive.isTrue)
.and(audioContentComment.member.id.notIn(blockedMemberIdSubQuery(memberId)))
.and(audioContentComment.member.id.notIn(blockingMemberIdSubQuery(memberId)))
)
.where(visibleReplyCondition(commentId, memberId))
.fetch()
.size
}
@@ -194,7 +190,8 @@ class AudioContentCommentQueryRepositoryImpl(
audioContentComment.id,
audioContentComment.member.id,
displayName,
audioContentComment.member.profileImage.prepend("/").prepend(cloudFrontHost),
audioContentComment.member.profileImage.coalesce("profile/default-profile.png")
.prepend("/").prepend(cloudFrontHost),
audioContentComment.comment,
audioContentComment.languageCode,
audioContentComment.isSecret,
@@ -205,13 +202,7 @@ class AudioContentCommentQueryRepositoryImpl(
)
.from(audioContentComment)
.innerJoin(audioContentComment.member, member)
.where(
audioContentComment.parent.isNotNull
.and(audioContentComment.parent.id.eq(commentId))
.and(audioContentComment.isActive.isTrue)
.and(audioContentComment.member.id.notIn(blockedMemberIdSubQuery(memberId)))
.and(audioContentComment.member.id.notIn(blockingMemberIdSubQuery(memberId)))
)
.where(visibleReplyCondition(commentId, memberId))
.offset(offset)
.limit(limit.toLong())
.orderBy(audioContentComment.createdAt.desc())
@@ -269,6 +260,30 @@ class AudioContentCommentQueryRepositoryImpl(
return response
}
private fun visibleReplyCondition(commentId: Long, memberId: Long): BooleanExpression {
return audioContentComment.parent.id.eq(commentId)
.and(audioContentComment.isActive.isTrue)
.and(audioContentComment.parent.isActive.isTrue)
.and(audioContentComment.parent.parent.isNull)
.and(audioContentComment.audioContent.id.eq(audioContentComment.parent.audioContent.id))
.and(
audioContentComment.parent.isSecret.isFalse
.or(audioContentComment.parent.member.id.eq(memberId))
.or(audioContentComment.audioContent.member.id.eq(memberId))
)
.and(
audioContentComment.isSecret.isFalse
.or(audioContentComment.member.id.eq(memberId))
.or(audioContentComment.audioContent.member.id.eq(memberId))
.or(
audioContentComment.member.id.eq(audioContentComment.audioContent.member.id)
.and(audioContentComment.parent.member.id.eq(memberId))
)
)
.and(audioContentComment.member.id.notIn(blockedMemberIdSubQuery(memberId)))
.and(audioContentComment.member.id.notIn(blockingMemberIdSubQuery(memberId)))
}
private fun blockedMemberIdSubQuery(memberId: Long) = JPAExpressions
.select(blockMember.blockedMember.id)
.from(blockMember)
@@ -14,6 +14,7 @@ import kr.co.vividnext.sodalive.i18n.LangContext
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
import kr.co.vividnext.sodalive.v2.commentthread.port.out.CommentThreadLockPort
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
@@ -21,6 +22,8 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import javax.persistence.EntityManager
import javax.persistence.LockModeType
@Service
@Transactional(readOnly = true)
@@ -33,6 +36,8 @@ class AudioContentCommentService(
private val messageSource: SodaMessageSource,
private val langContext: LangContext,
private val localizedNameService: CreatorLocalizedNameService,
private val threadLocks: CommentThreadLockPort,
private val entityManager: EntityManager,
@Value("\${cloud.aws.cloud-front.host}")
private val cloudFrontHost: String
@@ -62,23 +67,28 @@ class AudioContentCommentService(
contentId = audioContent.id!!
)
if (isSecret && !isExistsAudioContent) {
val parent = parentId?.let {
threadLocks.lockContentRoot(it)?.takeIf { root ->
root.isActive && root.audioContent?.id == audioContentId
} ?: throw SodaException(messageKey = "content.comment.error.invalid_access_retry")
}
if (parent?.isSecret == true && parent.member?.id != member.id && creator.id != member.id) {
throw SodaException(messageKey = "content.comment.error.invalid_access_retry")
}
val isCreatorReply = parent != null && member.id == creator.id
val effectiveSecret = parent?.isSecret == true || (isSecret && !isCreatorReply)
if (effectiveSecret && !isCreatorReply && !isExistsAudioContent) {
throw SodaException(messageKey = "content.comment.error.secret_requires_purchase")
}
val audioContentComment = AudioContentComment(comment = comment, languageCode = languageCode, isSecret = isSecret)
val audioContentComment = AudioContentComment(
comment = comment,
languageCode = languageCode,
isSecret = effectiveSecret
)
audioContentComment.audioContent = audioContent
audioContentComment.member = member
val parent = if (parentId != null) {
repository.findByIdOrNull(id = parentId)
} else {
null
}
if (parent != null) {
audioContentComment.parent = parent
}
audioContentComment.parent = parent
val savedContentComment = repository.save(audioContentComment)
@@ -125,6 +135,14 @@ class AudioContentCommentService(
fun modifyComment(request: ModifyCommentRequest, member: Member) {
val audioContentComment = repository.findByIdOrNull(request.commentId)
?: throw SodaException(messageKey = "content.comment.error.invalid_access_retry")
val root = threadLocks.lockContentRoot(audioContentComment.parent?.id ?: request.commentId)
?: throw SodaException(messageKey = "content.comment.error.invalid_access_retry")
if (audioContentComment.id != root.id) {
entityManager.refresh(audioContentComment, LockModeType.PESSIMISTIC_WRITE)
if (!root.isActive || audioContentComment.audioContent?.id != root.audioContent?.id) {
throw SodaException(messageKey = "content.comment.error.invalid_access_retry")
}
}
if (audioContentComment.member!!.id!! == member.id!!) {
if (request.comment != null) {
@@ -583,6 +583,7 @@ class ExplorerQueryRepository(
languageCode = it.languageCode,
date = date.format(cheersDateFormatter),
replyList = it.children.asSequence()
.filter { cheers -> cheers.isActive && cheers.creator?.id == creatorId }
.filterNot { cheers ->
cheers.member?.id != null && blockedMemberIdSet.contains(cheers.member!!.id!!)
}
@@ -772,13 +773,6 @@ class ExplorerQueryRepository(
.toSet()
}
fun getCreatorCheers(cheersId: Long): CreatorCheers? {
return queryFactory
.selectFrom(creatorCheers)
.where(creatorCheers.id.eq(cheersId))
.fetchFirst()
}
fun getCheers(cheersId: Long): CreatorCheers? {
return queryFactory
.selectFrom(creatorCheers)
@@ -32,6 +32,7 @@ import kr.co.vividnext.sodalive.member.MemberRole
import kr.co.vividnext.sodalive.member.MemberService
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
import kr.co.vividnext.sodalive.v2.api.creator.channel.fantalk.dto.CreatorChannelFanTalkResponse
import kr.co.vividnext.sodalive.v2.commentthread.port.out.CommentThreadLockPort
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
@@ -44,6 +45,8 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalAdjusters
import javax.persistence.EntityManager
import javax.persistence.LockModeType
import kotlin.random.Random
@Service
@@ -67,6 +70,8 @@ class ExplorerService(
private val messageSource: SodaMessageSource,
private val langContext: LangContext,
private val localizedNameService: CreatorLocalizedNameService,
private val threadLocks: CommentThreadLockPort,
private val entityManager: EntityManager,
@Value("\${cloud.aws.cloud-front.host}")
private val cloudFrontHost: String
@@ -601,15 +606,12 @@ class ExplorerService(
cheers.member = member
cheers.creator = creator
val parent = if (request.parentId != null) {
queryRepository.getCreatorCheers(request.parentId)
} else {
null
}
if (parent != null) {
cheers.parent = parent
val parent = request.parentId?.let {
threadLocks.lockFanTalkRoot(it)?.takeIf { root ->
root.isActive && root.creator?.id == request.creatorId
} ?: throw SodaException(messageKey = "common.error.invalid_request")
}
cheers.parent = parent
val savedCheers = cheersRepository.save(cheers)
@@ -650,6 +652,14 @@ class ExplorerService(
fun modifyCheers(request: PutWriteCheersRequest, member: Member): CreatorChannelFanTalkResponse {
val cheers = queryRepository.getCheers(request.cheersId)
?: throw SodaException(messageKey = "common.error.invalid_request")
val root = threadLocks.lockFanTalkRoot(cheers.parent?.id ?: request.cheersId)
?: throw SodaException(messageKey = "common.error.invalid_request")
if (cheers.id != root.id) {
entityManager.refresh(cheers, LockModeType.PESSIMISTIC_WRITE)
if (!root.isActive || cheers.creator?.id != root.creator?.id) {
throw SodaException(messageKey = "common.error.invalid_request")
}
}
val isWriter = cheers.member!!.id!! == member.id!!
val isCreator = cheers.creator!!.id!! == member.id!!
@@ -27,6 +27,7 @@ import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
import kr.co.vividnext.sodalive.utils.generateFileName
import kr.co.vividnext.sodalive.utils.validateImage
import kr.co.vividnext.sodalive.v2.commentthread.port.out.CommentThreadLockPort
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
import kr.co.vividnext.sodalive.v2.home.following.application.HomeFollowingNewsPublishService
import org.slf4j.LoggerFactory
@@ -63,6 +64,7 @@ class CreatorCommunityService(
private val homeFollowingNewsPublishService: HomeFollowingNewsPublishService,
private val creatorCommunityTranslationService: CreatorCommunityTranslationService,
private val entityManager: EntityManager,
private val threadLocks: CommentThreadLockPort,
@Value("\${cloud.aws.s3.bucket}")
private val imageBucket: String,
@@ -499,6 +501,10 @@ class CreatorCommunityService(
) {
val post = repository.findByIdAndActive(postId = postId, isAdult = isAdult)
?: throw SodaException(messageKey = "creator.community.invalid_request_retry")
entityManager.refresh(post, LockModeType.PESSIMISTIC_WRITE)
if (!post.isActive || (!isAdult && post.isAdult)) {
throw SodaException(messageKey = "creator.community.invalid_request_retry")
}
val creatorId = post.member!!.id!!
@@ -508,23 +514,28 @@ class CreatorCommunityService(
val isExistOrdered = useCanRepository.isExistCommunityPostOrdered(postId = postId, memberId = member.id!!)
if (isSecret && !isExistOrdered) {
val parent = parentId?.let {
val candidate = commentRepository.findByIdOrNull(it)
?: throw SodaException(messageKey = "creator.community.invalid_access_retry")
if (candidate.creatorCommunity?.id != postId) {
throw SodaException(messageKey = "creator.community.invalid_access_retry")
}
threadLocks.lockCommunityRoot(it)?.takeIf { root -> root.isActive }
?: throw SodaException(messageKey = "creator.community.invalid_access_retry")
}
if (parent?.isSecret == true && parent.member?.id != member.id && creatorId != member.id) {
throw SodaException(messageKey = "creator.community.invalid_access_retry")
}
val isCreatorReply = parent != null && member.id == creatorId
val effectiveSecret = parent?.isSecret == true || (isSecret && !isCreatorReply)
if (effectiveSecret && !isCreatorReply && !isExistOrdered) {
throw SodaException(messageKey = "creator.community.secret_comment_purchase_required")
}
val postComment = CreatorCommunityComment(comment = comment, isSecret = isSecret)
val postComment = CreatorCommunityComment(comment = comment, isSecret = effectiveSecret)
postComment.creatorCommunity = post
postComment.member = member
val parent = if (parentId != null) {
commentRepository.findByIdOrNull(id = parentId)
} else {
null
}
if (parent != null) {
postComment.parent = parent
}
postComment.parent = parent
commentRepository.save(postComment)
@@ -550,6 +561,14 @@ class CreatorCommunityService(
fun modifyCommunityPostComment(request: ModifyCommunityPostCommentRequest, member: Member) {
val postComment = commentRepository.findByIdOrNull(id = request.commentId)
?: throw SodaException(messageKey = "creator.community.invalid_access_retry")
val root = threadLocks.lockCommunityRoot(postComment.parent?.id ?: request.commentId)
?: throw SodaException(messageKey = "creator.community.invalid_access_retry")
if (postComment.id != root.id) {
entityManager.refresh(postComment, LockModeType.PESSIMISTIC_WRITE)
if (!root.isActive || postComment.creatorCommunity?.id != root.creatorCommunity?.id) {
throw SodaException(messageKey = "creator.community.invalid_access_retry")
}
}
if (request.comment != null && postComment.member!!.id!! == member.id!!) {
postComment.comment = request.comment
@@ -1,5 +1,6 @@
package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.core.types.dsl.Expressions
import com.querydsl.jpa.JPAExpressions
import com.querydsl.jpa.impl.JPAQueryFactory
@@ -85,7 +86,8 @@ class CreatorCommunityCommentQueryRepositoryImpl(
creatorCommunityComment.id,
creatorCommunityComment.member.id,
creatorCommunityComment.member.nickname,
creatorCommunityComment.member.profileImage.prepend("/").prepend(imageHost),
creatorCommunityComment.member.profileImage.coalesce("profile/default-profile.png")
.prepend("/").prepend(imageHost),
creatorCommunityComment.comment,
creatorCommunityComment.isSecret,
formattedDate,
@@ -109,13 +111,7 @@ class CreatorCommunityCommentQueryRepositoryImpl(
override fun commentReplyCountByCommentId(commentId: Long, memberId: Long): Int {
return queryFactory.select(creatorCommunityComment.id)
.from(creatorCommunityComment)
.where(
creatorCommunityComment.isActive.isTrue
.and(creatorCommunityComment.parent.isNotNull)
.and(creatorCommunityComment.parent.id.eq(commentId))
.and(creatorCommunityComment.member.id.notIn(blockedMemberIdSubQuery(memberId)))
.and(creatorCommunityComment.member.id.notIn(blockingMemberIdSubQuery(memberId)))
)
.where(visibleReplyCondition(commentId, memberId))
.fetch()
.size
}
@@ -170,7 +166,8 @@ class CreatorCommunityCommentQueryRepositoryImpl(
creatorCommunityComment.id,
creatorCommunityComment.member.id,
creatorCommunityComment.member.nickname,
creatorCommunityComment.member.profileImage.prepend("/").prepend(imageHost),
creatorCommunityComment.member.profileImage.coalesce("profile/default-profile.png")
.prepend("/").prepend(imageHost),
creatorCommunityComment.comment,
creatorCommunityComment.isSecret,
formattedDate,
@@ -178,13 +175,7 @@ class CreatorCommunityCommentQueryRepositoryImpl(
)
)
.from(creatorCommunityComment)
.where(
creatorCommunityComment.isActive.isTrue
.and(creatorCommunityComment.parent.isNotNull)
.and(creatorCommunityComment.parent.id.eq(commentId))
.and(creatorCommunityComment.member.id.notIn(blockedMemberIdSubQuery(memberId)))
.and(creatorCommunityComment.member.id.notIn(blockingMemberIdSubQuery(memberId)))
)
.where(visibleReplyCondition(commentId, memberId))
.offset(offset)
.limit(limit)
.orderBy(creatorCommunityComment.createdAt.desc())
@@ -194,6 +185,30 @@ class CreatorCommunityCommentQueryRepositoryImpl(
}
}
private fun visibleReplyCondition(commentId: Long, memberId: Long): BooleanExpression {
return creatorCommunityComment.parent.id.eq(commentId)
.and(creatorCommunityComment.isActive.isTrue)
.and(creatorCommunityComment.parent.isActive.isTrue)
.and(creatorCommunityComment.parent.parent.isNull)
.and(creatorCommunityComment.creatorCommunity.id.eq(creatorCommunityComment.parent.creatorCommunity.id))
.and(
creatorCommunityComment.parent.isSecret.isFalse
.or(creatorCommunityComment.parent.member.id.eq(memberId))
.or(creatorCommunityComment.creatorCommunity.member.id.eq(memberId))
)
.and(
creatorCommunityComment.isSecret.isFalse
.or(creatorCommunityComment.member.id.eq(memberId))
.or(creatorCommunityComment.creatorCommunity.member.id.eq(memberId))
.or(
creatorCommunityComment.member.id.eq(creatorCommunityComment.creatorCommunity.member.id)
.and(creatorCommunityComment.parent.member.id.eq(memberId))
)
)
.and(creatorCommunityComment.member.id.notIn(blockedMemberIdSubQuery(memberId)))
.and(creatorCommunityComment.member.id.notIn(blockingMemberIdSubQuery(memberId)))
}
private fun blockedMemberIdSubQuery(memberId: Long) = JPAExpressions
.select(blockMember.blockedMember.id)
.from(blockMember)
@@ -15,6 +15,7 @@ import kr.co.vividnext.sodalive.v2.api.admin.aicharacter.error.AiCharacterAdminA
import kr.co.vividnext.sodalive.v2.api.creator.channel.fantalk.dto.CreatorChannelFanTalkReplyResponse
import kr.co.vividnext.sodalive.v2.api.creator.channel.fantalk.dto.CreatorChannelFanTalkResponse
import kr.co.vividnext.sodalive.v2.api.creator.channel.fantalk.dto.CreatorChannelFanTalkTabResponse
import kr.co.vividnext.sodalive.v2.commentthread.port.out.CommentThreadLockPort
import kr.co.vividnext.sodalive.v2.common.domain.toCdnUrl
import kr.co.vividnext.sodalive.v2.creator.channel.fantalk.domain.CreatorChannelFanTalkQueryPolicy
import org.springframework.beans.factory.annotation.Value
@@ -22,6 +23,8 @@ import org.springframework.context.ApplicationEventPublisher
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import javax.persistence.EntityManager
import javax.persistence.LockModeType
@Service
class AiCharacterAdminFanTalkFacade(
@@ -31,6 +34,8 @@ class AiCharacterAdminFanTalkFacade(
private val creatorCheersRepository: CreatorCheersRepository,
private val queryPolicy: CreatorChannelFanTalkQueryPolicy,
private val applicationEventPublisher: ApplicationEventPublisher,
private val threadLocks: CommentThreadLockPort,
private val entityManager: EntityManager,
@Value("\${cloud.aws.cloud-front.host}") private val cloudFrontHost: String
) {
@Transactional(readOnly = true)
@@ -75,6 +80,8 @@ class AiCharacterAdminFanTalkFacade(
val creator = target.creatorMember
val creatorMemberId = creator.id ?: throw invalidRequest()
val parent = repository.findActiveRoot(creatorMemberId, fanTalkId) ?: throw invalidRequest()
threadLocks.lockFanTalkRoot(fanTalkId) ?: throw invalidRequest()
if (!parent.isActive || parent.creator?.id != creatorMemberId) throw invalidRequest()
val savedReply = creatorCheersRepository.save(
CreatorCheers(cheers = request.content, languageCode = null).apply {
member = creator
@@ -107,6 +114,8 @@ class AiCharacterAdminFanTalkFacade(
val target = resolveActiveTarget(characterId)
val creatorMemberId = target.creatorMember.id ?: throw invalidRequest()
val fanRoot = repository.findFanRoot(creatorMemberId, fanTalkId) ?: throw invalidRequest()
threadLocks.lockFanTalkRoot(fanTalkId) ?: throw invalidRequest()
if (fanRoot.creator?.id != creatorMemberId || fanRoot.member?.id == creatorMemberId) throw invalidRequest()
fanRoot.isActive = false
}
@@ -121,7 +130,10 @@ class AiCharacterAdminFanTalkFacade(
val request = readRequest(requestString, AiCharacterAdminFanTalkReplyUpdateRequest::class.java)
val target = resolveActiveTarget(characterId)
val creatorMemberId = target.creatorMember.id ?: throw invalidRequest()
val root = threadLocks.lockFanTalkRoot(fanTalkId) ?: throw invalidRequest()
if (!root.isActive || root.creator?.id != creatorMemberId) throw invalidRequest()
val reply = repository.findUpdatableReply(creatorMemberId, fanTalkId, replyId) ?: throw invalidRequest()
entityManager.refresh(reply, LockModeType.PESSIMISTIC_WRITE)
request.content?.let { reply.cheers = it }
request.isActive?.let { reply.isActive = it }
@@ -0,0 +1,43 @@
package kr.co.vividnext.sodalive.v2.commentthread.adapter.out.persistence
import kr.co.vividnext.sodalive.content.comment.AudioContentComment
import kr.co.vividnext.sodalive.explorer.profile.CreatorCheers
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.CreatorCommunity
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment.CreatorCommunityComment
import kr.co.vividnext.sodalive.v2.commentthread.port.out.CommentThreadLockPort
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import javax.persistence.EntityManager
import javax.persistence.LockModeType
@Repository
@Transactional(propagation = Propagation.MANDATORY)
class DefaultCommentThreadLockRepository(private val entityManager: EntityManager) : CommentThreadLockPort {
override fun lockContentRoot(rootId: Long): AudioContentComment? {
val root = entityManager.find(AudioContentComment::class.java, rootId, LockModeType.PESSIMISTIC_WRITE) ?: return null
if (root.parent != null) return null
entityManager.refresh(root, LockModeType.PESSIMISTIC_WRITE)
return root
}
override fun lockCommunityRoot(rootId: Long): CreatorCommunityComment? {
val root = entityManager.find(CreatorCommunityComment::class.java, rootId) ?: return null
if (root.parent != null) return null
val post = entityManager.find(
CreatorCommunity::class.java,
root.creatorCommunity!!.id,
LockModeType.PESSIMISTIC_WRITE
)
entityManager.refresh(post, LockModeType.PESSIMISTIC_WRITE)
entityManager.refresh(root, LockModeType.PESSIMISTIC_WRITE)
return root
}
override fun lockFanTalkRoot(rootId: Long): CreatorCheers? {
val root = entityManager.find(CreatorCheers::class.java, rootId, LockModeType.PESSIMISTIC_WRITE) ?: return null
if (root.parent != null) return null
entityManager.refresh(root, LockModeType.PESSIMISTIC_WRITE)
return root
}
}
@@ -0,0 +1,12 @@
package kr.co.vividnext.sodalive.v2.commentthread.port.out
import kr.co.vividnext.sodalive.content.comment.AudioContentComment
import kr.co.vividnext.sodalive.explorer.profile.CreatorCheers
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment.CreatorCommunityComment
/** Requires a write transaction; returns refreshed roots including inactive rows, or null for missing/non-root IDs. */
interface CommentThreadLockPort {
fun lockContentRoot(rootId: Long): AudioContentComment?
fun lockCommunityRoot(rootId: Long): CreatorCommunityComment?
fun lockFanTalkRoot(rootId: Long): CreatorCheers?
}
@@ -523,9 +523,23 @@ class DefaultCreatorChannelCommunityQueryRepository(
}
private fun visibleSecretReplyCondition(viewerId: Long): BooleanExpression {
return creatorCommunityComment.isSecret.isFalse
.or(creatorCommunityComment.creatorCommunity.member.id.eq(viewerId))
.or(creatorCommunityComment.member.id.eq(viewerId))
return creatorCommunityComment.parent.isActive.isTrue
.and(creatorCommunityComment.parent.parent.isNull)
.and(creatorCommunityComment.creatorCommunity.id.eq(creatorCommunityComment.parent.creatorCommunity.id))
.and(
creatorCommunityComment.parent.isSecret.isFalse
.or(creatorCommunityComment.creatorCommunity.member.id.eq(viewerId))
.or(creatorCommunityComment.parent.member.id.eq(viewerId))
)
.and(
creatorCommunityComment.isSecret.isFalse
.or(creatorCommunityComment.member.id.eq(viewerId))
.or(creatorCommunityComment.creatorCommunity.member.id.eq(viewerId))
.or(
creatorCommunityComment.member.id.eq(creatorCommunityComment.creatorCommunity.member.id)
.and(creatorCommunityComment.parent.member.id.eq(viewerId))
)
)
}
private fun notBlockedCommentWriterCondition(viewerId: Long): BooleanExpression {
@@ -119,6 +119,9 @@ class DefaultCreatorChannelFanTalkQueryRepository(
creatorCheers.creator.id.eq(creatorId),
creatorCheers.member.id.eq(creatorId),
creatorCheers.isActive.isTrue,
creatorCheers.parent.isActive.isTrue,
creatorCheers.parent.parent.isNull,
creatorCheers.parent.creator.id.eq(creatorId),
creatorCheers.parent.id.`in`(parentFanTalkIds)
)
.orderBy(creatorCheers.createdAt.asc(), creatorCheers.id.asc())