Adds protections against filters with empty arrays because some relays consider that null as opposed to empty.

This commit is contained in:
Vitor Pamplona
2024-08-09 18:13:19 -04:00
parent 312501e527
commit 939c8e95b0
4 changed files with 39 additions and 28 deletions

View File

@@ -35,15 +35,19 @@ object NostrCommunityDataSource : AmethystNostrDataSource("SingleCommunityFeed")
val community = myCommunityToWatch.event as? CommunityDefinitionEvent ?: return null val community = myCommunityToWatch.event as? CommunityDefinitionEvent ?: return null
val authors =
community
.moderators()
.map { it.key }
.plus(listOfNotNull(myCommunityToWatch.author?.pubkeyHex))
if (authors.isEmpty()) return null
return TypedFilter( return TypedFilter(
types = COMMON_FEED_TYPES, types = COMMON_FEED_TYPES,
filter = filter =
SincePerRelayFilter( SincePerRelayFilter(
authors = authors = authors,
community
.moderators()
.map { it.key }
.plus(listOfNotNull(myCommunityToWatch.author?.pubkeyHex)),
tags = tags =
mapOf( mapOf(
"a" to listOf(myCommunityToWatch.address.toTag()), "a" to listOf(myCommunityToWatch.address.toTag()),

View File

@@ -67,15 +67,17 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
} }
fun createMarketplaceFilter(): List<TypedFilter> { fun createMarketplaceFilter(): List<TypedFilter> {
val follows = account.liveDiscoveryListAuthorsPerRelay.value val follows = account.liveDiscoveryListAuthorsPerRelay.value?.ifEmpty { null }
val hashToLoad = val hashToLoad =
account.liveDiscoveryFollowLists.value account.liveDiscoveryFollowLists.value
?.hashtags ?.hashtags
?.toList() ?.toList()
?.ifEmpty { null }
val geohashToLoad = val geohashToLoad =
account.liveDiscoveryFollowLists.value account.liveDiscoveryFollowLists.value
?.geotags ?.geotags
?.toList() ?.toList()
?.ifEmpty { null }
return listOfNotNull( return listOfNotNull(
TypedFilter( TypedFilter(
@@ -162,6 +164,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
account.liveDiscoveryFollowLists.value account.liveDiscoveryFollowLists.value
?.users ?.users
?.toList() ?.toList()
?.ifEmpty { null }
val followsRelays = account.liveDiscoveryListAuthorsPerRelay.value val followsRelays = account.liveDiscoveryListAuthorsPerRelay.value
@@ -200,7 +203,7 @@ object NostrDiscoveryDataSource : AmethystNostrDataSource("DiscoveryFeed") {
} }
fun createPublicChatFilter(): List<TypedFilter> { fun createPublicChatFilter(): List<TypedFilter> {
val follows = account.liveDiscoveryListAuthorsPerRelay.value val follows = account.liveDiscoveryListAuthorsPerRelay.value?.ifEmpty { null }
val followChats = account.selectedChatsFollowList().toList() val followChats = account.selectedChatsFollowList().toList()
return listOfNotNull( return listOfNotNull(

View File

@@ -114,7 +114,7 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") {
fun createFollowMetadataAndReleaseFilter(): TypedFilter? { fun createFollowMetadataAndReleaseFilter(): TypedFilter? {
val follows = account.liveHomeListAuthorsPerRelay.value val follows = account.liveHomeListAuthorsPerRelay.value
return if (follows != null) { return if (!follows.isNullOrEmpty()) {
TypedFilter( TypedFilter(
types = setOf(FeedType.FOLLOWS), types = setOf(FeedType.FOLLOWS),
filter = filter =

View File

@@ -65,26 +65,30 @@ object NostrSingleUserDataSource : AmethystNostrDataSource("SingleUserFeed") {
val groupIds = group.map { it.pubkeyHex } val groupIds = group.map { it.pubkeyHex }
val minEOSEs = findMinimumEOSEsForUsers(group) val minEOSEs = findMinimumEOSEsForUsers(group)
listOf( if (groupIds.isNotEmpty()) {
TypedFilter( listOf(
types = EVENT_FINDER_TYPES, TypedFilter(
filter = types = EVENT_FINDER_TYPES,
SincePerRelayFilter( filter =
kinds = listOf(MetadataEvent.KIND, StatusEvent.KIND, AdvertisedRelayListEvent.KIND, ChatMessageRelayListEvent.KIND), SincePerRelayFilter(
authors = groupIds, kinds = listOf(MetadataEvent.KIND, StatusEvent.KIND, AdvertisedRelayListEvent.KIND, ChatMessageRelayListEvent.KIND),
since = minEOSEs, authors = groupIds,
), since = minEOSEs,
), ),
TypedFilter( ),
types = EVENT_FINDER_TYPES, TypedFilter(
filter = types = EVENT_FINDER_TYPES,
SincePerRelayFilter( filter =
kinds = listOf(ReportEvent.KIND), SincePerRelayFilter(
tags = mapOf("p" to groupIds), kinds = listOf(ReportEvent.KIND),
since = minEOSEs, tags = mapOf("p" to groupIds),
), since = minEOSEs,
), ),
) ),
)
} else {
listOf()
}
}.flatten() }.flatten()
} }