Modern Apps git

← Modern-Apps.git

findfamily: backward compatibility fixes

Commit
c6e590f8e984feeaef5a0a4d8d098f64dfc635e5
Author
Vayun Mathur <[email protected]>
When
2026-02-19 23:45 UTC (9 months ago)
Parents
1a38737

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/Networking.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/Networking.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/Networking.ktindex 661df903d0..6f9c7168c1 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/Networking.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/Networking.kt@@ -1,6 +1,7 @@ package com.vayunmathur.findfamily  import com.vayunmathur.findfamily.data.LocationValue+import com.vayunmathur.findfamily.data.LocationValueCompatible import com.vayunmathur.findfamily.data.TemporaryLink import com.vayunmathur.findfamily.data.User import com.vayunmathur.library.util.DataStoreUtils@@ -114,16 +115,16 @@ object Networking {     }      suspend fun ensureUserExists() {-        if(getKey(userid.toULong()) == null) {+        if(getKey(userid) == null) {             register()         }     } -    private suspend fun getKey(userid: ULong): RSA.OAEP.PublicKey? {+    private suspend fun getKey(userid: Long): RSA.OAEP.PublicKey? {         return checkNetworkDown {             val response = client.post("${getUrl()}/api/getkey") {                 contentType(ContentType.Application.Json)-                setBody("{\"userid\": $userid}")+                setBody("{\"userid\": ${userid.toULong()}}")             }             if(response.status != HttpStatusCode.OK) {                 return@checkNetworkDown null@@ -140,19 +141,19 @@ object Networking {                 Base64.decode(user.encryptionKey)             )         } else {-            getKey(user.id.toULong())?.also {+            getKey(user.id)?.also {                 val keyString = Base64.encode(it.encodeToByteArray(RSA.PublicKey.Format.PEM))                 viewModel.upsert(user.copy(encryptionKey = keyString))             }         } ?: return false-        return makeRequest("/api/location/publish", encryptLocation(location, user.id.toULong(), key)) ?: false+        return makeRequest("/api/location/publish", encryptLocation(location, user.id, key)) ?: false     }      suspend fun publishLocation(location: LocationValue, user: TemporaryLink): Boolean {         val key = crypto.publicKeyDecoder(SHA512).decodeFromByteArray(RSA.PublicKey.Format.PEM,             Base64.decode(user.publicKey)         )-        return makeRequest("/api/location/publish", encryptLocation(location, user.id.toULong(), key)) ?: false+        return makeRequest("/api/location/publish", encryptLocation(location, user.id, key)) ?: false     }      suspend fun receiveLocations(): List<LocationValue>? {@@ -160,17 +161,17 @@ object Networking {         return strings.map { decryptLocation(it) }     } -    private suspend fun encryptLocation(location: LocationValue, recipientUserID: ULong, key: RSA.OAEP.PublicKey): LocationSharingData {+    private suspend fun encryptLocation(location: LocationValue, recipientUserID: Long, key: RSA.OAEP.PublicKey): LocationSharingData {         val cipher = key.encryptor()-        val str = Json.encodeToString(location)+        val str = Json.encodeToString(location.toCompatible())         val encryptedData = Base64.encode(cipher.encrypt(str.encodeToByteArray()))-        return LocationSharingData(recipientUserID, encryptedData)+        return LocationSharingData(recipientUserID.toULong(), encryptedData)     }      private suspend fun decryptLocation(encryptedLocation: String): LocationValue {         val cipher = privatekey!!.decryptor()         val decryptedData = cipher.decrypt(Base64.decode(encryptedLocation)).decodeToString()-        return Json.decodeFromString(decryptedData)+        return Json.decodeFromString<LocationValueCompatible>(decryptedData).toLocationValue()     }      suspend fun generateKeyPair(): RSA.OAEP.KeyPair {
findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.ktindex d661d93e8c..3c937202d9 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt@@ -17,4 +17,41 @@ data class LocationValue(     val timestamp: Instant,     val battery: Float,     @PrimaryKey(autoGenerate = true) override val id: Long = 0-): DatabaseItem\ No newline at end of file+): DatabaseItem {+    fun toCompatible(): LocationValueCompatible {+        return LocationValueCompatible(+            userid = userid.toULong(),+            coord = coord,+            speed = speed,+            acc = acc,+            timestamp = timestamp.toEpochMilliseconds(),+            battery = battery,+            sleep = false,+            id = id.toULong()+        )+    }+}++@Serializable+data class LocationValueCompatible(+    val id: ULong = 0uL,+    val userid: ULong,+    val coord: Coord,+    val speed: Float,+    val acc: Float,+    val timestamp: Long,+    val battery: Float,+    val sleep: Boolean? = null+) {+    fun toLocationValue(): LocationValue {+        return LocationValue(+            userid = userid.toLong(),+            coord = coord,+            speed = speed,+            acc = acc,+            timestamp = Instant.fromEpochMilliseconds(timestamp),+            battery = battery,+            id = id.toLong()+        )+    }+}\ No newline at end of file