2023-07-27 05:31:52 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-09-20 20:33:11 +00:00
|
|
|
import type { UsersRepository } from '@/models/index.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { QueueService } from '@/core/QueueService.js';
|
|
|
|
import { UserSuspendService } from '@/core/UserSuspendService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-12-04 06:03:09 +00:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class DeleteAccountService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
private userSuspendService: UserSuspendService,
|
|
|
|
private queueService: QueueService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public async deleteAccount(user: {
|
|
|
|
id: string;
|
|
|
|
host: string | null;
|
|
|
|
}): Promise<void> {
|
2023-01-12 12:02:26 +00:00
|
|
|
const _user = await this.usersRepository.findOneByOrFail({ id: user.id });
|
|
|
|
if (_user.isRoot) throw new Error('cannot delete a root account');
|
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
// 物理削除する前にDelete activityを送信する
|
|
|
|
await this.userSuspendService.doPostSuspend(user).catch(e => {});
|
2023-07-07 22:08:16 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
this.queueService.createDeleteAccountJob(user, {
|
|
|
|
soft: false,
|
|
|
|
});
|
2023-07-07 22:08:16 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
await this.usersRepository.update(user.id, {
|
|
|
|
isDeleted: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|