commit 0086e19c97d0c4e49f9a6f5a211d6d5bb35f658b
parent adfb581783d74efe456e3b598199b2c49b559ccd
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Tue, 27 Aug 2024 21:48:25 +0200
fix(core/better_location): friend cluster support
Diffstat:
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt
@@ -192,8 +192,8 @@ class ProtoReader(private val buffer: ByteArray) {
@JSFunction
- fun getFixed32(id: Int): Int {
- val bytes = getByteArray(id) ?: return 0
+ fun getFixed32(id: Int): Int? {
+ val bytes = getByteArray(id) ?: return null
var value = 0
for (i in 0..3) {
value = value or ((bytes[i].toInt() and 0xFF) shl (i * 8))
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt
@@ -129,23 +129,33 @@ class BetterLocation : Feature("Better Location") {
private fun onLocationEvent(protoReader: ProtoReader) {
protoReader.eachBuffer(3, 1) {
- val userId = UUID(getFixed64(1, 1) ?: return@eachBuffer, getFixed64(1, 2) ?: return@eachBuffer).toString()
- val friendCluster = FriendLocation(
- userId = userId,
- latitude = Float.fromBits(getFixed32(4)).toDouble(),
- longitude = Float.fromBits(getFixed32(5)).toDouble(),
- lastUpdated = getVarInt(7, 2) ?: -1L,
- locality = getString(10),
- localityPieces = mutableListOf<String>().also {
- forEach { index, wire ->
- if (index != 11) return@forEach
- it.add((wire.value as ByteArray).toString(Charsets.UTF_8) )
- }
- },
- batteryLevel = getFixed32(7, 13)?.let { Float.fromBits(it) } ?: -1F,
- )
+ val clusterId = UUID(getFixed64(1, 1) ?: return@eachBuffer, getFixed64(1, 2) ?: return@eachBuffer).toString()
+
+ val latitude = getFixed32(4)?.let { Float.fromBits(it) }?.toDouble() ?: return@eachBuffer
+ val longitude = getFixed32(5)?.let { Float.fromBits(it) }?.toDouble() ?: return@eachBuffer
+
+ val locality = getString(10)
+ val localityPieces = mutableListOf<String>().also {
+ forEach { index, wire ->
+ if (index != 11) return@forEach
+ it.add((wire.value as ByteArray).toString(Charsets.UTF_8) )
+ }
+ }
- locationHistory[userId] = friendCluster
+ eachBuffer(7) friend@{
+ val userId = if (contains(1)) UUID(getFixed64(1, 1) ?: return@friend, getFixed64(1, 2) ?: return@friend).toString() else clusterId
+ val friendLocation = FriendLocation(
+ userId = userId,
+ latitude = latitude,
+ longitude = longitude,
+ lastUpdated = getVarInt(2) ?: -1L,
+ locality = locality,
+ localityPieces = localityPieces,
+ batteryLevel = getFixed32(13)?.let { Float.fromBits(it) } ?: -1F,
+ )
+
+ locationHistory[userId] = friendLocation
+ }
}
}