diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt index fd06198ae..03be8b972 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt @@ -46,7 +46,7 @@ class EventNotificationConsumer(private val applicationContext: Context) { val user = note.author?.toBestDisplayName() ?: "" val userPicture = note.author?.profilePicture() val noteUri = note.toNEvent() - notificationManager().sendDMNotification(content, user, userPicture, noteUri, applicationContext) + notificationManager().sendDMNotification(event.id, content, user, userPicture, noteUri, applicationContext) } } } @@ -88,7 +88,7 @@ class EventNotificationConsumer(private val applicationContext: Context) { } val userPicture = senderInfo?.first?.profilePicture() val noteUri = "nostr:Notifications" - notificationManager().sendZapNotification(content, title, userPicture, noteUri, applicationContext) + notificationManager().sendZapNotification(event.id, content, title, userPicture, noteUri, applicationContext) } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationUtils.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationUtils.kt index d8d5d5d0b..36a5bcb84 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationUtils.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationUtils.kt @@ -15,10 +15,6 @@ import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.ui.MainActivity object NotificationUtils { - - // Notification ID. - private var notificationId = 0 - private var dmChannel: NotificationChannel? = null private var zapChannel: NotificationChannel? = null @@ -63,6 +59,7 @@ object NotificationUtils { } fun NotificationManager.sendZapNotification( + id: String, messageBody: String, messageTitle: String, pictureUrl: String?, @@ -72,10 +69,11 @@ object NotificationUtils { val zapChannel = getOrCreateZapChannel(applicationContext) val channelId = applicationContext.getString(R.string.app_notification_zaps_channel_id) - sendNotification(messageBody, messageTitle, pictureUrl, uri, channelId, applicationContext) + sendNotification(id, messageBody, messageTitle, pictureUrl, uri, channelId, applicationContext) } fun NotificationManager.sendDMNotification( + id: String, messageBody: String, messageTitle: String, pictureUrl: String?, @@ -85,10 +83,11 @@ object NotificationUtils { val dmChannel = getOrCreateDMChannel(applicationContext) val channelId = applicationContext.getString(R.string.app_notification_dms_channel_id) - sendNotification(messageBody, messageTitle, pictureUrl, uri, channelId, applicationContext) + sendNotification(id, messageBody, messageTitle, pictureUrl, uri, channelId, applicationContext) } fun NotificationManager.sendNotification( + id: String, messageBody: String, messageTitle: String, pictureUrl: String?, @@ -104,6 +103,7 @@ object NotificationUtils { val imageLoader = ImageLoader(applicationContext) val imageResult = imageLoader.executeBlocking(request) sendNotification( + id = id, messageBody = messageBody, messageTitle = messageTitle, picture = imageResult.drawable as? BitmapDrawable, @@ -113,6 +113,7 @@ object NotificationUtils { ) } else { sendNotification( + id = id, messageBody = messageBody, messageTitle = messageTitle, picture = null, @@ -124,6 +125,7 @@ object NotificationUtils { } private fun NotificationManager.sendNotification( + id: String, messageBody: String, messageTitle: String, picture: BitmapDrawable?, @@ -137,7 +139,7 @@ object NotificationUtils { val contentPendingIntent = PendingIntent.getActivity( applicationContext, - notificationId, + id.hashCode(), contentIntent, PendingIntent.FLAG_MUTABLE ) @@ -171,9 +173,7 @@ object NotificationUtils { .setPriority(NotificationCompat.PRIORITY_HIGH) .setAutoCancel(true) - notify(notificationId, builder.build()) - - notificationId++ + notify(id.hashCode(), builder.build()) } /**