From 2d39b4edfed2d25ae30aead56fe6af8b54e40b7c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 27 Aug 2024 17:41:37 -0400 Subject: [PATCH] Only register for endpoints if it has changed from the one in memory --- .../notifications/PushMessageReceiver.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt index 68926667f..41ae86871 100644 --- a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt +++ b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt @@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.service.notifications import android.app.NotificationManager import android.content.Context -import android.content.Intent import android.util.Log import android.util.LruCache import androidx.core.content.ContextCompat @@ -83,13 +82,17 @@ class PushMessageReceiver : MessagingReceiver() { endpoint: String, instance: String, ) { - Log.d(TAG, "New endpoint provided:- $endpoint for Instance: $instance") val sanitizedEndpoint = endpoint.dropLast(5) - pushHandler.setEndpoint(sanitizedEndpoint) - scope.launch(Dispatchers.IO) { - RegisterAccounts(LocalPreferences.allSavedAccounts()).go(sanitizedEndpoint) - notificationManager().getOrCreateZapChannel(appContext) - notificationManager().getOrCreateDMChannel(appContext) + if (sanitizedEndpoint != pushHandler.getSavedEndpoint()) { + Log.d(TAG, "New endpoint provided:- $endpoint for Instance: $instance ${pushHandler.getSavedEndpoint()} $sanitizedEndpoint") + pushHandler.setEndpoint(sanitizedEndpoint) + scope.launch(Dispatchers.IO) { + RegisterAccounts(LocalPreferences.allSavedAccounts()).go(sanitizedEndpoint) + notificationManager().getOrCreateZapChannel(appContext) + notificationManager().getOrCreateDMChannel(appContext) + } + } else { + Log.d(TAG, "Same endpoint provided:- $endpoint for Instance: $instance $sanitizedEndpoint") } }