diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt index 68e344b8fe..f1f999242c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt @@ -166,6 +166,8 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( const val RESET_SEQ_NO = "UPDATE $lastMessageServerIDTable SET $lastMessageServerID = 0;" + const val EMPTY_VERSION = "0.0.0" + // endregion } @@ -179,7 +181,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null val x25519Key = components.getOrNull(3) ?: return@mapNotNull null - val version = components.getOrNull(4) ?: "0.0.0" + val version = components.getOrNull(4) ?: EMPTY_VERSION Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) } }?.toSet() ?: setOf() @@ -235,7 +237,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( val port = components.getOrNull(1)?.toIntOrNull() val ed25519Key = components.getOrNull(2) val x25519Key = components.getOrNull(3) - val version = components.getOrNull(4) ?: "0.0.0" + val version = components.getOrNull(4) ?: EMPTY_VERSION if (port != null && ed25519Key != null && x25519Key != null) { Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) } else { @@ -280,7 +282,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null val x25519Key = components.getOrNull(3) ?: return@mapNotNull null - val version = components.getOrNull(4) ?: "0.0.0" + val version = components.getOrNull(4) ?: EMPTY_VERSION Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) } }?.toSet() diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 9ba49e2b19..9b008fad06 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -94,6 +94,8 @@ object SnodeAPI { const val KEY_ED25519 = "pubkey_ed25519" const val KEY_VERSION = "storage_server_version" + const val EMPTY_VERSION = "0.0.0" + // Error internal sealed class Error(val description: String) : Exception(description) { object Generic : Error("An error occurred.") @@ -744,7 +746,7 @@ object SnodeAPI { val x25519Key = rawSnodeAsJSON?.get(KEY_X25519) as? String if (address != null && port != null && ed25519Key != null && x25519Key != null && address != "0.0.0.0") { - Snode("https://$address", port, Snode.KeySet(ed25519Key, x25519Key), "0.0.0") + Snode("https://$address", port, Snode.KeySet(ed25519Key, x25519Key), EMPTY_VERSION) } else { Log.d("Loki", "Failed to parse snode from: ${rawSnode?.prettifiedDescription()}.") null