misskey/src/remote/activitypub/act/follow.ts
2018-04-06 03:10:25 +09:00

26 lines
643 B
TypeScript

import parseAcct from '../../../acct/parse';
import User from '../../../models/user';
import config from '../../../config';
import follow from '../../../services/following/create';
export default async (actor, activity): Promise<void> => {
const prefix = config.url + '/@';
const id = activity.object.id || activity.object;
if (!id.startsWith(prefix)) {
return null;
}
const { username, host } = parseAcct(id.slice(prefix.length));
if (host !== null) {
throw new Error();
}
const followee = await User.findOne({ username, host });
if (followee === null) {
throw new Error();
}
await follow(actor, followee, activity);
};