From 743020d6bfeb64cd0b984effa6fca12dabebef53 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 19 Jun 2026 01:55:22 +0900 Subject: [PATCH] =?UTF-8?q?feat(fcm):=20=EC=B1=84=ED=8C=85=20=ED=91=B8?= =?UTF-8?q?=EC=8B=9C=20payload=EB=A5=BC=20=ED=99=95=EC=9E=A5=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/vividnext/sodalive/fcm/FcmEvent.kt | 2 + .../co/vividnext/sodalive/fcm/FcmService.kt | 62 +++++++++++-------- .../vividnext/sodalive/fcm/FcmServiceTest.kt | 27 ++++++++ 3 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/test/kotlin/kr/co/vividnext/sodalive/fcm/FcmServiceTest.kt 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 c747b300..1addc75c 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmEvent.kt @@ -45,6 +45,7 @@ class FcmEvent( val roomId: Long? = null, val contentId: Long? = null, val messageId: Long? = null, + val chatType: String? = null, val creatorId: Long? = null, val auditionId: Long? = null, val deepLinkValue: FcmDeepLinkValue? = null, @@ -191,6 +192,7 @@ class FcmSendListener( roomId = roomId ?: fcmEvent.roomId, contentId = contentId ?: fcmEvent.contentId, messageId = messageId ?: fcmEvent.messageId, + chatType = fcmEvent.chatType, creatorId = creatorId ?: fcmEvent.creatorId, auditionId = auditionId ?: fcmEvent.auditionId, deepLinkValue = fcmEvent.deepLinkValue, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt index f4824489..cd02bdce 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt @@ -33,7 +33,8 @@ class FcmService( auditionId: Long? = null, deepLinkValue: FcmDeepLinkValue? = null, deepLinkId: Long? = null, - deepLinkCommentPostId: Long? = null + deepLinkCommentPostId: Long? = null, + chatType: String? = null ) { if (tokens.isEmpty()) return logger.info("os: $container") @@ -70,30 +71,17 @@ class FcmService( .build() ) - if (roomId != null) { - multicastMessage.putData("room_id", roomId.toString()) - } - - if (messageId != null) { - multicastMessage.putData("message_id", messageId.toString()) - } - - if (contentId != null) { - multicastMessage.putData("content_id", contentId.toString()) - } - - if (creatorId != null) { - multicastMessage.putData("channel_id", creatorId.toString()) - } - - if (auditionId != null) { - multicastMessage.putData("audition_id", auditionId.toString()) - } - - val deepLink = createDeepLink(deepLinkValue, deepLinkId, deepLinkCommentPostId) - if (deepLink != null) { - multicastMessage.putData("deep_link", deepLink) - } + multicastMessage.putAllData( + buildDataPayload( + roomId = roomId, + messageId = messageId, + contentId = contentId, + creatorId = creatorId, + auditionId = auditionId, + deepLink = createDeepLink(deepLinkValue, deepLinkId, deepLinkCommentPostId), + chatType = chatType + ) + ) val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build()) val failedTokens = mutableListOf() @@ -226,5 +214,29 @@ class FcmService( return baseDeepLink } + + fun buildDataPayload( + roomId: Long? = null, + messageId: Long? = null, + contentId: Long? = null, + creatorId: Long? = null, + auditionId: Long? = null, + deepLinkValue: FcmDeepLinkValue? = null, + deepLinkId: Long? = null, + deepLinkCommentPostId: Long? = null, + deepLink: String? = null, + chatType: String? = null + ): Map { + val payload = mutableMapOf() + if (roomId != null) payload["room_id"] = roomId.toString() + if (messageId != null) payload["message_id"] = messageId.toString() + if (chatType != null) payload["chat_type"] = chatType + if (contentId != null) payload["content_id"] = contentId.toString() + if (creatorId != null) payload["channel_id"] = creatorId.toString() + if (auditionId != null) payload["audition_id"] = auditionId.toString() + val resolvedDeepLink = deepLink ?: buildDeepLink("", deepLinkValue, deepLinkId, deepLinkCommentPostId) + if (resolvedDeepLink != null) payload["deep_link"] = resolvedDeepLink + return payload + } } } diff --git a/src/test/kotlin/kr/co/vividnext/sodalive/fcm/FcmServiceTest.kt b/src/test/kotlin/kr/co/vividnext/sodalive/fcm/FcmServiceTest.kt new file mode 100644 index 00000000..a1317ce1 --- /dev/null +++ b/src/test/kotlin/kr/co/vividnext/sodalive/fcm/FcmServiceTest.kt @@ -0,0 +1,27 @@ +package kr.co.vividnext.sodalive.fcm + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +class FcmServiceTest { + @Test + @DisplayName("메시지 푸시 data payload는 채팅 이동에 필요한 chat_type을 포함한다") + fun shouldBuildMessagePayloadWithChatType() { + val payload = FcmService.buildDataPayload( + roomId = 10L, + messageId = 204L, + contentId = null, + creatorId = null, + auditionId = null, + deepLinkValue = null, + deepLinkId = null, + deepLinkCommentPostId = null, + chatType = "USER_CREATOR" + ) + + assertEquals("10", payload["room_id"]) + assertEquals("204", payload["message_id"]) + assertEquals("USER_CREATOR", payload["chat_type"]) + } +}