크리에이터 채널 공지사항 변경 시 푸시 발송
This commit is contained in:
		| @@ -11,11 +11,14 @@ import kr.co.vividnext.sodalive.explorer.profile.CreatorCheers | |||||||
| import kr.co.vividnext.sodalive.explorer.profile.CreatorCheersRepository | import kr.co.vividnext.sodalive.explorer.profile.CreatorCheersRepository | ||||||
| import kr.co.vividnext.sodalive.explorer.profile.PostWriteCheersRequest | import kr.co.vividnext.sodalive.explorer.profile.PostWriteCheersRequest | ||||||
| import kr.co.vividnext.sodalive.explorer.profile.PutWriteCheersRequest | import kr.co.vividnext.sodalive.explorer.profile.PutWriteCheersRequest | ||||||
|  | import kr.co.vividnext.sodalive.fcm.FcmEvent | ||||||
|  | import kr.co.vividnext.sodalive.fcm.FcmEventType | ||||||
| import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailUser | import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailUser | ||||||
| import kr.co.vividnext.sodalive.member.Member | import kr.co.vividnext.sodalive.member.Member | ||||||
| import kr.co.vividnext.sodalive.member.MemberRole | import kr.co.vividnext.sodalive.member.MemberRole | ||||||
| import kr.co.vividnext.sodalive.member.MemberService | import kr.co.vividnext.sodalive.member.MemberService | ||||||
| import org.springframework.beans.factory.annotation.Value | import org.springframework.beans.factory.annotation.Value | ||||||
|  | import org.springframework.context.ApplicationEventPublisher | ||||||
| import org.springframework.data.domain.Pageable | import org.springframework.data.domain.Pageable | ||||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||||
| import org.springframework.transaction.annotation.Transactional | import org.springframework.transaction.annotation.Transactional | ||||||
| @@ -28,6 +31,7 @@ class ExplorerService( | |||||||
|     private val queryRepository: ExplorerQueryRepository, |     private val queryRepository: ExplorerQueryRepository, | ||||||
|     private val cheersRepository: CreatorCheersRepository, |     private val cheersRepository: CreatorCheersRepository, | ||||||
|     private val noticeRepository: ChannelNoticeRepository, |     private val noticeRepository: ChannelNoticeRepository, | ||||||
|  |     private val applicationEventPublisher: ApplicationEventPublisher, | ||||||
|  |  | ||||||
|     @Value("\${cloud.aws.cloud-front.host}") |     @Value("\${cloud.aws.cloud-front.host}") | ||||||
|     private val cloudFrontHost: String |     private val cloudFrontHost: String | ||||||
| @@ -318,5 +322,14 @@ class ExplorerService( | |||||||
|         } else { |         } else { | ||||||
|             channelNotice.notice = notice |             channelNotice.notice = notice | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         applicationEventPublisher.publishEvent( | ||||||
|  |             FcmEvent( | ||||||
|  |                 type = FcmEventType.CHANGE_NOTICE, | ||||||
|  |                 title = member.nickname, | ||||||
|  |                 message = "공지사항이 변경되었습니다 - ${notice.substring(0, 10)}", | ||||||
|  |                 creatorId = member.id!! | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ import org.springframework.scheduling.annotation.Async | |||||||
| import org.springframework.stereotype.Component | import org.springframework.stereotype.Component | ||||||
|  |  | ||||||
| enum class FcmEventType { | enum class FcmEventType { | ||||||
|     ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE |     ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE | ||||||
| } | } | ||||||
|  |  | ||||||
| class FcmEvent( | class FcmEvent( | ||||||
| @@ -156,6 +156,39 @@ class FcmSendListener( | |||||||
|                     messageId = fcmEvent.messageId |                     messageId = fcmEvent.messageId | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             FcmEventType.CHANGE_NOTICE -> { | ||||||
|  |                 if (fcmEvent.creatorId != null) { | ||||||
|  |                     val pushTokenList = memberRepository.getChangeNoticeRecipientPushTokens(fcmEvent.creatorId) | ||||||
|  |  | ||||||
|  |                     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", | ||||||
|  |                                 creatorId = fcmEvent.creatorId | ||||||
|  |                             ) | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     if (aosPushToken != null) { | ||||||
|  |                         for (tokens in aosPushToken) { | ||||||
|  |                             pushService.send( | ||||||
|  |                                 tokens = tokens, | ||||||
|  |                                 title = fcmEvent.title, | ||||||
|  |                                 message = fcmEvent.message, | ||||||
|  |                                 container = "aos", | ||||||
|  |                                 creatorId = fcmEvent.creatorId | ||||||
|  |                             ) | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,7 +19,8 @@ class FcmService { | |||||||
|         container: String, |         container: String, | ||||||
|         roomId: Long? = null, |         roomId: Long? = null, | ||||||
|         messageId: Long? = null, |         messageId: Long? = null, | ||||||
|         contentId: Long? = null |         contentId: Long? = null, | ||||||
|  |         creatorId: Long? = null | ||||||
|     ) { |     ) { | ||||||
|         if (tokens.isNotEmpty()) { |         if (tokens.isNotEmpty()) { | ||||||
|             logger.info("os: $container") |             logger.info("os: $container") | ||||||
| @@ -52,6 +53,10 @@ class FcmService { | |||||||
|                 multicastMessage.putData("content_id", contentId.toString()) |                 multicastMessage.putData("content_id", contentId.toString()) | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             if (creatorId != null) { | ||||||
|  |                 multicastMessage.putData("channel_id", creatorId.toString()) | ||||||
|  |             } | ||||||
|  |  | ||||||
|             val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build()) |             val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build()) | ||||||
|             logger.info("보내기 성공: ${response.successCount}") |             logger.info("보내기 성공: ${response.successCount}") | ||||||
|             logger.info("보내기 실패: ${response.failureCount}") |             logger.info("보내기 실패: ${response.failureCount}") | ||||||
|   | |||||||
| @@ -40,6 +40,8 @@ interface MemberQueryRepository { | |||||||
|     fun getIndividualRecipientPushTokens(recipients: List<Long>, isAuth: Boolean): Map<String, List<List<String>>> |     fun getIndividualRecipientPushTokens(recipients: List<Long>, isAuth: Boolean): Map<String, List<List<String>>> | ||||||
|     fun getChangeNicknamePrice(memberId: Long): GetChangeNicknamePriceResponse |     fun getChangeNicknamePrice(memberId: Long): GetChangeNicknamePriceResponse | ||||||
|     fun getMemberByEmail(email: String): Member? |     fun getMemberByEmail(email: String): Member? | ||||||
|  |  | ||||||
|  |     fun getChangeNoticeRecipientPushTokens(creatorId: Long): Map<String, List<List<String>>> | ||||||
| } | } | ||||||
|  |  | ||||||
| @Repository | @Repository | ||||||
| @@ -244,4 +246,41 @@ class MemberQueryRepositoryImpl( | |||||||
|             .where(member.email.eq(email)) |             .where(member.email.eq(email)) | ||||||
|             .fetchOne() |             .fetchOne() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     override fun getChangeNoticeRecipientPushTokens(creatorId: Long): Map<String, List<List<String>>> { | ||||||
|  |         val member = QMember.member | ||||||
|  |         val creator = QMember.member | ||||||
|  |  | ||||||
|  |         val where = creatorFollowing.isActive.isTrue | ||||||
|  |             .and(creatorFollowing.creator.id.eq(creatorId)) | ||||||
|  |             .and(creatorFollowing.member.email.notIn("admin@sodalive.net")) | ||||||
|  |             .and( | ||||||
|  |                 creatorFollowing.member.id.notIn( | ||||||
|  |                     blockMemberRepository.getBlockedMemberList(creatorId) | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |             .and(creatorFollowing.member.pushToken.isNotNull) | ||||||
|  |  | ||||||
|  |         val aosPushTokens = queryFactory | ||||||
|  |             .select(creatorFollowing.member.pushToken) | ||||||
|  |             .from(creatorFollowing) | ||||||
|  |             .innerJoin(creatorFollowing.creator, creator) | ||||||
|  |             .innerJoin(creatorFollowing.member, member) | ||||||
|  |             .where(where.and(member.container.eq("aos"))) | ||||||
|  |             .fetch() | ||||||
|  |             .toSet() | ||||||
|  |             .chunked(500) | ||||||
|  |  | ||||||
|  |         val iosPushTokens = queryFactory | ||||||
|  |             .select(creatorFollowing.member.pushToken) | ||||||
|  |             .from(creatorFollowing) | ||||||
|  |             .innerJoin(creatorFollowing.creator, creator) | ||||||
|  |             .innerJoin(creatorFollowing.member, member) | ||||||
|  |             .where(where.and(member.container.eq("ios"))) | ||||||
|  |             .fetch() | ||||||
|  |             .toSet() | ||||||
|  |             .chunked(500) | ||||||
|  |  | ||||||
|  |         return mapOf("aos" to aosPushTokens, "ios" to iosPushTokens) | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user