rudeshark.net/src/remote/activitypub/kernel/undo/index.ts

38 lines
773 B
TypeScript
Raw Normal View History

2018-04-07 09:14:35 +02:00
import * as debug from 'debug';
import { IRemoteUser } from '../../../../models/user';
2018-06-18 07:28:43 +02:00
import { IUndo, IFollow } from '../../type';
2018-04-07 08:54:11 +02:00
import unfollow from './follow';
2018-04-07 09:14:35 +02:00
import Resolver from '../../resolver';
const log = debug('misskey:activitypub');
2018-04-04 18:22:41 +02:00
2018-04-07 09:14:35 +02:00
export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
2018-04-07 20:58:11 +02:00
if ('actor' in activity && actor.uri !== activity.actor) {
2018-04-04 18:22:41 +02:00
throw new Error('invalid actor');
}
2018-04-07 09:14:35 +02:00
const uri = activity.id || activity;
log(`Undo: ${uri}`);
const resolver = new Resolver();
let object;
try {
object = await resolver.resolve(activity.object);
} catch (e) {
log(`Resolution failed: ${e}`);
throw e;
}
switch (object.type) {
2018-04-04 18:22:41 +02:00
case 'Follow':
2018-06-18 07:28:43 +02:00
unfollow(actor, object as IFollow);
2018-04-04 18:22:41 +02:00
break;
}
return null;
};