egirlskey/src/remote/activitypub/kernel/reject/index.ts

35 lines
751 B
TypeScript
Raw Normal View History

2018-05-31 15:42:37 +00:00
import Resolver from '../../resolver';
import { IRemoteUser } from '../../../../models/user';
import rejectFollow from './follow';
2018-06-18 05:28:43 +00:00
import { IReject, IFollow } from '../../type';
import { apLogger } from '../../logger';
2018-05-31 15:42:37 +00:00
const logger = apLogger;
2018-05-31 15:42:37 +00:00
export default async (actor: IRemoteUser, activity: IReject): Promise<void> => {
const uri = activity.id || activity;
logger.info(`Reject: ${uri}`);
2018-05-31 15:42:37 +00:00
const resolver = new Resolver();
let object;
try {
object = await resolver.resolve(activity.object);
} catch (e) {
logger.error(`Resolution failed: ${e}`);
2018-05-31 15:42:37 +00:00
throw e;
}
switch (object.type) {
case 'Follow':
2018-06-18 05:28:43 +00:00
rejectFollow(actor, object as IFollow);
2018-05-31 15:42:37 +00:00
break;
default:
logger.warn(`Unknown reject type: ${object.type}`);
2018-05-31 15:42:37 +00:00
break;
}
};