From 4df0407a28f2324bc2b22d468f9cda76bee66f6f Mon Sep 17 00:00:00 2001 From: ssmucny Date: Fri, 21 Apr 2023 19:13:37 -0400 Subject: [PATCH] Add event to AP publishing --- .../src/core/activitypub/ApRendererService.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 0b22aa9bcf..111e34cc61 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -19,7 +19,7 @@ import { MfmService } from '@/core/MfmService.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import type { UserKeypair } from '@/models/entities/UserKeypair.js'; -import type { UsersRepository, UserProfilesRepository, NotesRepository, DriveFilesRepository, EmojisRepository, PollsRepository } from '@/models/index.js'; +import type { UsersRepository, UserProfilesRepository, NotesRepository, DriveFilesRepository, EmojisRepository, PollsRepository, EventsRepository } from '@/models/index.js'; import { bindThis } from '@/decorators.js'; import { CustomEmojiService } from '@/core/CustomEmojiService.js'; import { isNotNull } from '@/misc/is-not-null.js'; @@ -52,6 +52,9 @@ export class ApRendererService { @Inject(DI.pollsRepository) private pollsRepository: PollsRepository, + @Inject(DI.eventsRepository) + private eventsRepository: EventsRepository, + private customEmojiService: CustomEmojiService, private userEntityService: UserEntityService, private driveFileEntityService: DriveFileEntityService, @@ -424,6 +427,17 @@ export class ApRendererService { })), } as const : {}; + let asEvent = {}; + if (note.hasEvent) { + const event = await this.eventsRepository.findOneBy({ noteId: note.id }); + asEvent = event ? { + type: 'Event', + name: event.title, + startTime: event.start, + endTime: event.end, + } as const : {}; + } + return { id: `${this.config.url}/notes/${note.id}`, type: 'Note', @@ -444,6 +458,7 @@ export class ApRendererService { attachment: files.map(x => this.renderDocument(x)), sensitive: note.cw != null || files.some(file => file.isSensitive), tag, + ...asEvent, ...asPoll, }; }