라이브 취소 푸시 발송 로직 추가

This commit is contained in:
Klaus 2023-09-01 16:46:43 +09:00
parent 8f50d05906
commit d6dfa63bea
3 changed files with 76 additions and 1 deletions

View File

@ -9,7 +9,8 @@ import org.springframework.transaction.annotation.Transactional
import org.springframework.transaction.event.TransactionalEventListener
enum class FcmEventType {
ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE, CREATE_CONTENT_COMMENT
ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, CANCEL_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE,
CREATE_CONTENT_COMMENT
}
class FcmEvent(
@ -131,6 +132,37 @@ class FcmSendListener(
}
}
FcmEventType.CANCEL_LIVE -> {
if (fcmEvent.roomId != null) {
val pushTokenList = memberRepository.getPushTokenFromReservationList(fcmEvent.roomId)
val iosPushTokens = pushTokenList["ios"]
val aosPushToken = pushTokenList["aos"]
if (iosPushTokens != null) {
for (tokens in iosPushTokens) {
pushService.send(
tokens = tokens,
title = fcmEvent.title,
message = fcmEvent.message,
container = "ios"
)
}
}
if (aosPushToken != null) {
for (tokens in aosPushToken) {
pushService.send(
tokens = tokens,
title = fcmEvent.title,
message = fcmEvent.message,
container = "aos"
)
}
}
}
}
FcmEventType.UPLOAD_CONTENT -> {
if (fcmEvent.container.isNotBlank()) {
val pushTokens = memberRepository.getUploadContentNotificationRecipientPushTokens(

View File

@ -475,6 +475,15 @@ class LiveRoomService(
}
reservationRepository.cancelReservation(roomId = room.id!!)
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.CANCEL_LIVE,
title = room.member!!.nickname,
message = "라이브 취소 : ${room.title}",
roomId = request.roomId
)
)
}
@Transactional

View File

@ -50,6 +50,7 @@ interface MemberQueryRepository {
fun getMemberByEmail(email: String): Member?
fun getChangeNoticeRecipientPushTokens(creatorId: Long): Map<String, List<List<String>>>
fun getPushTokenFromReservationList(roomId: Long): Map<String, List<List<String>>>
}
@Repository
@ -255,9 +256,11 @@ class MemberQueryRepositoryImpl(
)
.from(message)
.innerJoin(message.recipient, member)
.innerJoin(member.notification, memberNotification)
.where(
message.id.eq(messageId)
.and(member.pushToken.isNotNull)
.and(memberNotification.message.isTrue)
)
.fetchFirst()
}
@ -356,4 +359,35 @@ class MemberQueryRepositoryImpl(
return mapOf("aos" to aosPushTokens, "ios" to iosPushTokens)
}
override fun getPushTokenFromReservationList(roomId: Long): Map<String, List<List<String>>> {
val query = queryFactory
.select(liveReservation.member.pushToken)
.from(liveReservation)
.innerJoin(liveReservation.room, liveRoom)
.innerJoin(liveReservation.member, member)
val where = liveRoom.id.eq(roomId)
.and(liveReservation.isActive.isTrue)
val aosPushTokens = query
.where(
where
.and(member.container.eq("aos"))
)
.fetch()
.toSet()
.chunked(500)
val iosPushTokens = query
.where(
where
.and(member.container.eq("ios"))
)
.fetch()
.toSet()
.chunked(500)
return mapOf("aos" to aosPushTokens, "ios" to iosPushTokens)
}
}