mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-28 18:51:45 +01:00
Expands the Around me filter to 50km
This commit is contained in:
parent
54e6be8ef3
commit
e1e3a0e6a0
@ -28,6 +28,7 @@ import androidx.lifecycle.asLiveData
|
|||||||
import androidx.lifecycle.liveData
|
import androidx.lifecycle.liveData
|
||||||
import androidx.lifecycle.switchMap
|
import androidx.lifecycle.switchMap
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import com.fonfon.kgeohash.GeoHash
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
import com.vitorpamplona.amethyst.Amethyst
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.commons.richtext.RichTextParser
|
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(
|
suspend fun mapIntoFollowLists(
|
||||||
listName: String,
|
listName: String,
|
||||||
kind3: LiveFollowList?,
|
kind3: LiveFollowList?,
|
||||||
@ -593,16 +634,9 @@ class Account(
|
|||||||
val geohashResult = location ?: Amethyst.instance.locationManager.geohashStateFlow.value
|
val geohashResult = location ?: Amethyst.instance.locationManager.geohashStateFlow.value
|
||||||
if (geohashResult is LocationState.LocationResult.Success) {
|
if (geohashResult is LocationState.LocationResult.Success) {
|
||||||
// 2 neighbors deep = 25x25km
|
// 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(
|
LiveFollowList(
|
||||||
authorsPlusMe = setOf(signer.pubKey),
|
authorsPlusMe = setOf(signer.pubKey),
|
||||||
geotags = hashes.toSet(),
|
geotags = compute50kmRange(geohashResult.geoHash).toSet(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LiveFollowList(authorsPlusMe = setOf(signer.pubKey))
|
LiveFollowList(authorsPlusMe = setOf(signer.pubKey))
|
||||||
|
@ -124,10 +124,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
|
|||||||
kinds = listOf(ClassifiedsEvent.KIND),
|
kinds = listOf(ClassifiedsEvent.KIND),
|
||||||
tags =
|
tags =
|
||||||
mapOf(
|
mapOf(
|
||||||
"g" to
|
"g" to it,
|
||||||
it
|
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
|
||||||
.flatten(),
|
|
||||||
),
|
),
|
||||||
limit = 300,
|
limit = 300,
|
||||||
since =
|
since =
|
||||||
@ -304,13 +301,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
|
|||||||
filter =
|
filter =
|
||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(LiveActivitiesChatMessageEvent.KIND, LiveActivitiesEvent.KIND),
|
kinds = listOf(LiveActivitiesChatMessageEvent.KIND, LiveActivitiesEvent.KIND),
|
||||||
tags =
|
tags = mapOf("g" to hashToLoad),
|
||||||
mapOf(
|
|
||||||
"g" to
|
|
||||||
hashToLoad
|
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
|
||||||
.flatten(),
|
|
||||||
),
|
|
||||||
limit = 300,
|
limit = 300,
|
||||||
since =
|
since =
|
||||||
latestEOSEs.users[account.userProfile()]
|
latestEOSEs.users[account.userProfile()]
|
||||||
@ -367,12 +358,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
|
|||||||
kinds =
|
kinds =
|
||||||
listOf(ChannelCreateEvent.KIND, ChannelMetadataEvent.KIND, ChannelMessageEvent.KIND),
|
listOf(ChannelCreateEvent.KIND, ChannelMetadataEvent.KIND, ChannelMessageEvent.KIND),
|
||||||
tags =
|
tags =
|
||||||
mapOf(
|
mapOf("g" to hashToLoad),
|
||||||
"g" to
|
|
||||||
hashToLoad
|
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
|
||||||
.flatten(),
|
|
||||||
),
|
|
||||||
limit = 300,
|
limit = 300,
|
||||||
since =
|
since =
|
||||||
latestEOSEs.users[account.userProfile()]
|
latestEOSEs.users[account.userProfile()]
|
||||||
@ -426,13 +412,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
|
|||||||
filter =
|
filter =
|
||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(CommunityDefinitionEvent.KIND, CommunityPostApprovalEvent.KIND),
|
kinds = listOf(CommunityDefinitionEvent.KIND, CommunityPostApprovalEvent.KIND),
|
||||||
tags =
|
tags = mapOf("g" to hashToLoad),
|
||||||
mapOf(
|
|
||||||
"g" to
|
|
||||||
hashToLoad
|
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
|
||||||
.flatten(),
|
|
||||||
),
|
|
||||||
limit = 300,
|
limit = 300,
|
||||||
since =
|
since =
|
||||||
latestEOSEs.users[account.userProfile()]
|
latestEOSEs.users[account.userProfile()]
|
||||||
|
@ -229,10 +229,7 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") {
|
|||||||
),
|
),
|
||||||
tags =
|
tags =
|
||||||
mapOf(
|
mapOf(
|
||||||
"g" to
|
"g" to hashToLoad.toList(),
|
||||||
hashToLoad
|
|
||||||
.map { listOf(it.lowercase()) }
|
|
||||||
.flatten(),
|
|
||||||
),
|
),
|
||||||
limit = 100,
|
limit = 100,
|
||||||
since =
|
since =
|
||||||
|
@ -160,10 +160,7 @@ object NostrVideoDataSource : AmethystNostrDataSource("VideoFeed") {
|
|||||||
|
|
||||||
if (hashToLoad.isEmpty()) return emptyList()
|
if (hashToLoad.isEmpty()) return emptyList()
|
||||||
|
|
||||||
val geoHashes =
|
val geoHashes = hashToLoad
|
||||||
hashToLoad
|
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
|
||||||
.flatten()
|
|
||||||
|
|
||||||
return listOf(
|
return listOf(
|
||||||
TypedFilter(
|
TypedFilter(
|
||||||
|
@ -46,7 +46,7 @@ class FilterByListParams(
|
|||||||
|
|
||||||
fun isEventInList(noteEvent: Event): Boolean {
|
fun isEventInList(noteEvent: Event): Boolean {
|
||||||
if (followLists == null) return false
|
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) {
|
return if (noteEvent is LiveActivitiesEvent) {
|
||||||
noteEvent.participantsIntersect(followLists.authors) ||
|
noteEvent.participantsIntersect(followLists.authors) ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user