Merge pull request 'test' (#95) from test into main

Reviewed-on: #95
This commit is contained in:
klaus 2023-11-27 12:48:24 +00:00
commit 858ce524f9
5 changed files with 94 additions and 35 deletions

View File

@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.content.comment
import com.querydsl.jpa.impl.JPAQueryFactory import com.querydsl.jpa.impl.JPAQueryFactory
import kr.co.vividnext.sodalive.content.QAudioContent.audioContent import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment
import kr.co.vividnext.sodalive.member.QMember.member
import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
import java.time.ZoneId import java.time.ZoneId
@ -30,7 +31,11 @@ interface AudioContentCommentQueryRepository {
limit: Int limit: Int
): List<GetAudioContentCommentListItem> ): List<GetAudioContentCommentListItem>
fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse? fun findPushTokenByContentIdAndCommentParentIdMyMemberId(
contentId: Long,
commentParentId: Long?,
myMemberId: Long
): List<FindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse>
} }
@Repository @Repository
@ -143,27 +148,49 @@ class AudioContentCommentQueryRepositoryImpl(
.toList() .toList()
} }
override fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse? { override fun findPushTokenByContentIdAndCommentParentIdMyMemberId(
val response = queryFactory contentId: Long,
.selectFrom(audioContentComment) commentParentId: Long?,
.innerJoin(audioContentComment.audioContent, audioContent) myMemberId: Long
.where(audioContentComment.id.eq(contentCommentId)) ): List<FindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse> {
.fetchFirst() var where = audioContent.id.eq(contentId)
.and(member.id.ne(myMemberId))
.and(audioContentComment.isActive.isTrue)
return if (response == null) { if (commentParentId != null) {
null where = where.and(
} else { audioContentComment.parent.id.eq(commentParentId)
if (response.parent != null) { .or(audioContentComment.id.eq(commentParentId))
FindPushTokenByContentCommentIdResponse( )
pushToken = response.parent!!.member!!.pushToken ?: "",
container = response.parent!!.member!!.container
)
} else {
FindPushTokenByContentCommentIdResponse(
pushToken = response.audioContent!!.member!!.pushToken ?: "",
container = response.audioContent!!.member!!.container
)
}
} }
val response = if (commentParentId != null) {
queryFactory
.select(
QFindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse(
member.pushToken.coalesce(""),
member.container
)
)
.from(audioContentComment)
.innerJoin(audioContentComment.audioContent, audioContent)
.innerJoin(audioContentComment.member, member)
.where(where)
.fetch()
} else {
queryFactory
.select(
QFindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse(
member.pushToken.coalesce(""),
member.container
)
)
.from(audioContent)
.innerJoin(audioContent.member, member)
.where(where)
.fetch()
}
return response
} }
} }

View File

@ -57,7 +57,8 @@ class AudioContentCommentService(
"콘텐츠에 댓글을 달았습니다.: ${audioContent.title}" "콘텐츠에 댓글을 달았습니다.: ${audioContent.title}"
}, },
contentId = audioContentId, contentId = audioContentId,
contentCommentId = audioContentComment.id!! commentParentId = parentId,
myMemberId = member.id
) )
) )
} }

View File

@ -1,6 +0,0 @@
package kr.co.vividnext.sodalive.content.comment
data class FindPushTokenByContentCommentIdResponse(
val pushToken: String,
val container: String
)

View File

@ -0,0 +1,8 @@
package kr.co.vividnext.sodalive.content.comment
import com.querydsl.core.annotations.QueryProjection
data class FindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse @QueryProjection constructor(
val pushToken: String,
val container: String
)

View File

@ -25,7 +25,8 @@ class FcmEvent(
val contentId: Long? = null, val contentId: Long? = null,
val messageId: Long? = null, val messageId: Long? = null,
val creatorId: Long? = null, val creatorId: Long? = null,
val contentCommentId: Long? = null val commentParentId: Long? = null,
val myMemberId: Long? = null
) )
@Component @Component
@ -228,17 +229,45 @@ class FcmSendListener(
} }
FcmEventType.CREATE_CONTENT_COMMENT -> { FcmEventType.CREATE_CONTENT_COMMENT -> {
if (fcmEvent.contentCommentId != null && fcmEvent.contentId != null) { if (fcmEvent.myMemberId != null && fcmEvent.contentId != null) {
val response = contentCommentRepository.findPushTokenByContentCommentId( val response = contentCommentRepository.findPushTokenByContentIdAndCommentParentIdMyMemberId(
contentCommentId = fcmEvent.contentCommentId contentId = fcmEvent.contentId,
commentParentId = fcmEvent.commentParentId,
myMemberId = fcmEvent.myMemberId
) )
if (response != null) { val iosPushTokens = response
.asSequence()
.distinct()
.filter { it.pushToken.isNotBlank() }
.filter { it.container == "ios" }
.map { it.pushToken }
.toList()
val aosPushTokens = response
.asSequence()
.distinct()
.filter { it.pushToken.isNotBlank() }
.filter { it.container == "aos" }
.map { it.pushToken }
.toList()
if (iosPushTokens.isNotEmpty()) {
pushService.send( pushService.send(
tokens = listOf(response.pushToken), tokens = iosPushTokens,
title = fcmEvent.title, title = fcmEvent.title,
message = fcmEvent.message, message = fcmEvent.message,
container = response.container, container = "ios",
contentId = fcmEvent.contentId
)
}
if (aosPushTokens.isNotEmpty()) {
pushService.send(
tokens = aosPushTokens,
title = fcmEvent.title,
message = fcmEvent.message,
container = "aos",
contentId = fcmEvent.contentId contentId = fcmEvent.contentId
) )
} }