fix: honour silent push mode for data-only FCM (0.4.7)
Handle notifications synchronously in onMessageReceived and read title/body from data payload sent by SAC. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
||||
applicationId = "ru.kalinamall.seaca"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 10
|
||||
versionName = "0.4.6"
|
||||
versionCode = 11
|
||||
versionName = "0.4.7"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
@@ -6,6 +6,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import ru.kalinamall.seaca.data.NotificationMode
|
||||
import ru.kalinamall.seaca.data.SacRepository
|
||||
|
||||
@@ -14,19 +15,18 @@ class SeacaMessagingService : FirebaseMessagingService() {
|
||||
private val repo by lazy { SacRepository(applicationContext) }
|
||||
|
||||
override fun onMessageReceived(message: RemoteMessage) {
|
||||
scope.launch {
|
||||
when (repo.session.getNotificationMode()) {
|
||||
NotificationMode.OFF -> return@launch
|
||||
val mode = runBlocking { repo.session.getNotificationMode() }
|
||||
when (mode) {
|
||||
NotificationMode.OFF -> return
|
||||
NotificationMode.PUSH_SILENT -> show(message, silent = true)
|
||||
NotificationMode.PUSH_SOUND -> show(message, silent = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun show(message: RemoteMessage, silent: Boolean) {
|
||||
val data = message.data
|
||||
val title = message.notification?.title ?: data["title"] ?: "SAC"
|
||||
val body = message.notification?.body ?: data["body"] ?: ""
|
||||
val title = data["title"] ?: message.notification?.title ?: "SAC"
|
||||
val body = data["body"] ?: message.notification?.body ?: ""
|
||||
NotificationHelper.show(
|
||||
context = this,
|
||||
title = title,
|
||||
|
||||
Reference in New Issue
Block a user