fix(push): create notification channels from profiles
这个提交包含在:
父节点
999e21bcf2
当前提交
fbc6f089c1
@ -15,11 +15,13 @@ internal object PushNotificationChannelManager {
|
|||||||
|
|
||||||
fun apply(context: Context, pushConfig: JsonObject?) {
|
fun apply(context: Context, pushConfig: JsonObject?) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || pushConfig == null) return
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || pushConfig == null) return
|
||||||
val channels = pushConfig.getAsJsonArray("channels") ?: return
|
|
||||||
val channelByKey = mutableMapOf<String, String>()
|
val channelByKey = mutableMapOf<String, String>()
|
||||||
|
val routeToChannel = mutableMapOf<String, String>()
|
||||||
val manager = context.getSystemService(NotificationManager::class.java)
|
val manager = context.getSystemService(NotificationManager::class.java)
|
||||||
|
|
||||||
channels.mapNotNull { it.takeIf { item -> item.isJsonObject }?.asJsonObject }
|
pushConfig.getAsJsonArray("channels")
|
||||||
|
?.mapNotNull { it.takeIf { item -> item.isJsonObject }?.asJsonObject }
|
||||||
|
.orEmpty()
|
||||||
.forEach { channel ->
|
.forEach { channel ->
|
||||||
val key = channel.text("key").ifBlank { return@forEach }
|
val key = channel.text("key").ifBlank { return@forEach }
|
||||||
val baseChannelId = channel.text("channelId").ifBlank { key }
|
val baseChannelId = channel.text("channelId").ifBlank { key }
|
||||||
@ -42,6 +44,34 @@ internal object PushNotificationChannelManager {
|
|||||||
Log.d(TAG, "Notification channel ready key=$key id=$effectiveChannelId")
|
Log.d(TAG, "Notification channel ready key=$key id=$effectiveChannelId")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Current tenant PUSH schema stores notification channels directly in profiles.
|
||||||
|
// Vendor push APIs send this exact channelId, so do not append a version suffix.
|
||||||
|
pushConfig.getAsJsonArray("profiles")
|
||||||
|
?.mapNotNull { it.takeIf { item -> item.isJsonObject }?.asJsonObject }
|
||||||
|
.orEmpty()
|
||||||
|
.filter { it.bool("enabled", true) }
|
||||||
|
.forEach { profile ->
|
||||||
|
val channelId = profile.text("channelId").ifBlank { return@forEach }
|
||||||
|
val routeType = profile.text("routeType").ifBlank { "DEFAULT" }
|
||||||
|
val profileKey = profile.text("profileKey").ifBlank { routeType }
|
||||||
|
val notificationChannel = NotificationChannel(
|
||||||
|
channelId,
|
||||||
|
routeType,
|
||||||
|
profile.importance(),
|
||||||
|
).apply {
|
||||||
|
description = profile.text("remark")
|
||||||
|
enableVibration(profile.bool("vibration", true))
|
||||||
|
setShowBadge(profile.bool("badge", true))
|
||||||
|
if (!profile.bool("sound", true)) {
|
||||||
|
setSound(null, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
manager.createNotificationChannel(notificationChannel)
|
||||||
|
channelByKey[profileKey] = channelId
|
||||||
|
routeToChannel[routeType] = channelId
|
||||||
|
Log.d(TAG, "Profile notification channel ready route=$routeType id=$channelId")
|
||||||
|
}
|
||||||
|
|
||||||
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
prefs.edit().apply {
|
prefs.edit().apply {
|
||||||
channelByKey.forEach { (key, channelId) -> putString("channel_$key", channelId) }
|
channelByKey.forEach { (key, channelId) -> putString("channel_$key", channelId) }
|
||||||
@ -52,6 +82,9 @@ internal object PushNotificationChannelManager {
|
|||||||
val channelId = channelByKey[channelKey] ?: return@forEach
|
val channelId = channelByKey[channelKey] ?: return@forEach
|
||||||
putString(KEY_PREFIX_ROUTE + type, channelId)
|
putString(KEY_PREFIX_ROUTE + type, channelId)
|
||||||
}
|
}
|
||||||
|
routeToChannel.forEach { (routeType, channelId) ->
|
||||||
|
putString(KEY_PREFIX_ROUTE + routeType, channelId)
|
||||||
|
}
|
||||||
}.apply()
|
}.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户