diff --git a/app/src/main/java/io/heckel/ntfy/db/Repository.kt b/app/src/main/java/io/heckel/ntfy/db/Repository.kt index f5f0aeac..502cb397 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Repository.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Repository.kt @@ -27,6 +27,7 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database) private val connectionDetails = ConcurrentHashMap() private val connectionDetailsLiveData = MutableLiveData>(connectionDetails) + private val reconnectVersions = ConcurrentHashMap() // TODO Move these into an ApplicationState singleton val detailViewSubscriptionId = AtomicLong(0L) // Omg, what a hack ... @@ -572,6 +573,15 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database) return connectionDetails[baseUrl] } + fun getReconnectVersion(baseUrl: String): Long { + return reconnectVersions[baseUrl] ?: 0L + } + + fun incrementReconnectVersion(baseUrl: String) { + reconnectVersions.compute(baseUrl) { _, current -> (current ?: 0L) + 1 } + Log.d(TAG, "Reconnect version incremented for $baseUrl: ${reconnectVersions[baseUrl]}") + } + companion object { const val SHARED_PREFS_ID = "MainPreferences" const val SHARED_PREFS_POLL_WORKER_VERSION = "PollWorkerVersion" diff --git a/app/src/main/java/io/heckel/ntfy/service/Connection.kt b/app/src/main/java/io/heckel/ntfy/service/Connection.kt index cb298b3a..3af4a3f6 100644 --- a/app/src/main/java/io/heckel/ntfy/service/Connection.kt +++ b/app/src/main/java/io/heckel/ntfy/service/Connection.kt @@ -17,5 +17,6 @@ data class ConnectionId( val credentialsHash: Int, // Hash of "username:password" or 0 if no user val headersHash: Int, // Hash of sorted headers or 0 if none val trustedCertsHash: Int, // Hash of trusted certificates or 0 if none - val clientCertHash: Int // Hash of client certificate or 0 if none + val clientCertHash: Int, // Hash of client certificate or 0 if none + val reconnectVersion: Long // Incremented to force reconnection for this baseUrl ) diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index d9e8f0b3..dece6eea 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -220,6 +220,7 @@ class SubscriberService : Service() { .hashCode() val trustedCertsHash = repository.getTrustedCertificate(baseUrl)?.hashCode() ?: 0 val clientCertHash = repository.getClientCertificate(baseUrl)?.hashCode() ?: 0 + val reconnectVersion = repository.getReconnectVersion(baseUrl) ConnectionId( baseUrl = baseUrl, topicsToSubscriptionIds = subs.associate { s -> s.topic to s.id }, @@ -227,7 +228,8 @@ class SubscriberService : Service() { credentialsHash = credentialsHash, headersHash = headersHash, trustedCertsHash = trustedCertsHash, - clientCertHash = clientCertHash + clientCertHash = clientCertHash, + reconnectVersion = reconnectVersion ) } .toSet() diff --git a/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt index 6924d092..03b5a0b6 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt @@ -72,6 +72,9 @@ class ConnectionErrorFragment : DialogFragment() { toolbar.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.connection_error_dialog_action_retry -> { + selectedBaseUrl?.let { baseUrl -> + repository.incrementReconnectVersion(baseUrl) + } SubscriberServiceManager.refresh(requireContext()) dismiss() true