From e5dba81036e31779a11159f90ebbc5c8c7e40379 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sat, 26 Nov 2022 21:05:49 -0500 Subject: [PATCH] Fix topics do not re-subscribe to Firebase after restoring from backup (#511) --- app/src/main/java/io/heckel/ntfy/backup/Backuper.kt | 7 +++++++ fastlane/metadata/android/en-US/changelog/29.txt | 1 + 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/io/heckel/ntfy/backup/Backuper.kt b/app/src/main/java/io/heckel/ntfy/backup/Backuper.kt index e0f8f92..8c87f90 100644 --- a/app/src/main/java/io/heckel/ntfy/backup/Backuper.kt +++ b/app/src/main/java/io/heckel/ntfy/backup/Backuper.kt @@ -5,9 +5,11 @@ import android.net.Uri import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.stream.JsonReader +import io.heckel.ntfy.R import io.heckel.ntfy.app.Application import io.heckel.ntfy.db.Icon import io.heckel.ntfy.db.Repository +import io.heckel.ntfy.firebase.FirebaseMessenger import io.heckel.ntfy.util.Log import io.heckel.ntfy.util.topicUrl import java.io.InputStreamReader @@ -16,6 +18,7 @@ class Backuper(val context: Context) { private val gson = Gson() private val resolver = context.applicationContext.contentResolver private val repository = (context.applicationContext as Application).repository + private val messenger = FirebaseMessenger() suspend fun backup(uri: Uri, withSettings: Boolean = true, withSubscriptions: Boolean = true, withUsers: Boolean = true) { Log.d(TAG, "Backing up settings to file $uri") @@ -88,6 +91,7 @@ class Backuper(val context: Context) { if (subscriptions == null) { return; } + val appBaseUrl = context.getString(R.string.app_base_url) subscriptions.forEach { s -> try { repository.addSubscription(io.heckel.ntfy.db.Subscription( @@ -104,6 +108,9 @@ class Backuper(val context: Context) { upConnectorToken = s.upConnectorToken, displayName = s.displayName, )) + if (s.baseUrl == appBaseUrl) { + messenger.subscribe(s.topic) + } } catch (e: Exception) { Log.w(TAG, "Unable to restore subscription ${s.id} (${topicUrl(s.baseUrl, s.topic)}): ${e.message}. Ignoring.", e) } diff --git a/fastlane/metadata/android/en-US/changelog/29.txt b/fastlane/metadata/android/en-US/changelog/29.txt index 3012700..cb3518c 100644 --- a/fastlane/metadata/android/en-US/changelog/29.txt +++ b/fastlane/metadata/android/en-US/changelog/29.txt @@ -5,6 +5,7 @@ Bug fixes + maintenance: * Remove timestamp when copying message text (#471, thanks to @wunter8) * Fix auto-delete if some icons do not exist anymore (#506) * Fix notification icon color (#480, thanks to @s-h-a-r-d for reporting) +* Fix topics do not re-subscribe to Firebase after restoring from backup (#511) * Add donate button (no ticket) Additional translations: