iceshrimp-161sh/packages/backend/src/services/suspend-user.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import renderDelete from "@/remote/activitypub/renderer/delete.js";
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
import { deliver } from "@/queue/index.js";
import config from "@/config/index.js";
import type { User } from "@/models/entities/user.js";
import { Users, Followings } from "@/models/index.js";
import { Not, IsNull } from "typeorm";
import { publishInternalEvent } from "@/services/stream.js";
2023-01-13 05:40:33 +01:00
export async function doPostSuspend(user: {
id: User["id"];
host: User["host"];
}) {
publishInternalEvent("userChangeSuspendedState", {
id: user.id,
isSuspended: true,
});
if (Users.isLocalUser(user)) {
// Send Delete to all known SharedInboxes
2023-01-13 05:40:33 +01:00
const content = renderActivity(
renderDelete(`${config.url}/users/${user.id}`, user),
);
const queue: string[] = [];
const followings = await Followings.find({
where: [
{ followerSharedInbox: Not(IsNull()) },
2021-12-09 15:58:30 +01:00
{ followeeSharedInbox: Not(IsNull()) },
],
2023-01-13 05:40:33 +01:00
select: ["followerSharedInbox", "followeeSharedInbox"],
});
2023-01-13 05:40:33 +01:00
const inboxes = followings.map(
(x) => x.followerSharedInbox || x.followeeSharedInbox,
);
for (const inbox of inboxes) {
if (inbox != null && !queue.includes(inbox)) queue.push(inbox);
}
for (const inbox of queue) {
deliver(user, content, inbox);
}
}
}