From 2cf737213bb41c5049273c30dc3a9885f9052ddf Mon Sep 17 00:00:00 2001 From: padreug Date: Wed, 22 Oct 2025 00:27:22 +0200 Subject: [PATCH] Filters and sorts scheduled events Improves scheduled event retrieval by filtering events based on user participation and sorting them by start time. This ensures that users only see events they are participating in or events that are open to the entire community. --- .../services/ScheduledEventService.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/modules/nostr-feed/services/ScheduledEventService.ts b/src/modules/nostr-feed/services/ScheduledEventService.ts index 3b64c5a..6215e4b 100644 --- a/src/modules/nostr-feed/services/ScheduledEventService.ts +++ b/src/modules/nostr-feed/services/ScheduledEventService.ts @@ -194,19 +194,26 @@ export class ScheduledEventService extends BaseService { */ getTodaysEvents(userPubkey?: string): ScheduledEvent[] { const today = new Date().toISOString().split('T')[0] - const events = this.getEventsForDate(today) + let events = this.getEventsForDate(today) - // If no user pubkey provided, return all events - if (!userPubkey) return events + // Filter events based on participation (if user pubkey provided) + if (userPubkey) { + events = events.filter(event => { + // If event has no participants, it's community-wide (show to everyone) + if (!event.participants || event.participants.length === 0) return true - // 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) + }) + } - // Otherwise, only show if user is a participant - return event.participants.some(p => p.pubkey === userPubkey) + // Sort by start time (ascending order) + events.sort((a, b) => { + // ISO datetime strings can be compared lexicographically + return a.start.localeCompare(b.start) }) + + return events } /**