From 62c38185e89f71c62cde1d2f10bcedef809468d4 Mon Sep 17 00:00:00 2001 From: padreug Date: Tue, 21 Oct 2025 23:41:37 +0200 Subject: [PATCH] Filters scheduled events by participation Ensures users only see scheduled events they are participating in or events that are open to everyone. This change filters the list of today's scheduled events based on the current user's participation. It only displays events where the user is listed as a participant or events that do not have any participants specified. --- .../composables/useScheduledEvents.ts | 9 +++++-- .../services/ScheduledEventService.ts | 27 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/modules/nostr-feed/composables/useScheduledEvents.ts b/src/modules/nostr-feed/composables/useScheduledEvents.ts index ae79702..42552c7 100644 --- a/src/modules/nostr-feed/composables/useScheduledEvents.ts +++ b/src/modules/nostr-feed/composables/useScheduledEvents.ts @@ -1,6 +1,7 @@ import { computed } from 'vue' import { injectService, SERVICE_TOKENS } from '@/core/di-container' import type { ScheduledEventService, ScheduledEvent, EventCompletion } from '../services/ScheduledEventService' +import type { AuthService } from '@/modules/base/auth/auth-service' import { useToast } from '@/core/composables/useToast' /** @@ -8,8 +9,12 @@ import { useToast } from '@/core/composables/useToast' */ export function useScheduledEvents() { const scheduledEventService = injectService(SERVICE_TOKENS.SCHEDULED_EVENT_SERVICE) + const authService = injectService(SERVICE_TOKENS.AUTH_SERVICE) const toast = useToast() + // Get current user's pubkey + const currentUserPubkey = computed(() => authService?.user.value?.pubkey) + /** * Get all scheduled events */ @@ -27,11 +32,11 @@ export function useScheduledEvents() { } /** - * Get today's scheduled events + * Get today's scheduled events (filtered by current user participation) */ const getTodaysEvents = (): ScheduledEvent[] => { if (!scheduledEventService) return [] - return scheduledEventService.getTodaysEvents() + return scheduledEventService.getTodaysEvents(currentUserPubkey.value) } /** diff --git a/src/modules/nostr-feed/services/ScheduledEventService.ts b/src/modules/nostr-feed/services/ScheduledEventService.ts index 19bda58..3b64c5a 100644 --- a/src/modules/nostr-feed/services/ScheduledEventService.ts +++ b/src/modules/nostr-feed/services/ScheduledEventService.ts @@ -16,6 +16,7 @@ export interface ScheduledEvent { location?: string status: string eventType?: string // 'task' for completable events, 'announcement' for informational + participants?: Array<{ pubkey: string; type?: string }> // 'required', 'optional', 'organizer' content: string tags: string[][] } @@ -79,6 +80,13 @@ export class ScheduledEventService extends BaseService { const status = event.tags.find(tag => tag[0] === 'status')?.[1] || 'pending' const eventType = event.tags.find(tag => tag[0] === 'event-type')?.[1] + // Parse participant tags: ["p", "", "", ""] + const participantTags = event.tags.filter(tag => tag[0] === 'p') + const participants = participantTags.map(tag => ({ + pubkey: tag[1], + type: tag[3] // 'required', 'optional', 'organizer' + })) + if (!start) { console.warn('Scheduled event missing start date:', event.id) return @@ -99,6 +107,7 @@ export class ScheduledEventService extends BaseService { location, status, eventType, + participants: participants.length > 0 ? participants : undefined, content: event.content, tags: event.tags } @@ -181,11 +190,23 @@ export class ScheduledEventService extends BaseService { } /** - * Get events for today + * Get events for today, optionally filtered by user participation */ - getTodaysEvents(): ScheduledEvent[] { + getTodaysEvents(userPubkey?: string): ScheduledEvent[] { const today = new Date().toISOString().split('T')[0] - return this.getEventsForDate(today) + const events = this.getEventsForDate(today) + + // If no user pubkey provided, return all events + if (!userPubkey) return events + + // Filter events based on participation + return events.filter(event => { + // If event has no participants, it's community-wide (show to everyone) + if (!event.participants || event.participants.length === 0) return true + + // Otherwise, only show if user is a participant + return event.participants.some(p => p.pubkey === userPubkey) + }) } /**