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.
This commit is contained in:
parent
9aa8c28bef
commit
62c38185e8
2 changed files with 31 additions and 5 deletions
|
|
@ -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<ScheduledEventService>(SERVICE_TOKENS.SCHEDULED_EVENT_SERVICE)
|
||||
const authService = injectService<AuthService>(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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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", "<pubkey>", "<relay-hint>", "<participation-type>"]
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue