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:
parent
62161dd000
commit
2cf737213b
1 changed files with 16 additions and 9 deletions
|
|
@ -194,19 +194,26 @@ export class ScheduledEventService extends BaseService {
|
||||||
*/
|
*/
|
||||||
getTodaysEvents(userPubkey?: string): ScheduledEvent[] {
|
getTodaysEvents(userPubkey?: string): ScheduledEvent[] {
|
||||||
const today = new Date().toISOString().split('T')[0]
|
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
|
// Filter events based on participation (if user pubkey provided)
|
||||||
if (!userPubkey) return events
|
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
|
// Otherwise, only show if user is a participant
|
||||||
return events.filter(event => {
|
return event.participants.some(p => p.pubkey === userPubkey)
|
||||||
// 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
|
// Sort by start time (ascending order)
|
||||||
return event.participants.some(p => p.pubkey === userPubkey)
|
events.sort((a, b) => {
|
||||||
|
// ISO datetime strings can be compared lexicographically
|
||||||
|
return a.start.localeCompare(b.start)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue