rudeshark.net/src/remote/activitypub/act/delete/index.ts

37 lines
806 B
TypeScript
Raw Normal View History

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-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-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
};