From d64dc458999afdc0bfd5f662a583bd1a0f6eebb3 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Mon, 29 Oct 2018 20:32:42 +0900 Subject: User blocking (Following part) (#3035) * block wip * UndoBlock * UnBlock * wip * follow * UI * fix --- src/remote/activitypub/kernel/block/index.ts | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/remote/activitypub/kernel/block/index.ts (limited to 'src/remote/activitypub/kernel/block') diff --git a/src/remote/activitypub/kernel/block/index.ts b/src/remote/activitypub/kernel/block/index.ts new file mode 100644 index 0000000000..dec591accf --- /dev/null +++ b/src/remote/activitypub/kernel/block/index.ts @@ -0,0 +1,34 @@ +import * as mongo from 'mongodb'; +import User, { IRemoteUser } from '../../../../models/user'; +import config from '../../../../config'; +import * as debug from 'debug'; +import { IBlock } from '../../type'; +import block from '../../../../services/blocking/create'; + +const log = debug('misskey:activitypub'); + +export default async (actor: IRemoteUser, activity: IBlock): Promise => { + const id = typeof activity.object == 'string' ? activity.object : activity.object.id; + + const uri = activity.id || activity; + + log(`Block: ${uri}`); + + if (!id.startsWith(config.url + '/')) { + return null; + } + + const blockee = await User.findOne({ + _id: new mongo.ObjectID(id.split('/').pop()) + }); + + if (blockee === null) { + throw new Error('blockee not found'); + } + + if (blockee.host != null) { + throw new Error('ブロックしようとしているユーザーはローカルユーザーではありません'); + } + + block(actor, blockee); +}; -- cgit v1.2.3-freya