From d6a8889d84f17f4e4530d4b5dcb555d1f3978b01 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 9 May 2020 08:25:23 +0900 Subject: Receive Flag (#6331) --- src/remote/activitypub/kernel/flag/index.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/remote/activitypub/kernel/flag/index.ts (limited to 'src/remote/activitypub/kernel/flag/index.ts') diff --git a/src/remote/activitypub/kernel/flag/index.ts b/src/remote/activitypub/kernel/flag/index.ts new file mode 100644 index 0000000000..9b3065b112 --- /dev/null +++ b/src/remote/activitypub/kernel/flag/index.ts @@ -0,0 +1,28 @@ +import { IRemoteUser } from '../../../../models/entities/user'; +import config from '../../../../config'; +import { IFlag, getApIds } from '../../type'; +import { AbuseUserReports, Users } from '../../../../models'; +import { In } from 'typeorm'; +import { genId } from '../../../../misc/gen-id'; + +export default async (actor: IRemoteUser, activity: IFlag): Promise => { + // objectは `(User|Note) | (User|Note)[]` だけど、全パターンDBスキーマと対応させられないので + // 対象ユーザーは一番最初のユーザー として あとはコメントとして格納する + const uris = getApIds(activity.object); + + const userIds = uris.filter(uri => uri.startsWith(config.url + '/users/')).map(uri => uri.split('/').pop()); + const users = await Users.find({ + id: In(userIds) + }); + if (users.length < 1) return `skip`; + + await AbuseUserReports.insert({ + id: genId(), + createdAt: new Date(), + userId: users[0].id, + reporterId: actor.id, + comment: `${activity.content}\n${JSON.stringify(uris, null, 2)}` + }); + + return `ok`; +}; -- cgit v1.2.3-freya