2023-01-12 21:40:33 -07: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";
|
2019-07-17 11:03:28 -06:00
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
export async function doPostSuspend(user: {
|
|
|
|
id: User["id"];
|
|
|
|
host: User["host"];
|
|
|
|
}) {
|
|
|
|
publishInternalEvent("userChangeSuspendedState", {
|
|
|
|
id: user.id,
|
|
|
|
isSuspended: true,
|
|
|
|
});
|
2022-03-25 01:27:41 -06:00
|
|
|
|
2019-07-17 11:03:28 -06:00
|
|
|
if (Users.isLocalUser(user)) {
|
2022-12-15 11:44:03 -07:00
|
|
|
// Send Delete to all known SharedInboxes
|
2023-01-12 21:40:33 -07:00
|
|
|
const content = renderActivity(
|
|
|
|
renderDelete(`${config.url}/users/${user.id}`, user),
|
|
|
|
);
|
2019-07-17 11:03:28 -06:00
|
|
|
|
|
|
|
const queue: string[] = [];
|
|
|
|
|
|
|
|
const followings = await Followings.find({
|
|
|
|
where: [
|
|
|
|
{ followerSharedInbox: Not(IsNull()) },
|
2021-12-09 07:58:30 -07:00
|
|
|
{ followeeSharedInbox: Not(IsNull()) },
|
2019-07-17 11:03:28 -06:00
|
|
|
],
|
2023-01-12 21:40:33 -07:00
|
|
|
select: ["followerSharedInbox", "followeeSharedInbox"],
|
2019-07-17 11:03:28 -06:00
|
|
|
});
|
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
const inboxes = followings.map(
|
|
|
|
(x) => x.followerSharedInbox || x.followeeSharedInbox,
|
|
|
|
);
|
2019-07-17 11:03:28 -06:00
|
|
|
|
|
|
|
for (const inbox of inboxes) {
|
|
|
|
if (inbox != null && !queue.includes(inbox)) queue.push(inbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const inbox of queue) {
|
2021-03-23 20:05:37 -06:00
|
|
|
deliver(user, content, inbox);
|
2019-07-17 11:03:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|