mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Update how swarms are stored in the database.
This commit is contained in:
parent
1e014a690f
commit
f7197ca1de
@ -66,9 +66,13 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
return database.get(swarmCache, "${Companion.hexEncodedPublicKey} = ?", wrap(hexEncodedPublicKey)) { cursor ->
|
return database.get(swarmCache, "${Companion.hexEncodedPublicKey} = ?", wrap(hexEncodedPublicKey)) { cursor ->
|
||||||
val swarmAsString = cursor.getString(cursor.getColumnIndexOrThrow(swarm))
|
val swarmAsString = cursor.getString(cursor.getColumnIndexOrThrow(swarm))
|
||||||
swarmAsString.split(", ").map { targetAsString ->
|
swarmAsString.split(", ").mapNotNull { targetAsString ->
|
||||||
val components = targetAsString.split("?port=")
|
val components = targetAsString.split("-")
|
||||||
LokiAPITarget(components[0], components[1].toInt())
|
val address = components[0]
|
||||||
|
val port = components.getOrNull(1) ?: return@mapNotNull null
|
||||||
|
val identificationKey = components.getOrNull(2) ?: return@mapNotNull null
|
||||||
|
val encryptionKey = components.getOrNull(3)?: return@mapNotNull null
|
||||||
|
LokiAPITarget(address, port.toInt(), LokiAPITarget.Keys(identificationKey, encryptionKey))
|
||||||
}
|
}
|
||||||
}?.toSet()
|
}?.toSet()
|
||||||
}
|
}
|
||||||
@ -76,7 +80,12 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
override fun setSwarmCache(hexEncodedPublicKey: String, newValue: Set<LokiAPITarget>) {
|
override fun setSwarmCache(hexEncodedPublicKey: String, newValue: Set<LokiAPITarget>) {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
val swarmAsString = newValue.joinToString(", ") { target ->
|
val swarmAsString = newValue.joinToString(", ") { target ->
|
||||||
"${target.address}?port=${target.port}"
|
var string = "${target.address}-${target.port}"
|
||||||
|
val keys = target.publicKeys
|
||||||
|
if (keys != null) {
|
||||||
|
string += "-${keys.identification}-${keys.encryption}"
|
||||||
|
}
|
||||||
|
string
|
||||||
}
|
}
|
||||||
val row = wrap(mapOf( Companion.hexEncodedPublicKey to hexEncodedPublicKey, swarm to swarmAsString ))
|
val row = wrap(mapOf( Companion.hexEncodedPublicKey to hexEncodedPublicKey, swarm to swarmAsString ))
|
||||||
database.insertOrUpdate(swarmCache, row, "${Companion.hexEncodedPublicKey} = ?", wrap(hexEncodedPublicKey))
|
database.insertOrUpdate(swarmCache, row, "${Companion.hexEncodedPublicKey} = ?", wrap(hexEncodedPublicKey))
|
||||||
|
Loading…
Reference in New Issue
Block a user