2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 23:33:11 +03:00
|
|
|
import type { UsersRepository, AbuseUserReportsRepository } from '@/models/index.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { InstanceActorService } from '@/core/InstanceActorService.js';
|
|
|
|
import { QueueService } from '@/core/QueueService.js';
|
|
|
|
import { ApRendererService } from '@/core/remote/activitypub/ApRendererService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2019-01-19 12:16:48 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: true,
|
2019-01-19 12:16:48 +02:00
|
|
|
requireModerator: true,
|
2022-02-19 07:05:32 +02:00
|
|
|
} as const;
|
2019-01-19 12:16:48 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
reportId: { type: 'string', format: 'misskey:id' },
|
|
|
|
forward: { type: 'boolean', default: false },
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2022-02-19 07:05:32 +02:00
|
|
|
required: ['reportId'],
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2019-01-19 12:16:48 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
// TODO: ロジックをサービスに切り出す
|
2019-01-19 12:16:48 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
@Inject(DI.abuseUserReportsRepository)
|
|
|
|
private abuseUserReportsRepository: AbuseUserReportsRepository,
|
|
|
|
|
|
|
|
private queueService: QueueService,
|
|
|
|
private instanceActorService: InstanceActorService,
|
|
|
|
private apRendererService: ApRendererService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const report = await this.abuseUserReportsRepository.findOneBy({ id: ps.reportId });
|
|
|
|
|
|
|
|
if (report == null) {
|
|
|
|
throw new Error('report not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps.forward && report.targetUserHost != null) {
|
|
|
|
const actor = await this.instanceActorService.getInstanceActor();
|
|
|
|
const targetUser = await this.usersRepository.findOneByOrFail({ id: report.targetUserId });
|
|
|
|
|
|
|
|
this.queueService.deliver(actor, this.apRendererService.renderActivity(this.apRendererService.renderFlag(actor, [targetUser.uri!], report.comment)), targetUser.inbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.abuseUserReportsRepository.update(report.id, {
|
|
|
|
resolved: true,
|
|
|
|
assigneeId: me.id,
|
|
|
|
forwarded: ps.forward && report.targetUserHost != null,
|
|
|
|
});
|
|
|
|
});
|
2022-01-20 20:06:38 +02:00
|
|
|
}
|
2022-09-17 21:27:08 +03:00
|
|
|
}
|