summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/accept/follow.ts
blob: f3e517ad9fb2eac7ad3b850f5cfa25740b3df998 (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
27
28
import { IRemoteUser } from '../../../../models/entities/user';
import config from '../../../../config';
import accept from '../../../../services/following/requests/accept';
import { IFollow } from '../../type';
import { Users } from '../../../../models';

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

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

	const follower = await Users.findOne({
		id: id.split('/').pop()
	});

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

	if (follower.host != null) {
		throw new Error('フォローリクエストしたユーザーはローカルユーザーではありません');
	}

	await accept(actor, follower);
};