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.
This commit is contained in:
padreug 2025-10-22 00:27:22 +02:00
parent 62161dd000
commit 2cf737213b

View file

@ -194,13 +194,11 @@ 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
return events.filter(event => {
// 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
@ -209,6 +207,15 @@ export class ScheduledEventService extends BaseService {
})
}
// 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
}
/**
* Get completion status for an event
*/