1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-25 20:18:28 +09:00
misskey/src/remote/activitypub/kernel/follow.ts
2018-04-18 14:09:55 +09:00

28 lines
813 B
TypeScript

import * as mongo from 'mongodb';
import User, { IRemoteUser } from '../../../models/user';
import config from '../../../config';
import follow from '../../../services/following/create';
import { IFollow } from '../type';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (!id.startsWith(config.url + '/')) {
return null;
}
const followee = await User.findOne({
_id: new mongo.ObjectID(id.split('/').pop())
});
if (followee === null) {
throw new Error('followee not found');
}
if (followee.host != null) {
throw new Error('フォローしようとしているユーザーはローカルユーザーではありません');
}
await follow(actor, followee, activity);
};