From fa44b74f09e654c1324a8b22a3a5ab847dcebbe0 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 29 Jun 2024 15:33:39 -0400 Subject: [PATCH] Adds a try/catch when receiving notifications to make sure it gets decrypted by the correct account. --- .../service/notifications/EventNotificationConsumer.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt index 7580bdc2e..f75a5de2b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt @@ -58,7 +58,11 @@ class EventNotificationConsumer( LocalPreferences.allSavedAccounts().forEach { if (it.hasPrivKey || it.loggedInWithExternalSigner) { LocalPreferences.loadCurrentAccountFromEncryptedStorage(it.npub)?.let { acc -> - consumeIfMatchesAccount(event, acc) + try { + consumeIfMatchesAccount(event, acc) + } catch (e: Exception) { + // Not for this account. + } } } } @@ -71,7 +75,7 @@ class EventNotificationConsumer( pushWrappedEvent.cachedGift(account.signer) { notificationEvent -> val consumed = LocalCache.hasConsumed(notificationEvent) val verified = LocalCache.justVerify(notificationEvent) - Log.d("EventNotificationConsumer", "New Notification Arrived for ${account.userProfile().toBestDisplayName()} consumed= $consumed && verified= $verified") + Log.d("EventNotificationConsumer", "New Notification ${notificationEvent.kind} ${notificationEvent.id} Arrived for ${account.userProfile().toBestDisplayName()} consumed= $consumed && verified= $verified") if (!consumed && verified) { Log.d("EventNotificationConsumer", "New Notification was verified") unwrapAndConsume(notificationEvent, account) { innerEvent ->