PR feedback

This commit is contained in:
ThomasSession 2024-07-23 17:31:23 +10:00
parent af9f581f18
commit bf1548d98e
2 changed files with 8 additions and 4 deletions

View File

@ -166,6 +166,8 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
const val RESET_SEQ_NO = "UPDATE $lastMessageServerIDTable SET $lastMessageServerID = 0;" const val RESET_SEQ_NO = "UPDATE $lastMessageServerIDTable SET $lastMessageServerID = 0;"
const val EMPTY_VERSION = "0.0.0"
// endregion // endregion
} }
@ -179,7 +181,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null
val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null
val x25519Key = components.getOrNull(3) ?: 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) Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version)
} }
}?.toSet() ?: setOf() }?.toSet() ?: setOf()
@ -235,7 +237,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
val port = components.getOrNull(1)?.toIntOrNull() val port = components.getOrNull(1)?.toIntOrNull()
val ed25519Key = components.getOrNull(2) val ed25519Key = components.getOrNull(2)
val x25519Key = components.getOrNull(3) 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) { if (port != null && ed25519Key != null && x25519Key != null) {
Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version)
} else { } else {
@ -280,7 +282,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null
val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null
val x25519Key = components.getOrNull(3) ?: 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) Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version)
} }
}?.toSet() }?.toSet()

View File

@ -94,6 +94,8 @@ object SnodeAPI {
const val KEY_ED25519 = "pubkey_ed25519" const val KEY_ED25519 = "pubkey_ed25519"
const val KEY_VERSION = "storage_server_version" const val KEY_VERSION = "storage_server_version"
const val EMPTY_VERSION = "0.0.0"
// Error // Error
internal sealed class Error(val description: String) : Exception(description) { internal sealed class Error(val description: String) : Exception(description) {
object Generic : Error("An error occurred.") object Generic : Error("An error occurred.")
@ -744,7 +746,7 @@ object SnodeAPI {
val x25519Key = rawSnodeAsJSON?.get(KEY_X25519) as? String val x25519Key = rawSnodeAsJSON?.get(KEY_X25519) as? String
if (address != null && port != null && ed25519Key != null && x25519Key != null && address != "0.0.0.0") { 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 { } else {
Log.d("Loki", "Failed to parse snode from: ${rawSnode?.prettifiedDescription()}.") Log.d("Loki", "Failed to parse snode from: ${rawSnode?.prettifiedDescription()}.")
null null