2018-04-06 12:35:23 +02:00
|
|
|
import Resolver from '../../resolver';
|
|
|
|
import deleteNote from './note';
|
2018-04-06 23:44:29 +02:00
|
|
|
import Post from '../../../../models/post';
|
2018-04-03 10:50:52 +02:00
|
|
|
|
2018-04-06 23:44:29 +02:00
|
|
|
/**
|
|
|
|
* 削除アクティビティを捌きます
|
|
|
|
*/
|
2018-04-04 20:21:11 +02:00
|
|
|
export default async (actor, activity): Promise<void> => {
|
2018-04-03 10:50:52 +02:00
|
|
|
if ('actor' in activity && actor.account.uri !== activity.actor) {
|
2018-04-06 23:44:29 +02:00
|
|
|
throw new Error('invalid actor');
|
2018-04-03 10:50:52 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 20:21:11 +02:00
|
|
|
const resolver = new Resolver();
|
2018-04-03 10:50:52 +02:00
|
|
|
|
2018-04-06 23:44:29 +02:00
|
|
|
const object = await resolver.resolve(activity.object);
|
|
|
|
|
|
|
|
const uri = (object as any).id;
|
2018-04-03 10:50:52 +02:00
|
|
|
|
2018-04-04 20:21:11 +02:00
|
|
|
switch (object.type) {
|
|
|
|
case 'Note':
|
2018-04-06 23:51:35 +02:00
|
|
|
deleteNote(actor, uri);
|
2018-04-06 23:44:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Tombstone':
|
|
|
|
const post = await Post.findOne({ uri });
|
|
|
|
if (post != null) {
|
2018-04-06 23:51:35 +02:00
|
|
|
deleteNote(actor, uri);
|
2018-04-06 23:44:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
console.warn(`Unknown type: ${object.type}`);
|
2018-04-04 20:21:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-03 10:50:52 +02:00
|
|
|
};
|