diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt index e766c32..ad25846 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt @@ -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( diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt index b470dd1..647377a 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt @@ -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 diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt index 3a60039..6d8c0cf 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt @@ -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) + } }