푸시메시지 기능 추가 - 전체, 개별, 라이브 생성, 라이브 시작, 메시지 전송, 콘텐츠 업로드
This commit is contained in:
137
src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt
Normal file
137
src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt
Normal file
@@ -0,0 +1,137 @@
|
||||
package kr.co.vividnext.sodalive.fcm
|
||||
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import org.springframework.context.event.EventListener
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
enum class FcmEventType {
|
||||
ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE
|
||||
}
|
||||
|
||||
class FcmEvent(
|
||||
val type: FcmEventType,
|
||||
val title: String,
|
||||
val message: String,
|
||||
val container: String = "",
|
||||
val recipients: List<Long> = listOf(),
|
||||
val isAuth: Boolean = false,
|
||||
val roomId: Long? = null,
|
||||
val contentId: Long? = null,
|
||||
val messageId: Long? = null,
|
||||
val creatorId: Long? = null
|
||||
)
|
||||
|
||||
@Component
|
||||
class FcmSendListener(
|
||||
private val pushService: FcmService,
|
||||
private val memberRepository: MemberRepository
|
||||
) {
|
||||
@EventListener
|
||||
fun send(fcmEvent: FcmEvent) {
|
||||
when (fcmEvent.type) {
|
||||
FcmEventType.ALL -> {
|
||||
if (fcmEvent.container.isNotBlank()) {
|
||||
val pushTokens = memberRepository.getAllRecipientPushTokens(
|
||||
fcmEvent.isAuth,
|
||||
fcmEvent.container
|
||||
)
|
||||
|
||||
for (tokens in pushTokens) {
|
||||
pushService.send(
|
||||
tokens = tokens,
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = fcmEvent.container
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FcmEventType.INDIVIDUAL -> {
|
||||
if (fcmEvent.recipients.isNotEmpty()) {
|
||||
val pushTokens = memberRepository.getIndividualRecipientPushTokens(
|
||||
recipients = fcmEvent.recipients,
|
||||
isAuth = fcmEvent.isAuth
|
||||
)
|
||||
|
||||
val iosPushTokens = pushTokens["ios"]
|
||||
val aosPushToken = pushTokens["aos"]
|
||||
|
||||
if (iosPushTokens != null) {
|
||||
for (tokens in iosPushTokens) {
|
||||
pushService.send(
|
||||
tokens = tokens,
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = fcmEvent.container
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (aosPushToken != null) {
|
||||
for (tokens in aosPushToken) {
|
||||
pushService.send(
|
||||
tokens = tokens,
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = fcmEvent.container
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FcmEventType.CREATE_LIVE, FcmEventType.START_LIVE -> {
|
||||
if (fcmEvent.container.isNotBlank()) {
|
||||
val pushTokens = memberRepository.getCreateLiveRoomNotificationRecipientPushTokens(
|
||||
creatorId = fcmEvent.creatorId!!,
|
||||
isAuth = fcmEvent.isAuth,
|
||||
container = fcmEvent.container
|
||||
)
|
||||
|
||||
for (tokens in pushTokens) {
|
||||
pushService.send(
|
||||
tokens = tokens,
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = fcmEvent.container,
|
||||
roomId = fcmEvent.roomId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FcmEventType.UPLOAD_CONTENT -> {
|
||||
if (fcmEvent.container.isNotBlank()) {
|
||||
val pushTokens = memberRepository.getUploadContentNotificationRecipientPushTokens(
|
||||
creatorId = fcmEvent.creatorId!!,
|
||||
isAuth = fcmEvent.isAuth,
|
||||
container = fcmEvent.container
|
||||
)
|
||||
|
||||
for (tokens in pushTokens) {
|
||||
pushService.send(
|
||||
tokens = tokens,
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = fcmEvent.container,
|
||||
contentId = fcmEvent.contentId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FcmEventType.SEND_MESSAGE -> {
|
||||
val response = memberRepository.getMessageRecipientPushToken(messageId = fcmEvent.messageId!!)
|
||||
|
||||
pushService.send(
|
||||
tokens = listOf(response.pushToken),
|
||||
title = fcmEvent.title,
|
||||
message = fcmEvent.message,
|
||||
container = response.container,
|
||||
messageId = fcmEvent.messageId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user