summary refs log tree commit diff
path: root/src/activitypub/routes
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-10-26 05:39:22 +0000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-10-26 05:39:22 +0000
commitcc48f595fdecfdb2825f4023fb157ff5f0e8ded6 (patch)
tree974b4612b87bf5b3fc04933f2c731d83f1ee083c /src/activitypub/routes
parentbasic channel federation (diff)
downloadserver-ts-feat/federation2.tar.xz
bug fixes and improvements (i wrote this code a week ago and forgot what it does) feat/federation2
Diffstat (limited to 'src/activitypub/routes')
-rw-r--r--src/activitypub/routes/guilds/#guild_id/followers.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/activitypub/routes/guilds/#guild_id/followers.ts b/src/activitypub/routes/guilds/#guild_id/followers.ts
new file mode 100644

index 00000000..7f3b9e31 --- /dev/null +++ b/src/activitypub/routes/guilds/#guild_id/followers.ts
@@ -0,0 +1,41 @@ +import { makeOrderedCollection } from "@spacebar/ap"; +import { route } from "@spacebar/api"; +import { + Channel, + Config, + Datasource, + FederationKey, + Member, +} from "@spacebar/util"; +import { Request, Response, Router } from "express"; +const router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + const { guild_id } = req.params; + const { page, min_id, max_id } = req.query; + + const { host } = Config.get().federation; + + const ret = await makeOrderedCollection({ + page: page != undefined, + min_id: min_id?.toString(), + max_id: max_id?.toString(), + id: `https://${host}/federation/guilds/${guild_id}/following`, + getTotalElements: () => Channel.count({ where: { guild_id } }), + getElements: async (before, after): Promise<string[]> => { + const members = await Datasource.getRepository(FederationKey) + .createQueryBuilder("key") + .leftJoin(Member, "member", "member.id == key.actorId") + .where("member.guild_id = :guild_id", { guild_id }) + .getMany(); + + // TODO: actual pagination + + return members.map((x) => x.federatedId); + }, + }); + + return res.json(ret); +}); + +export default router;