retry registering with push server and show message if failed

reconnect with relays when changing notification type
This commit is contained in:
greenart7c3
2024-06-26 13:45:31 -03:00
parent 582ee7447d
commit 13650b219c
3 changed files with 30 additions and 7 deletions
@@ -25,7 +25,9 @@ import com.greenart7c3.nostrsigner.AccountInfo
import com.greenart7c3.nostrsigner.BuildConfig
import com.greenart7c3.nostrsigner.LocalPreferences
import com.greenart7c3.nostrsigner.NostrSigner
import com.greenart7c3.nostrsigner.database.LogEntity
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.relays.AmberListenerSingleton
import com.vitorpamplona.ammolite.service.HttpClientManager
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
@@ -117,12 +119,32 @@ class RegisterAccounts(
.build()
val client = HttpClientManager.getHttpClient()
client.newCall(request).execute().use {
if (it.isSuccessful) {
Log.d("FirebaseMsgService", "Successfully registered with push server")
} else {
Log.d("FirebaseMsgService", "Failed to register with push server")
var isSuccess = client.newCall(request).execute().use {
it.isSuccessful
}
var tries = 0
while (!isSuccess && tries < 3) {
Log.d("FirebaseMsgService", "Failed to register with push server, retrying...")
isSuccess = client.newCall(request).execute().use {
it.isSuccessful
}
tries++
}
if (isSuccess) {
Log.d("FirebaseMsgService", "Successfully registered with push server")
} else {
accounts.forEach {
NostrSigner.instance.getDatabase(it.npub).applicationDao().insertLog(
LogEntity(
0,
"Push server",
"Push server",
"Failed to register with push server",
System.currentTimeMillis(),
),
)
}
AmberListenerSingleton.accountStateViewModel?.toast("Push server", "Failed to register with push server")
}
} catch (e: java.lang.Exception) {
if (e is CancellationException) throw e
@@ -321,13 +321,14 @@ fun SettingsScreen(
NotificationDataSource.stopSync()
RelayPool.disconnect()
} else {
NostrSigner.instance.checkForNewRelays()
NotificationDataSource.start()
NostrSigner.instance.applicationContext.startService(
Intent(
NostrSigner.instance.applicationContext,
ConnectivityService::class.java,
),
)
NotificationDataSource.start()
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ lifecycle_version = "2.8.2"
material3 = "1.2.1"
mockk = "1.13.11"
nav_version = "2.7.7"
quartz = "main-SNAPSHOT"
quartz = "d6ab376f2d"
compose_ui = "1.6.8"
richtextUi = "077a2cde64"
roomKtx = "2.6.1"