From 5f8fb43cc9a2a3dc40b42fa63eee7cc0f9b17338 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 11 Jul 2020 06:19:49 +0900 Subject: [PATCH] =?UTF-8?q?AP=20Delate=20Activity=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20(#6512)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/remote/activitypub/kernel/delete/index.ts | 46 ++++++++++++++----- src/remote/activitypub/type.ts | 8 ++++ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/remote/activitypub/kernel/delete/index.ts b/src/remote/activitypub/kernel/delete/index.ts index be7779e02..4fb3d4057 100644 --- a/src/remote/activitypub/kernel/delete/index.ts +++ b/src/remote/activitypub/kernel/delete/index.ts @@ -1,26 +1,48 @@ -import Resolver from '../../resolver'; import deleteNote from './note'; import { IRemoteUser } from '../../../../models/entities/user'; -import { IDelete, getApId, validPost } from '../../type'; -import { apLogger } from '../../logger'; +import { IDelete, getApId, isTombstone, IObject, validPost, validActor } from '../../type'; +import { toSingle } from '../../../../prelude/array'; /** * 削除アクティビティを捌きます */ -export default async (actor: IRemoteUser, activity: IDelete): Promise => { +export default async (actor: IRemoteUser, activity: IDelete): Promise => { if ('actor' in activity && actor.uri !== activity.actor) { throw new Error('invalid actor'); } - const resolver = new Resolver(); + // 削除対象objectのtype + let formarType: string | undefined; - const object = await resolver.resolve(activity.object); - - const uri = getApId(object); - - if (validPost.includes(object.type) || object.type === 'Tombstone') { - deleteNote(actor, uri); + if (typeof activity.object === 'string') { + // typeが不明だけど、どうせ消えてるのでremote resolveしない + formarType = undefined; } else { - apLogger.warn(`Unknown type: ${object.type}`); + const object = activity.object as IObject; + if (isTombstone(object)) { + formarType = toSingle(object.formerType); + } else { + formarType = toSingle(object.type); + } + } + + const uri = getApId(activity.object); + + // type不明でもactorとobjectが同じならばそれはPersonに違いない + if (!formarType && actor.uri === uri) { + formarType = 'Person'; + } + + // それでもなかったらおそらくNote + if (!formarType) { + formarType = 'Note'; + } + + if (validPost.includes(formarType)) { + return await deleteNote(actor, uri); + } else if (validActor.includes(formarType)) { + return `Delete Actor is not implanted`; + } else { + return `Unknown type ${formarType}`; } }; diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 0533506cd..5c01c24b5 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -119,6 +119,14 @@ interface IQuestionChoice { replies?: ICollection; _misskey_votes?: number; } +export interface ITombstone extends IObject { + type: 'Tombstone'; + formerType?: string; + deleted?: Date; +} + +export const isTombstone = (object: IObject): object is ITombstone => + object.type === 'Tombstone'; export const validActor = ['Person', 'Service', 'Group', 'Organization', 'Application'];