summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/follow.ts
blob: c255067bfd82c87622a3fabe98b8eebad58f9839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { IRemoteUser } from '../../../models/entities/user';
import config from '../../../config';
import follow from '../../../services/following/create';
import { IFollow } from '../type';
import { Users } from '../../../models';

export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
	const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
	if (id == null) throw new Error('missing id');

	if (!id.startsWith(config.url + '/')) {
		return;
	}

	const followee = await Users.findOne(id.split('/').pop());

	if (followee == null) {
		throw new Error('followee not found');
	}

	if (followee.host != null) {
		throw new Error('フォローしようとしているユーザーはローカルユーザーではありません');
	}

	await follow(actor, followee, activity.id);
};