summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/block/index.ts
blob: 24bc9d524f6206c9a6e4c32778c39e4c1750b55d (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
29
30
31
32
import config from '../../../../config';
import { IBlock, getApId } from '../../type';
import block from '../../../../services/blocking/create';
import { apLogger } from '../../logger';
import { Users } from '../../../../models';
import { IRemoteUser } from '../../../../models/entities/user';

const logger = apLogger;

export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
	const id = getApId(activity.object);

	const uri = getApId(activity);

	logger.info(`Block: ${uri}`);

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

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

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

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

	block(actor, blockee);
};