Attempt fixing blank notifications

This commit is contained in:
Phillip Thelen 2024-01-10 15:56:30 +01:00
parent 6715566ece
commit 486a1d451b
2 changed files with 21 additions and 7 deletions

View file

@ -50,6 +50,10 @@ abstract class HabiticaLocalNotification(
notificationBuilder = notificationBuilder.setContentText(message)
}
if (this.title == null && this.message == null) {
return
}
val notificationId = getNotificationID(data)
this.setNotificationActions(notificationId, data)

View file

@ -134,11 +134,6 @@ class PushNotificationManager(
fun displayNotification(remoteMessage: RemoteMessage, context: Context, pushNotificationManager: PushNotificationManager? = null) {
val remoteMessageIdentifier = remoteMessage.data["identifier"]
val notificationFactory = HabiticaLocalNotificationFactory()
val notification = notificationFactory.build(
remoteMessageIdentifier,
context
)
if (pushNotificationManager?.userIsSubscribedToNotificationType(remoteMessageIdentifier) != false) {
if (remoteMessage.data.containsKey("sendAnalytics")) {
val additionalData = HashMap<String, Any>()
@ -150,8 +145,23 @@ class PushNotificationManager(
additionalData
)
}
notification.setExtras(remoteMessage.data)
notification.notifyLocally(remoteMessage.data["title"], remoteMessage.data["body"], remoteMessage.data)
val notification = remoteMessage.notification
if (notification != null) {
val notificationManager = NotificationManagerCompat.from(context)
notificationManager.notify(notification.channelId, notification)
} else {
val notificationFactory = HabiticaLocalNotificationFactory()
val localNotification = notificationFactory.build(
remoteMessageIdentifier,
context
)
localNotification.setExtras(remoteMessage.data)
localNotification.notifyLocally(
remoteMessage.data["title"],
remoteMessage.data["body"],
remoteMessage.data
)
}
}
}
}