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 kr.co.vividnext.sodalive.content.QAudioContent.audioContent
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.stereotype.Repository
import java.time.ZoneId
@ -30,7 +31,11 @@ interface AudioContentCommentQueryRepository {
limit: Int
): List<GetAudioContentCommentListItem>
fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse?
fun findPushTokenByContentIdAndCommentParentIdMyMemberId(
contentId: Long,
commentParentId: Long?,
myMemberId: Long
): List<FindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse>
}
@Repository
@ -143,27 +148,49 @@ class AudioContentCommentQueryRepositoryImpl(
.toList()
}
override fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse? {
val response = queryFactory
.selectFrom(audioContentComment)
.innerJoin(audioContentComment.audioContent, audioContent)
.where(audioContentComment.id.eq(contentCommentId))
.fetchFirst()
override fun findPushTokenByContentIdAndCommentParentIdMyMemberId(
contentId: Long,
commentParentId: Long?,
myMemberId: Long
): List<FindPushTokenByContentIdAndCommentParentIdMyMemberIdResponse> {
var where = audioContent.id.eq(contentId)
.and(member.id.ne(myMemberId))
.and(audioContentComment.isActive.isTrue)
return if (response == null) {
null
} else {
if (response.parent != null) {
FindPushTokenByContentCommentIdResponse(
pushToken = response.parent!!.member!!.pushToken ?: "",
container = response.parent!!.member!!.container
)
} else {
FindPushTokenByContentCommentIdResponse(
pushToken = response.audioContent!!.member!!.pushToken ?: "",
container = response.audioContent!!.member!!.container
if (commentParentId != null) {
where = where.and(
audioContentComment.parent.id.eq(commentParentId)
.or(audioContentComment.id.eq(commentParentId))
)
}
}
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}"
},
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 messageId: Long? = null,
val creatorId: Long? = null,
val contentCommentId: Long? = null
val commentParentId: Long? = null,
val myMemberId: Long? = null
)
@Component
@ -228,17 +229,45 @@ class FcmSendListener(
}
FcmEventType.CREATE_CONTENT_COMMENT -> {
if (fcmEvent.contentCommentId != null && fcmEvent.contentId != null) {
val response = contentCommentRepository.findPushTokenByContentCommentId(
contentCommentId = fcmEvent.contentCommentId
if (fcmEvent.myMemberId != null && fcmEvent.contentId != null) {
val response = contentCommentRepository.findPushTokenByContentIdAndCommentParentIdMyMemberId(
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(
tokens = listOf(response.pushToken),
tokens = iosPushTokens,
title = fcmEvent.title,
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
)
}