From 7ea90155c7ebac91b2dac3d41fe15c95cb23dd34 Mon Sep 17 00:00:00 2001 From: atsu1125 Date: Thu, 28 Sep 2023 10:50:23 +0900 Subject: [PATCH] use ActivityPub defined property add activitypub `source` property parse MFM from new `source` attribute --- src/remote/activitypub/models/note.ts | 9 ++++++++- src/remote/activitypub/renderer/note.ts | 4 ++++ src/remote/activitypub/type.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 1e7652ab0a9e..b78954bb9d65 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -197,7 +197,14 @@ export async function createNote(value: string | IObject, resolver?: Resolver | const cw = note.summary === '' ? null : note.summary; // テキストのパース - const text = note._misskey_content || (note.content ? htmlToMfm(note.content, note.tag) : null); + let text: string | null = null; + if (note.source?.mediaType === 'text/x.misskeymarkdown' && typeof note.source?.content === 'string') { + text = note.source.content; + } else if (typeof note._misskey_content !== 'undefined') { + text = note._misskey_content; + } else if (typeof note.content === 'string') { + text = htmlToMfm(note.content, note.tag); + } // vote if (reply && reply.poll) { diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index d2dc88b500e6..52d8b0d066ff 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -145,6 +145,10 @@ export default async function renderNote(note: INote, dive = true): Promise summary, content, _misskey_content: text, + source: { + content: text, + mediaType: "text/x.misskeymarkdown", + }, _misskey_quote: quote, quoteUri: quote, published: note.createdAt.toISOString(), diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 2e97ed4448fa..965fd275bcb1 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -136,6 +136,10 @@ export interface IOrderedCollectionPage extends IObject { export interface IPost extends IObject { type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video' | 'Event'; _misskey_content?: string; + source?: { + content: string; + mediaType: string; + }; _misskey_quote?: string; quoteUrl?: string; quoteUri?: string; @@ -159,6 +163,10 @@ export const isTombstone = (object: IObject): object is ITombstone => export interface IQuestion extends IObject { type: 'Note' | 'Question'; _misskey_content?: string; + source?: { + content: string; + mediaType: string; + }; _misskey_quote?: string; quoteUrl?: string; quoteUri?: string;