2023-08-15 02:52:38 +09:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { ModerationLogsRepository } from '@/models/index.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { awaitAll } from '@/misc/prelude/await-all.js';
|
2023-08-08 20:13:05 +09:00
|
|
|
import type { User } from '@/models/entities/User.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import type { ModerationLog } from '@/models/entities/ModerationLog.js';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-08-08 20:13:05 +09:00
|
|
|
import { Packed } from '@/misc/json-schema.js';
|
2023-07-19 11:27:50 +09:00
|
|
|
import { UserEntityService } from './UserEntityService.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ModerationLogEntityService {
|
|
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.moderationLogsRepository)
|
|
|
|
|
private moderationLogsRepository: ModerationLogsRepository,
|
|
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public async pack(
|
|
|
|
|
src: ModerationLog['id'] | ModerationLog,
|
2023-08-08 20:13:05 +09:00
|
|
|
me: { id: User['id'] } | null | undefined,
|
|
|
|
|
) : Promise<Packed<'ModerationLog'>> {
|
2022-09-18 03:27:08 +09:00
|
|
|
const log = typeof src === 'object' ? src : await this.moderationLogsRepository.findOneByOrFail({ id: src });
|
|
|
|
|
|
|
|
|
|
return await awaitAll({
|
|
|
|
|
id: log.id,
|
|
|
|
|
createdAt: log.createdAt.toISOString(),
|
|
|
|
|
type: log.type,
|
|
|
|
|
info: log.info,
|
|
|
|
|
userId: log.userId,
|
2023-08-08 20:13:05 +09:00
|
|
|
user: this.userEntityService.pack(log.user ?? log.userId, me, {
|
2022-09-18 03:27:08 +09:00
|
|
|
detail: true,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2023-08-08 20:13:05 +09:00
|
|
|
public async packMany(
|
|
|
|
|
reports: (ModerationLog['id'] | ModerationLog)[],
|
|
|
|
|
me: { id: User['id'] } | null | undefined,
|
|
|
|
|
) : Promise<Packed<'ModerationLog'>[]> {
|
|
|
|
|
return (await Promise.allSettled(reports.map(x => this.pack(x, me))))
|
|
|
|
|
.filter(result => result.status === 'fulfilled')
|
|
|
|
|
.map(result => (result as PromiseFulfilledResult<Packed<'ModerationLog'>>).value);
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|