fix(dm): FCM deep_link payload 알림 생성을 보정한다

This commit is contained in:
2026-06-19 05:03:14 +09:00
parent 8b515bba97
commit 9c642fb3b7
2 changed files with 27 additions and 6 deletions

View File

@@ -31,6 +31,8 @@ class SodaFirebaseMessagingService : FirebaseMessagingService() {
remoteMessage.notification != null
) {
sendNotification(remoteMessage.data, remoteMessage.notification)
} else if (hasDeepLink(remoteMessage.data)) {
sendNotification(remoteMessage.data, remoteMessage.notification)
} else if (remoteMessage.data["message"]?.isNotBlank() == true) {
sendNotification(remoteMessage.data, remoteMessage.notification)
}
@@ -43,6 +45,11 @@ class SodaFirebaseMessagingService : FirebaseMessagingService() {
SharedPreferenceManager.pushToken = token
}
private fun hasDeepLink(messageData: Map<String, String>): Boolean {
return messageData["deepLink"]?.isNotBlank() == true ||
messageData["deep_link"]?.isNotBlank() == true
}
private fun sendNotification(
messageData: Map<String, String>,
notification: RemoteMessage.Notification?
@@ -78,13 +85,11 @@ class SodaFirebaseMessagingService : FirebaseMessagingService() {
val deepLinkExtras = if (!deepLinkUrl.isNullOrBlank()) {
android.os.Bundle().apply {
putString("deep_link", deepLinkUrl)
messageData["chat_type"]?.let { putString("chat_type", it) }
messageData["room_id"]?.let { putString("room_id", it) }
}
} else {
android.os.Bundle().apply {
messageData["room_id"]?.let { putString("room_id", it) }
messageData["chat_type"]?.let { putString("chat_type", it) }
messageData["message_id"]?.let { putString("message_id", it) }
messageData["content_id"]?.let { putString("content_id", it) }
messageData["channel_id"]?.let { putString("channel_id", it) }

View File

@@ -1,5 +1,6 @@
package kr.co.vividnext.sodalive.fcm
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.io.File
@@ -7,19 +8,19 @@ import java.io.File
class SodaFirebaseMessagingServiceSourceTest {
@Test
fun `FCM notification extras는 DM chat_type과 기존 deep link 값을 보존다`() {
fun `FCM notification extras는 기존 deep link 값을 보존하고 chat_type을 사용하지 않는다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/fcm/SodaFirebaseMessagingService.kt"
).readText()
assertTrue(source.contains("messageData[\"chat_type\"]?.let { putString(\"chat_type\", it) }"))
assertFalse(source.contains("chat_type"))
assertTrue(source.contains("messageData[\"room_id\"]?.let { putString(\"room_id\", it) }"))
assertTrue(source.contains("messageData[\"message_id\"]?.let { putString(\"message_id\", it) }"))
assertTrue(source.contains("messageData[\"deep_link_value\"]?.let { putString(\"deep_link_value\", it) }"))
}
@Test
fun `FCM deepLink payload도 DM chat_type과 room_id를 extra bundle에 보존한다`() {
fun `FCM deepLink payload는 deep_link와 room_id를 extra bundle에 보존한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/fcm/SodaFirebaseMessagingService.kt"
).readText()
@@ -29,10 +30,25 @@ class SodaFirebaseMessagingServiceSourceTest {
val deepLinkBundleSource = source.substring(deepLinkBundleStart, fallbackBundleStart)
assertTrue(deepLinkBundleSource.contains("putString(\"deep_link\", deepLinkUrl)"))
assertTrue(deepLinkBundleSource.contains("messageData[\"chat_type\"]?.let { putString(\"chat_type\", it) }"))
assertTrue(deepLinkBundleSource.contains("messageData[\"room_id\"]?.let { putString(\"room_id\", it) }"))
}
@Test
fun `FCM deep_link 단독 payload는 deep_link extra와 ACTION_VIEW data로 보존한다`() {
val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/fcm/SodaFirebaseMessagingService.kt"
).readText()
assertTrue(source.contains("} else if (hasDeepLink(remoteMessage.data)) {"))
assertTrue(source.contains("private fun hasDeepLink(messageData: Map<String, String>): Boolean"))
assertTrue(source.contains("messageData[\"deepLink\"]?.isNotBlank() == true"))
assertTrue(source.contains("messageData[\"deep_link\"]?.isNotBlank() == true"))
assertTrue(source.contains("val deepLinkUrl = messageData[\"deepLink\"] ?: messageData[\"deep_link\"]"))
assertTrue(source.contains("intent.action = Intent.ACTION_VIEW"))
assertTrue(source.contains("intent.data = Uri.parse(deepLinkUrl)"))
assertTrue(source.contains("putString(\"deep_link\", deepLinkUrl)"))
}
private fun projectFile(relativePath: String): File {
val candidates = listOf(File(relativePath), File("../$relativePath"))
return candidates.firstOrNull { it.exists() }