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 098bff8acc
commit 8381d43268

View file

@ -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
}
/**