FoundKey/packages/backend/src/services/delete-account.ts
Johann150 1eda1760d1
server: refactor to always use deleteAccount service
This should reduce code duplication around how deletion of an actor is
handled.
2023-01-07 19:46:05 +01:00

28 lines
811 B
TypeScript

import { Users } from '@/models/index.js';
import { createDeleteAccountJob } from '@/queue/index.js';
import { publishUserEvent } from './stream.js';
import { doPostSuspend } from './suspend-user.js';
export async function deleteAccount(user: {
id: string;
host: string | null;
}): Promise<void> {
await Users.update(user.id, {
isDeleted: true,
});
if (Users.isLocalUser(user)) {
// Terminate streaming
publishUserEvent(user.id, 'terminate', {});
}
// Send Delete activity before physical deletion
await doPostSuspend(user).catch(() => {});
createDeleteAccountJob(user, {
// Deleting remote users is specified as SOFT, because if they are physically deleted
// from the DB completely, they may be reassociated and their accounts may be reinstated.
soft: Users.isLocalUser(user),
});
}