test #426
@@ -45,6 +45,7 @@ class FcmEvent(
|
|||||||
val roomId: Long? = null,
|
val roomId: Long? = null,
|
||||||
val contentId: Long? = null,
|
val contentId: Long? = null,
|
||||||
val messageId: Long? = null,
|
val messageId: Long? = null,
|
||||||
|
val chatType: String? = null,
|
||||||
val creatorId: Long? = null,
|
val creatorId: Long? = null,
|
||||||
val auditionId: Long? = null,
|
val auditionId: Long? = null,
|
||||||
val deepLinkValue: FcmDeepLinkValue? = null,
|
val deepLinkValue: FcmDeepLinkValue? = null,
|
||||||
@@ -191,6 +192,7 @@ class FcmSendListener(
|
|||||||
roomId = roomId ?: fcmEvent.roomId,
|
roomId = roomId ?: fcmEvent.roomId,
|
||||||
contentId = contentId ?: fcmEvent.contentId,
|
contentId = contentId ?: fcmEvent.contentId,
|
||||||
messageId = messageId ?: fcmEvent.messageId,
|
messageId = messageId ?: fcmEvent.messageId,
|
||||||
|
chatType = fcmEvent.chatType,
|
||||||
creatorId = creatorId ?: fcmEvent.creatorId,
|
creatorId = creatorId ?: fcmEvent.creatorId,
|
||||||
auditionId = auditionId ?: fcmEvent.auditionId,
|
auditionId = auditionId ?: fcmEvent.auditionId,
|
||||||
deepLinkValue = fcmEvent.deepLinkValue,
|
deepLinkValue = fcmEvent.deepLinkValue,
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ class FcmService(
|
|||||||
auditionId: Long? = null,
|
auditionId: Long? = null,
|
||||||
deepLinkValue: FcmDeepLinkValue? = null,
|
deepLinkValue: FcmDeepLinkValue? = null,
|
||||||
deepLinkId: Long? = null,
|
deepLinkId: Long? = null,
|
||||||
deepLinkCommentPostId: Long? = null
|
deepLinkCommentPostId: Long? = null,
|
||||||
|
chatType: String? = null
|
||||||
) {
|
) {
|
||||||
if (tokens.isEmpty()) return
|
if (tokens.isEmpty()) return
|
||||||
logger.info("os: $container")
|
logger.info("os: $container")
|
||||||
@@ -70,30 +71,17 @@ class FcmService(
|
|||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
|
||||||
if (roomId != null) {
|
multicastMessage.putAllData(
|
||||||
multicastMessage.putData("room_id", roomId.toString())
|
buildDataPayload(
|
||||||
}
|
roomId = roomId,
|
||||||
|
messageId = messageId,
|
||||||
if (messageId != null) {
|
contentId = contentId,
|
||||||
multicastMessage.putData("message_id", messageId.toString())
|
creatorId = creatorId,
|
||||||
}
|
auditionId = auditionId,
|
||||||
|
deepLink = createDeepLink(deepLinkValue, deepLinkId, deepLinkCommentPostId),
|
||||||
if (contentId != null) {
|
chatType = chatType
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build())
|
val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build())
|
||||||
val failedTokens = mutableListOf<String>()
|
val failedTokens = mutableListOf<String>()
|
||||||
@@ -226,5 +214,29 @@ class FcmService(
|
|||||||
|
|
||||||
return baseDeepLink
|
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<String, String> {
|
||||||
|
val payload = mutableMapOf<String, String>()
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"])
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user