From de620c822aa6386f2c706f62e0cfd6b8d9449ab6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 7 Apr 2018 06:44:29 +0900 Subject: [PATCH] Fix bug --- src/remote/activitypub/act/delete/index.ts | 23 +++++++++++++++++++--- src/remote/activitypub/act/delete/note.ts | 10 ++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/remote/activitypub/act/delete/index.ts b/src/remote/activitypub/act/delete/index.ts index 764814bac..42272433d 100644 --- a/src/remote/activitypub/act/delete/index.ts +++ b/src/remote/activitypub/act/delete/index.ts @@ -1,18 +1,35 @@ import Resolver from '../../resolver'; import deleteNote from './note'; +import Post from '../../../../models/post'; +/** + * 削除アクティビティを捌きます + */ export default async (actor, activity): Promise => { if ('actor' in activity && actor.account.uri !== activity.actor) { - throw new Error(); + throw new Error('invalid actor'); } const resolver = new Resolver(); - const object = await resolver.resolve(activity); + const object = await resolver.resolve(activity.object); + + const uri = (object as any).id; switch (object.type) { case 'Note': - deleteNote(object); + deleteNote(uri); + break; + + case 'Tombstone': + const post = await Post.findOne({ uri }); + if (post != null) { + deleteNote(uri); + } + break; + + default: + console.warn(`Unknown type: ${object.type}`); break; } }; diff --git a/src/remote/activitypub/act/delete/note.ts b/src/remote/activitypub/act/delete/note.ts index 3b821f87c..75534250e 100644 --- a/src/remote/activitypub/act/delete/note.ts +++ b/src/remote/activitypub/act/delete/note.ts @@ -1,8 +1,14 @@ +import * as debug from 'debug'; + import Post from '../../../../models/post'; import { createDb } from '../../../../queue'; -export default async function(note) { - const post = await Post.findOneAndDelete({ uri: note.id }); +const log = debug('misskey:activitypub'); + +export default async function(uri: string) { + log(`Deleting the Note: ${uri}`); + + const post = await Post.findOneAndDelete({ uri }); createDb({ type: 'deletePostDependents',