From e6a10e07c41828ba122d027d367c35769fc53e87 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 13 Nov 2025 10:50:13 -0500 Subject: [PATCH] Correctly adding relays to the filters so that the Global feed can filter only events that came from the relays listed in the Global filter. --- .../amethyst/ui/dal/FilterByListParams.kt | 4 ++-- .../nip23LongForm/DiscoverLongFormFeedFilter.kt | 4 ++-- .../discover/nip28Chats/DiscoverChatFeedFilter.kt | 6 +++--- .../nip51FollowSets/DiscoverFollowSetsFeedFilter.kt | 4 ++-- .../nip53LiveActivities/DiscoverLiveFeedFilter.kt | 2 +- .../nip72Communities/DiscoverCommunityFeedFilter.kt | 6 +++--- .../discover/nip90DVMs/DiscoverNIP89FeedFilter.kt | 10 +++++++--- .../nip99Classifieds/DiscoverMarketplaceFeedFilter.kt | 4 ++-- .../feed/dal/FollowPackFeedConversationsFeedFilter.kt | 6 ++++-- .../loggedIn/home/dal/HomeConversationsFeedFilter.kt | 6 ++++-- .../gallery/dal/UserProfileGalleryFeedFilter.kt | 2 +- .../ui/screen/loggedIn/video/dal/VideoFeedFilter.kt | 2 +- 12 files changed, 32 insertions(+), 24 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt index accd8d685..d7b26ea33 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt @@ -67,14 +67,14 @@ class FilterByListParams( fun match( noteEvent: Event, - comingFrom: List = emptyList(), + comingFrom: List, ) = ((isGlobal(comingFrom)) || isEventInList(noteEvent)) && (isHiddenList || isNotHidden(noteEvent.pubKey)) && isNotInTheFuture(noteEvent) fun match( address: Address?, - comingFrom: List = emptyList(), + comingFrom: List, ) = address != null && (isGlobal(comingFrom) || isAuthorInFollows(address)) && (isHiddenList || isNotHidden(address.pubKeyHex)) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/DiscoverLongFormFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/DiscoverLongFormFeedFilter.kt index ff1110fac..1e9464341 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/DiscoverLongFormFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/DiscoverLongFormFeedFilter.kt @@ -49,7 +49,7 @@ open class DiscoverLongFormFeedFilter( val notes = LocalCache.addressables.filterIntoSet(LongTextNoteEvent.KIND) { _, it -> val noteEvent = it.event - noteEvent is LongTextNoteEvent && params.match(noteEvent) + noteEvent is LongTextNoteEvent && params.match(noteEvent, it.relays) } return sort(notes) } @@ -67,7 +67,7 @@ open class DiscoverLongFormFeedFilter( return collection.filterTo(HashSet()) { val noteEvent = it.event - noteEvent is LongTextNoteEvent && params.match(noteEvent) + noteEvent is LongTextNoteEvent && params.match(noteEvent, it.relays) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt index c3b6a5da7..745f31a8c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt @@ -51,7 +51,7 @@ open class DiscoverChatFeedFilter( val note = LocalCache.getNoteIfExists(channel.idHex) val noteEvent = note?.event - if (noteEvent == null || params.match(noteEvent)) { + if (noteEvent == null || params.match(noteEvent, note.relays)) { note } else { null @@ -75,7 +75,7 @@ open class DiscoverChatFeedFilter( return collection.mapNotNullTo(HashSet()) { note -> // note event here will never be null val noteEvent = note.event - if (noteEvent is ChannelCreateEvent && params.match(noteEvent)) { + if (noteEvent is ChannelCreateEvent && params.match(noteEvent, note.relays)) { if ((LocalCache.getPublicChatChannelIfExists(noteEvent.id)?.notes?.size() ?: 0) > 0) { note } else { @@ -86,7 +86,7 @@ open class DiscoverChatFeedFilter( val channelEvent = channel?.event if (channel != null && - (channelEvent == null || (channelEvent is ChannelCreateEvent && params.match(channelEvent))) + (channelEvent == null || (channelEvent is ChannelCreateEvent && params.match(channelEvent, note.relays))) ) { if ((LocalCache.getPublicChatChannelIfExists(channel.idHex)?.notes?.size() ?: 0) > 0) { channel diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip51FollowSets/DiscoverFollowSetsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip51FollowSets/DiscoverFollowSetsFeedFilter.kt index a6fc6c050..0f29d1b81 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip51FollowSets/DiscoverFollowSetsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip51FollowSets/DiscoverFollowSetsFeedFilter.kt @@ -48,7 +48,7 @@ open class DiscoverFollowSetsFeedFilter( val notes = LocalCache.addressables.filterIntoSet(FollowListEvent.KIND) { _, it -> val noteEvent = it.event - noteEvent is FollowListEvent && params.match(noteEvent) + noteEvent is FollowListEvent && params.match(noteEvent, it.relays) } return sort(notes) @@ -67,7 +67,7 @@ open class DiscoverFollowSetsFeedFilter( return collection.filterTo(HashSet()) { val noteEvent = it.event - noteEvent is FollowListEvent && params.match(noteEvent) + noteEvent is FollowListEvent && params.match(noteEvent, it.relays) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt index 2b1d0720c..856de6e36 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt @@ -72,7 +72,7 @@ open class DiscoverLiveFeedFilter( return collection.filterTo(HashSet()) { val noteEvent = it.event - noteEvent is LiveActivitiesEvent && filterParams.match(noteEvent) + noteEvent is LiveActivitiesEvent && filterParams.match(noteEvent, it.relays) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt index e0648c72f..9ab2c6f8b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt @@ -60,7 +60,7 @@ open class DiscoverCommunityFeedFilter( if (noteEvent == null && shouldInclude(key, filterParams, note.relays)) { // send unloaded communities to the screen note - } else if (noteEvent is CommunityDefinitionEvent && filterParams.match(noteEvent)) { + } else if (noteEvent is CommunityDefinitionEvent && filterParams.match(noteEvent, note.relays)) { note } else { null @@ -84,7 +84,7 @@ open class DiscoverCommunityFeedFilter( .mapNotNull { note -> // note event here will never be null val noteEvent = note.event - if (noteEvent is CommunityDefinitionEvent && filterParams.match(noteEvent)) { + if (noteEvent is CommunityDefinitionEvent && filterParams.match(noteEvent, note.relays)) { listOf(note) } else if (noteEvent is CommunityPostApprovalEvent) { noteEvent.communityAddresses().mapNotNull { @@ -93,7 +93,7 @@ open class DiscoverCommunityFeedFilter( if (definitionEvent == null && shouldInclude(it, filterParams, definitionNote.relays)) { definitionNote - } else if (definitionEvent is CommunityDefinitionEvent && filterParams.match(definitionEvent)) { + } else if (definitionEvent is CommunityDefinitionEvent && filterParams.match(definitionEvent, definitionNote.relays)) { definitionNote } else { null diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt index 276a55743..5c3e8ef37 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt @@ -34,6 +34,7 @@ import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.muted.MutedAuthors import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.muted.MutedAuthorsByProxyTopNavFilter import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter import com.vitorpamplona.amethyst.ui.dal.FilterByListParams +import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip51Lists.muteList.MuteListEvent import com.vitorpamplona.quartz.nip51Lists.peopleList.PeopleListEvent import com.vitorpamplona.quartz.nip89AppHandlers.definition.AppDefinitionEvent @@ -74,16 +75,19 @@ open class DiscoverNIP89FeedFilter( fun acceptDVM(note: Note): Boolean { val noteEvent = note.event return if (noteEvent is AppDefinitionEvent) { - acceptDVM(noteEvent) + acceptDVM(noteEvent, note.relays) } else { false } } - fun acceptDVM(noteEvent: AppDefinitionEvent): Boolean { + fun acceptDVM( + noteEvent: AppDefinitionEvent, + relays: List, + ): Boolean { val filterParams = buildFilterParams(account) return noteEvent.appMetaData()?.subscription != true && - filterParams.match(noteEvent) && + filterParams.match(noteEvent, relays) && noteEvent.includeKind(5300) && noteEvent.createdAt > lastAnnounced // && params.match(noteEvent) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/DiscoverMarketplaceFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/DiscoverMarketplaceFeedFilter.kt index a4c16b9e3..65b26e890 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/DiscoverMarketplaceFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/DiscoverMarketplaceFeedFilter.kt @@ -49,7 +49,7 @@ open class DiscoverMarketplaceFeedFilter( val notes = LocalCache.addressables.filterIntoSet(ClassifiedsEvent.KIND) { _, it -> val noteEvent = it.event - noteEvent is ClassifiedsEvent && noteEvent.isWellFormed() && params.match(noteEvent) + noteEvent is ClassifiedsEvent && noteEvent.isWellFormed() && params.match(noteEvent, it.relays) } return sort(notes) @@ -68,7 +68,7 @@ open class DiscoverMarketplaceFeedFilter( return collection.filterTo(HashSet()) { val noteEvent = it.event - noteEvent is ClassifiedsEvent && noteEvent.isWellFormed() && params.match(noteEvent) + noteEvent is ClassifiedsEvent && noteEvent.isWellFormed() && params.match(noteEvent, it.relays) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/followPacks/feed/dal/FollowPackFeedConversationsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/followPacks/feed/dal/FollowPackFeedConversationsFeedFilter.kt index 8d5e34deb..4895b9f7b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/followPacks/feed/dal/FollowPackFeedConversationsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/followPacks/feed/dal/FollowPackFeedConversationsFeedFilter.kt @@ -34,6 +34,7 @@ import com.vitorpamplona.amethyst.ui.dal.FilterByListParams import com.vitorpamplona.quartz.experimental.publicMessages.PublicMessageEvent import com.vitorpamplona.quartz.experimental.zapPolls.PollNoteEvent import com.vitorpamplona.quartz.nip01Core.core.Event +import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent import com.vitorpamplona.quartz.nip22Comments.CommentEvent import com.vitorpamplona.quartz.nip28PublicChat.message.ChannelMessageEvent @@ -96,6 +97,7 @@ class FollowPackFeedConversationsFeedFilter( fun acceptableEvent( event: Event?, + relays: List, filterParams: FilterByListParams, ): Boolean = ( @@ -107,12 +109,12 @@ class FollowPackFeedConversationsFeedFilter( event is PublicMessageEvent || event is LiveActivitiesChatMessageEvent ) && - filterParams.match(event) + filterParams.match(event, relays) fun acceptableEvent( note: Note, filterParams: FilterByListParams, - ): Boolean = acceptableEvent(note.event, filterParams) && !note.isNewThread() + ): Boolean = acceptableEvent(note.event, note.relays, filterParams) && !note.isNewThread() override fun sort(items: Set): List = items.sortedWith(DefaultFeedOrder) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeConversationsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeConversationsFeedFilter.kt index 441404d44..ad9757837 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeConversationsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeConversationsFeedFilter.kt @@ -31,6 +31,7 @@ import com.vitorpamplona.amethyst.ui.dal.FilterByListParams import com.vitorpamplona.quartz.experimental.publicMessages.PublicMessageEvent import com.vitorpamplona.quartz.experimental.zapPolls.PollNoteEvent import com.vitorpamplona.quartz.nip01Core.core.Event +import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent import com.vitorpamplona.quartz.nip22Comments.CommentEvent import com.vitorpamplona.quartz.nip28PublicChat.message.ChannelMessageEvent @@ -74,6 +75,7 @@ class HomeConversationsFeedFilter( fun acceptableEvent( event: Event?, + relays: List, filterParams: FilterByListParams, ): Boolean = ( @@ -85,12 +87,12 @@ class HomeConversationsFeedFilter( event is PublicMessageEvent || event is LiveActivitiesChatMessageEvent ) && - filterParams.match(event) + filterParams.match(event, relays) fun acceptableEvent( note: Note, filterParams: FilterByListParams, - ): Boolean = acceptableEvent(note.event, filterParams) && !note.isNewThread() + ): Boolean = acceptableEvent(note.event, note.relays, filterParams) && !note.isNewThread() override fun sort(items: Set): List = items.sortedWith(DefaultFeedOrder) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/dal/UserProfileGalleryFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/dal/UserProfileGalleryFeedFilter.kt index 95c41aae5..63955e745 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/dal/UserProfileGalleryFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/dal/UserProfileGalleryFeedFilter.kt @@ -72,7 +72,7 @@ class UserProfileGalleryFeedFilter( return ( (it.event?.pubKey == user.pubkeyHex && (noteEvent is PictureEvent || noteEvent is VideoEvent || (noteEvent is ProfileGalleryEntryEvent) && noteEvent.hasUrl() && noteEvent.hasFromEvent())) // && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET)) ) && - params.match(noteEvent) && + params.match(noteEvent, it.relays) && account.isAcceptable(it) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/dal/VideoFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/dal/VideoFeedFilter.kt index 129fe777d..6646dac18 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/dal/VideoFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/dal/VideoFeedFilter.kt @@ -126,7 +126,7 @@ class VideoFeedFilter( (noteEvent is FileStorageHeaderEvent && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET)) || (noteEvent is PictureEvent && acceptanceEvent(noteEvent)) ) && - params.match(noteEvent) && + params.match(noteEvent, note.relays) && (params.isHiddenList || account.isAcceptable(note)) }