콘텐츠 댓글 알림 추가
This commit is contained in:
parent
fb8309c7b4
commit
cd833dc21d
|
@ -1,6 +1,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 org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
@ -28,6 +29,8 @@ interface AudioContentCommentQueryRepository {
|
|||
offset: Long,
|
||||
limit: Int
|
||||
): List<GetAudioContentCommentListItem>
|
||||
|
||||
fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse?
|
||||
}
|
||||
|
||||
@Repository
|
||||
|
@ -138,4 +141,28 @@ class AudioContentCommentQueryRepositoryImpl(
|
|||
}
|
||||
.toList()
|
||||
}
|
||||
|
||||
override fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse? {
|
||||
val response = queryFactory
|
||||
.selectFrom(audioContentComment)
|
||||
.innerJoin(audioContentComment.audioContent, audioContent)
|
||||
.where(audioContentComment.id.eq(contentCommentId))
|
||||
.fetchFirst()
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package kr.co.vividnext.sodalive.content.comment
|
|||
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.content.AudioContentRepository
|
||||
import kr.co.vividnext.sodalive.fcm.FcmEvent
|
||||
import kr.co.vividnext.sodalive.fcm.FcmEventType
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
|
@ -14,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional
|
|||
class AudioContentCommentService(
|
||||
private val repository: AudioContentCommentRepository,
|
||||
private val audioContentRepository: AudioContentRepository,
|
||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
|
@ -38,6 +42,24 @@ class AudioContentCommentService(
|
|||
}
|
||||
|
||||
repository.save(audioContentComment)
|
||||
|
||||
applicationEventPublisher.publishEvent(
|
||||
FcmEvent(
|
||||
type = FcmEventType.CREATE_CONTENT_COMMENT,
|
||||
title = if (parent != null) {
|
||||
parent.member!!.nickname
|
||||
} else {
|
||||
member.nickname
|
||||
},
|
||||
message = if (parent != null) {
|
||||
"댓글에 답글을 달았습니다.: ${audioContent.title}"
|
||||
} else {
|
||||
"콘텐츠에 댓글을 달았습니다.: ${audioContent.title}"
|
||||
},
|
||||
contentId = audioContentId,
|
||||
contentCommentId = audioContentComment.id!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package kr.co.vividnext.sodalive.content.comment
|
||||
|
||||
data class FindPushTokenByContentCommentIdResponse(
|
||||
val pushToken: String,
|
||||
val container: String
|
||||
)
|
|
@ -1,12 +1,13 @@
|
|||
package kr.co.vividnext.sodalive.fcm
|
||||
|
||||
import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import org.springframework.context.event.EventListener
|
||||
import org.springframework.scheduling.annotation.Async
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.transaction.event.TransactionalEventListener
|
||||
|
||||
enum class FcmEventType {
|
||||
ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE
|
||||
ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE, CREATE_CONTENT_COMMENT
|
||||
}
|
||||
|
||||
class FcmEvent(
|
||||
|
@ -19,16 +20,18 @@ class FcmEvent(
|
|||
val roomId: Long? = null,
|
||||
val contentId: Long? = null,
|
||||
val messageId: Long? = null,
|
||||
val creatorId: Long? = null
|
||||
val creatorId: Long? = null,
|
||||
val contentCommentId: Long? = null
|
||||
)
|
||||
|
||||
@Component
|
||||
class FcmSendListener(
|
||||
private val pushService: FcmService,
|
||||
private val memberRepository: MemberRepository
|
||||
private val memberRepository: MemberRepository,
|
||||
private val contentCommentRepository: AudioContentCommentRepository
|
||||
) {
|
||||
@Async
|
||||
@EventListener
|
||||
@TransactionalEventListener
|
||||
fun send(fcmEvent: FcmEvent) {
|
||||
when (fcmEvent.type) {
|
||||
FcmEventType.ALL -> {
|
||||
|
@ -189,6 +192,24 @@ class FcmSendListener(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
FcmEventType.CREATE_CONTENT_COMMENT -> {
|
||||
if (fcmEvent.contentCommentId != null && fcmEvent.contentId != null) {
|
||||
val response = contentCommentRepository.findPushTokenByContentCommentId(
|
||||
contentCommentId = fcmEvent.contentCommentId
|
||||
)
|
||||
|
||||
if (response != null) {
|
||||
pushService.send(
|
||||
tokens = listOf(response.pushToken),
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = response.container,
|
||||
contentId = fcmEvent.contentId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue