Expands the Around me filter to 50km

This commit is contained in:
Vitor Pamplona 2024-12-30 19:57:20 -05:00
parent 54e6be8ef3
commit e1e3a0e6a0
5 changed files with 49 additions and 41 deletions

View File

@ -28,6 +28,7 @@ import androidx.lifecycle.asLiveData
import androidx.lifecycle.liveData
import androidx.lifecycle.switchMap
import com.fasterxml.jackson.module.kotlin.readValue
import com.fonfon.kgeohash.GeoHash
import com.vitorpamplona.amethyst.Amethyst
import com.vitorpamplona.amethyst.BuildConfig
import com.vitorpamplona.amethyst.commons.richtext.RichTextParser
@ -579,6 +580,46 @@ class Account(
}
}
fun compute50kmLine(geoHash: GeoHash): List<String> {
val hashes = mutableListOf<String>()
hashes.add(geoHash.toString())
var currentGeoHash = geoHash
repeat(5) {
currentGeoHash = currentGeoHash.westernNeighbour
hashes.add(currentGeoHash.toString())
}
currentGeoHash = geoHash
repeat(5) {
currentGeoHash = currentGeoHash.easternNeighbour
hashes.add(currentGeoHash.toString())
}
return hashes
}
fun compute50kmRange(geoHash: GeoHash): List<String> {
val hashes = mutableListOf<String>()
hashes.addAll(compute50kmLine(geoHash))
var currentGeoHash = geoHash
repeat(5) {
currentGeoHash = currentGeoHash.northernNeighbour
hashes.addAll(compute50kmLine(currentGeoHash))
}
currentGeoHash = geoHash
repeat(5) {
currentGeoHash = currentGeoHash.southernNeighbour
hashes.addAll(compute50kmLine(currentGeoHash))
}
return hashes
}
suspend fun mapIntoFollowLists(
listName: String,
kind3: LiveFollowList?,
@ -593,16 +634,9 @@ class Account(
val geohashResult = location ?: Amethyst.instance.locationManager.geohashStateFlow.value
if (geohashResult is LocationState.LocationResult.Success) {
// 2 neighbors deep = 25x25km
val hashes =
listOf(geohashResult.geoHash.toString()) +
geohashResult.geoHash.adjacent
.map { listOf(it.toString()) + it.adjacent.map { it.toString() } }
.flatten()
.distinct()
LiveFollowList(
authorsPlusMe = setOf(signer.pubKey),
geotags = hashes.toSet(),
geotags = compute50kmRange(geohashResult.geoHash).toSet(),
)
} else {
LiveFollowList(authorsPlusMe = setOf(signer.pubKey))

View File

@ -124,10 +124,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
kinds = listOf(ClassifiedsEvent.KIND),
tags =
mapOf(
"g" to
it
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
.flatten(),
"g" to it,
),
limit = 300,
since =
@ -304,13 +301,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
filter =
SincePerRelayFilter(
kinds = listOf(LiveActivitiesChatMessageEvent.KIND, LiveActivitiesEvent.KIND),
tags =
mapOf(
"g" to
hashToLoad
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
.flatten(),
),
tags = mapOf("g" to hashToLoad),
limit = 300,
since =
latestEOSEs.users[account.userProfile()]
@ -367,12 +358,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
kinds =
listOf(ChannelCreateEvent.KIND, ChannelMetadataEvent.KIND, ChannelMessageEvent.KIND),
tags =
mapOf(
"g" to
hashToLoad
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
.flatten(),
),
mapOf("g" to hashToLoad),
limit = 300,
since =
latestEOSEs.users[account.userProfile()]
@ -426,13 +412,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
filter =
SincePerRelayFilter(
kinds = listOf(CommunityDefinitionEvent.KIND, CommunityPostApprovalEvent.KIND),
tags =
mapOf(
"g" to
hashToLoad
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
.flatten(),
),
tags = mapOf("g" to hashToLoad),
limit = 300,
since =
latestEOSEs.users[account.userProfile()]

View File

@ -229,10 +229,7 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") {
),
tags =
mapOf(
"g" to
hashToLoad
.map { listOf(it.lowercase()) }
.flatten(),
"g" to hashToLoad.toList(),
),
limit = 100,
since =

View File

@ -160,10 +160,7 @@ object NostrVideoDataSource : AmethystNostrDataSource("VideoFeed") {
if (hashToLoad.isEmpty()) return emptyList()
val geoHashes =
hashToLoad
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
.flatten()
val geoHashes = hashToLoad
return listOf(
TypedFilter(

View File

@ -46,7 +46,7 @@ class FilterByListParams(
fun isEventInList(noteEvent: Event): Boolean {
if (followLists == null) return false
if (isAroundMe && followLists.geotags.isEmpty() == true) return false
if (isAroundMe && followLists.geotags.isEmpty()) return false
return if (noteEvent is LiveActivitiesEvent) {
noteEvent.participantsIntersect(followLists.authors) ||