From 667a7c2d893f6a765d90f95928ecf01f3753e3e6 Mon Sep 17 00:00:00 2001 From: padreug Date: Wed, 17 Sep 2025 02:06:57 +0200 Subject: [PATCH] Add rideshare content filter and enhance FeedService filtering logic - Introduced a new rideshare content filter in content-filters.ts, allowing for the categorization of rideshare requests and offers. - Updated the FeedService to support filtering by tags and keywords, enhancing the ability to search and filter content based on user-defined criteria. - Modified Home.vue to include the new rideshare filter preset, improving user access to rideshare-related content. These changes enhance the content filtering capabilities and user experience within the NostrFeed module. --- .../nostr-feed/config/content-filters.ts | 14 ++++++++ .../nostr-feed/services/FeedService.ts | 35 +++++++++++++++++-- src/pages/Home.vue | 3 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/modules/nostr-feed/config/content-filters.ts b/src/modules/nostr-feed/config/content-filters.ts index 4cbfb84..ba3bd04 100644 --- a/src/modules/nostr-feed/config/content-filters.ts +++ b/src/modules/nostr-feed/config/content-filters.ts @@ -99,6 +99,16 @@ export const CONTENT_FILTERS: Record = { label: 'Live Events', kinds: [30311], // NIP-53: Live Events description: 'Live streaming and real-time events' + }, + + // Rideshare content + rideshare: { + id: 'rideshare', + label: 'Rideshare', + kinds: [1, 31001], // Text notes + custom rideshare events + description: 'Rideshare requests, offers, and coordination', + tags: ['rideshare', 'uber', 'lyft', 'carpool', 'taxi', 'ride'], // NIP-12 tags + keywords: ['rideshare', 'ride share', 'carpool', 'uber', 'lyft', 'taxi', 'pickup', 'dropoff'] } } @@ -148,6 +158,10 @@ export const FILTER_PRESETS: Record = { content: [ CONTENT_FILTERS.longFormContent, CONTENT_FILTERS.textNotes + ], + + rideshare: [ + CONTENT_FILTERS.rideshare ] } diff --git a/src/modules/nostr-feed/services/FeedService.ts b/src/modules/nostr-feed/services/FeedService.ts index e6f0e29..1ae3286 100644 --- a/src/modules/nostr-feed/services/FeedService.ts +++ b/src/modules/nostr-feed/services/FeedService.ts @@ -23,6 +23,8 @@ export interface ContentFilter { description: string requiresAuth?: boolean filterByAuthor?: 'admin' | 'exclude-admin' | 'none' + tags?: string[] // NIP-12 tags to filter by + keywords?: string[] // Content keywords to search for } export interface FeedConfig { @@ -147,6 +149,11 @@ export class FeedService extends BaseService { // Will exclude admin in post-processing } + // Apply tag filtering if specified (NIP-12) + if (contentFilter.tags && contentFilter.tags.length > 0) { + filter['#t'] = contentFilter.tags + } + filters.push(filter) } } else { @@ -294,10 +301,34 @@ export class FeedService extends BaseService { // Apply author filtering if (filter.filterByAuthor === 'admin') { console.log('FeedService: Admin filter, isAdminPost:', isAdminPost) - return isAdminPost + if (!isAdminPost) return false } else if (filter.filterByAuthor === 'exclude-admin') { console.log('FeedService: Exclude admin filter, isAdminPost:', isAdminPost) - return !isAdminPost + if (isAdminPost) return false + } + + // Apply keyword filtering if specified + if (filter.keywords && filter.keywords.length > 0) { + const content = event.content.toLowerCase() + const hasMatchingKeyword = filter.keywords.some(keyword => + content.includes(keyword.toLowerCase()) + ) + if (!hasMatchingKeyword) { + console.log('FeedService: No matching keywords found') + return false + } + } + + // Apply tag filtering if specified (check if event has any matching tags) + if (filter.tags && filter.tags.length > 0) { + const eventTags = event.tags?.filter(tag => tag[0] === 't').map(tag => tag[1]) || [] + const hasMatchingTag = filter.tags.some(filterTag => + eventTags.includes(filterTag) + ) + if (!hasMatchingTag) { + console.log('FeedService: No matching tags found') + return false + } } console.log('FeedService: Filter passed all checks') diff --git a/src/pages/Home.vue b/src/pages/Home.vue index f7b845b..f394312 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -126,7 +126,8 @@ const quickFilterPresets = { all: { label: 'All', filters: FILTER_PRESETS.all }, announcements: { label: 'News', filters: FILTER_PRESETS.announcements }, social: { label: 'Social', filters: FILTER_PRESETS.social }, - events: { label: 'Events', filters: FILTER_PRESETS.events } + events: { label: 'Events', filters: FILTER_PRESETS.events }, + rideshare: { label: 'Rideshare', filters: FILTER_PRESETS.rideshare } } // Computed properties