2018-04-06 12:35:23 +02:00
|
|
|
import Resolver from '../../resolver';
|
|
|
|
import deleteNote from './note';
|
2018-04-07 19:30:37 +02:00
|
|
|
import Note from '../../../../models/note';
|
2018-04-06 23:58:53 +02:00
|
|
|
import { IRemoteUser } from '../../../../models/user';
|
2018-04-03 10:50:52 +02:00
|
|
|
|
2018-04-06 23:44:29 +02:00
|
|
|
/**
|
|
|
|
* 削除アクティビティを捌きます
|
|
|
|
*/
|
2018-04-06 23:58:53 +02:00
|
|
|
export default async (actor: IRemoteUser, activity): Promise<void> => {
|
2018-04-07 20:58:11 +02:00
|
|
|
if ('actor' in activity && actor.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':
|
2018-04-07 19:30:37 +02:00
|
|
|
const note = await Note.findOne({ uri });
|
|
|
|
if (note != 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
|
|
|
};
|