2018-05-31 17:42:37 +02:00
|
|
|
import * as mongo from 'mongodb';
|
|
|
|
import User, { IRemoteUser } from '../../../../models/user';
|
|
|
|
import config from '../../../../config';
|
2018-06-01 17:15:17 +02:00
|
|
|
import reject from '../../../../services/following/requests/reject';
|
2018-05-31 17:42:37 +02:00
|
|
|
import { IFollow } from '../../type';
|
|
|
|
|
|
|
|
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
2018-07-08 10:22:11 +02:00
|
|
|
const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id;
|
2018-05-31 17:42:37 +02:00
|
|
|
|
|
|
|
if (!id.startsWith(config.url + '/')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const follower = await User.findOne({
|
|
|
|
_id: new mongo.ObjectID(id.split('/').pop())
|
|
|
|
});
|
|
|
|
|
|
|
|
if (follower === null) {
|
|
|
|
throw new Error('follower not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (follower.host != null) {
|
|
|
|
throw new Error('フォローリクエストしたユーザーはローカルユーザーではありません');
|
|
|
|
}
|
|
|
|
|
|
|
|
await reject(actor, follower);
|
|
|
|
};
|