2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 20:33:11 +00:00
|
|
|
import type { UsersRepository, AbuseUserReportsRepository } from '@/models/index.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { InstanceActorService } from '@/core/InstanceActorService.js';
|
|
|
|
import { QueueService } from '@/core/QueueService.js';
|
2022-12-04 01:16:03 +00:00
|
|
|
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2019-01-19 10:16:48 +00:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: true,
|
2019-01-19 10:16:48 +00:00
|
|
|
requireModerator: true,
|
2022-02-19 05:05:32 +00:00
|
|
|
} as const;
|
2019-01-19 10:16:48 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
reportId: { type: 'string', format: 'misskey:id' },
|
|
|
|
forward: { type: 'boolean', default: false },
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-02-19 05:05:32 +00:00
|
|
|
required: ['reportId'],
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2019-01-19 10:16:48 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
// TODO: ロジックをサービスに切り出す
|
2019-01-19 10:16:48 +00:00
|
|
|
|
2022-09-17 18:27:08 +00: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 });
|
|
|
|
|
2023-03-14 10:11:31 +00:00
|
|
|
this.queueService.deliver(actor, this.apRendererService.addContext(this.apRendererService.renderFlag(actor, targetUser.uri!, report.comment)), targetUser.inbox, false);
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await this.abuseUserReportsRepository.update(report.id, {
|
|
|
|
resolved: true,
|
|
|
|
assigneeId: me.id,
|
|
|
|
forwarded: ps.forward && report.targetUserHost != null,
|
|
|
|
});
|
|
|
|
});
|
2022-01-20 18:06:38 +00:00
|
|
|
}
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|