From b7c7e4d32da3e4063958b18bf340dc7b45e2072f Mon Sep 17 00:00:00 2001 From: ssmucny Date: Mon, 22 May 2023 22:09:12 -0400 Subject: [PATCH] Add Event schema to metadata - add types from https://schema.org/Event - updated MkEvent to display new fields - minor refactoring --- .../core/activitypub/models/ApEventService.ts | 8 +-- packages/backend/src/models/entities/Event.ts | 43 ++++++++++++- .../api/endpoints/notes/events/search.ts | 2 +- packages/frontend/src/components/MkEvent.vue | 63 ++++++++++++++++++- packages/misskey-js/src/api.types.ts | 2 +- 5 files changed, 106 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApEventService.ts b/packages/backend/src/core/activitypub/models/ApEventService.ts index 81d40a88f6..b525f09ae0 100644 --- a/packages/backend/src/core/activitypub/models/ApEventService.ts +++ b/packages/backend/src/core/activitypub/models/ApEventService.ts @@ -3,13 +3,13 @@ import { DI } from '@/di-symbols.js'; import type { EventsRepository, NotesRepository } from '@/models/index.js'; import type { Config } from '@/config.js'; import type Logger from '@/logger.js'; +import { bindThis } from '@/decorators.js'; +import { IEvent } from '@/models/entities/Event.js'; import { isEvent } from '../type.js'; import { ApLoggerService } from '../ApLoggerService.js'; import { ApResolverService } from '../ApResolverService.js'; import type { Resolver } from '../ApResolverService.js'; import type { IObject } from '../type.js'; -import { bindThis } from '@/decorators.js'; -import { IEvent } from '@/models/entities/Event.js'; @Injectable() export class ApEventService { @@ -32,8 +32,8 @@ export class ApEventService { } @bindThis - public async extractEventFromNote(source: string | IObject, resolver?: Resolver): Promise { - if (resolver == null) resolver = this.apResolverService.createResolver(); + public async extractEventFromNote(source: string | IObject, resolverParam?: Resolver): Promise { + const resolver = resolverParam ?? this.apResolverService.createResolver(); const note = await resolver.resolve(source); diff --git a/packages/backend/src/models/entities/Event.ts b/packages/backend/src/models/entities/Event.ts index 57d2b50543..bad8b5d8ac 100644 --- a/packages/backend/src/models/entities/Event.ts +++ b/packages/backend/src/models/entities/Event.ts @@ -35,13 +35,13 @@ export class Event { public title: string; @Column('jsonb', { - default: { + default: { '@context': 'https://schema.org/', '@type': 'Event', }, comment: 'metadata object describing the event. Follows https://schema.org/Event', }) - public metadata: unknown; + public metadata: EventSchema; //#region Denormalized fields @Column('enum', { @@ -74,9 +74,46 @@ export class Event { } } +export type EventSchema = { + '@context': 'https://schema.org'; + '@type': 'Event'; + name?: string; + url?: string; + description?: string; + audience?: { + '@type': 'Audience'; + name: string; + }; + doorTime?: string; + startDate?: string; + endDate?: string; + eventStatus?: 'https://schema.org/EventCancelled' | 'https://schema.org/EventMovedOnline' | 'https://schema.org/EventPostponed' | 'https://schema.org/EventRescheduled' | 'https://schema.org/EventScheduled'; + inLanguage?: string; + isAccessibleForFree?: boolean; + keywords?: string; + location?: string; + offers?: { + '@type': 'Offer'; + price?: string; + priceCurrency?: string; + availabilityStarts?: string; + availabilityEnds?: string; + url?: string; + }; + organizer?: { + name: string; + sameAs?: string; // ie. URL to website/social + }; + performer?: { + name: string; + sameAs?: string; // ie. URL to website/social + }[]; + typicalAgeRange?: string; +} + export type IEvent = { start: Date; end: Date | null title: string; - metadata: Record; + metadata: EventSchema; } diff --git a/packages/backend/src/server/api/endpoints/notes/events/search.ts b/packages/backend/src/server/api/endpoints/notes/events/search.ts index dfc614039c..737867b1ef 100644 --- a/packages/backend/src/server/api/endpoints/notes/events/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/events/search.ts @@ -67,7 +67,7 @@ export const paramDef = { }, } as const; -function notAlphaNumeric(s: string) { +function notAlphaNumeric(s: string): boolean { return null !== s.match(/[^\w]/); } diff --git a/packages/frontend/src/components/MkEvent.vue b/packages/frontend/src/components/MkEvent.vue index 3b445ce1b5..a3dd01e796 100644 --- a/packages/frontend/src/components/MkEvent.vue +++ b/packages/frontend/src/components/MkEvent.vue @@ -15,9 +15,66 @@ -