From 336b45b6f7c9a2174655e4c28c7944c7905768c7 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 23 Nov 2018 02:10:07 +0900 Subject: [PATCH] AP quote (#3384) --- src/remote/activitypub/models/note.ts | 9 ++++++++- src/remote/activitypub/renderer/note.ts | 13 +++++++++++++ src/remote/activitypub/type.ts | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 48a02e79b..c6bdd072a 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -96,6 +96,13 @@ export async function createNote(value: any, resolver?: Resolver, silent = false // リプライ const reply = note.inReplyTo ? await resolveNote(note.inReplyTo, resolver) : null; + // 引用 + let quote: INote; + + if (note._misskey_quote && typeof note._misskey_quote == 'string') { + quote = await resolveNote(note._misskey_quote).catch(() => null); + } + // テキストのパース const text = note._misskey_content ? note._misskey_content : htmlToMFM(note.content); @@ -112,7 +119,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false createdAt: new Date(note.published), files: files, reply, - renote: undefined, + renote: quote, cw: note.summary, text: text, viaMobile: false, diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index d6e2d612c..a854ad9f1 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -42,6 +42,18 @@ export default async function renderNote(note: INote, dive = true): Promise inReplyTo = null; } + let quote; + + if (note.renoteId) { + const renote = await Note.findOne({ + _id: note.renoteId, + }); + + if (renote) { + quote = renote.uri ? renote.uri : `${config.url}/notes/${renote._id}`; + } + } + const user = await User.findOne({ _id: note.userId }); @@ -112,6 +124,7 @@ export default async function renderNote(note: INote, dive = true): Promise summary: note.cw, content, _misskey_content: text, + _misskey_quote: quote, published: note.createdAt.toISOString(), to, cc, diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 234403501..530aaa13d 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -41,6 +41,7 @@ export interface IOrderedCollection extends IObject { export interface INote extends IObject { type: 'Note'; _misskey_content: string; + _misskey_quote: string; } export interface IPerson extends IObject {