From c82b71695d16b0ef19d5e976ea7ca47c62ef3345 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:10:57 +0000 Subject: send Follow request to guild when remote invite code used --- .../routes/channels/#channel_id/messages/index.ts | 1 + src/api/routes/guilds/#guild_id/welcome-screen.ts | 8 +++++ src/api/routes/invites/index.ts | 38 ++++++++++++++++------ 3 files changed, 37 insertions(+), 10 deletions(-) (limited to 'src/api') diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index e303053c..c76df782 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -406,6 +406,7 @@ router.post( ); setImmediate(async () => { + if (!Config.get().federation.enabled) return; const ap = await transformMessageToAnnounceNoce(message); await Federation.distribute(ap); diff --git a/src/api/routes/guilds/#guild_id/welcome-screen.ts b/src/api/routes/guilds/#guild_id/welcome-screen.ts index 81000b4b..f391d7bd 100644 --- a/src/api/routes/guilds/#guild_id/welcome-screen.ts +++ b/src/api/routes/guilds/#guild_id/welcome-screen.ts @@ -70,6 +70,14 @@ router.patch( const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); + // TODO: move this + if (!guild.welcome_screen) + guild.welcome_screen = { + enabled: false, + description: "", + welcome_channels: [], + }; + if (body.enabled != undefined) guild.welcome_screen.enabled = body.enabled; diff --git a/src/api/routes/invites/index.ts b/src/api/routes/invites/index.ts index e91215c4..fe983e11 100644 --- a/src/api/routes/invites/index.ts +++ b/src/api/routes/invites/index.ts @@ -19,9 +19,10 @@ import { APError, APObjectIsOrganisation, - resolveWebfinger, splitQualifiedMention, transformOrganisationToInvite, + tryFederatedGuildJoin, + tryResolveWebfinger, } from "@spacebar/ap"; import { route } from "@spacebar/api"; import { @@ -68,14 +69,18 @@ router.get( if (domain != accountDomain && domain != host) { // The domain isn't ours - const remoteGuild = await resolveWebfinger(inputValue); - - if (APObjectIsOrganisation(remoteGuild)) - return res.json( - transformOrganisationToInvite(remoteGuild), - ); - - throw new APError("Remote resource is not a guild"); + const remoteGuild = await tryResolveWebfinger(inputValue); + if (remoteGuild) { + if (APObjectIsOrganisation(remoteGuild)) + return res.json( + await transformOrganisationToInvite( + inputValue, + remoteGuild, + ), + ); + + throw new APError("Remote resource is not a guild"); + } } } } @@ -110,8 +115,21 @@ router.post( }), async (req: Request, res: Response) => { if (req.user_bot) throw DiscordApiErrors.BOT_PROHIBITED_ENDPOINT; - const { code } = req.params; + + // Federation + const mention = splitQualifiedMention(code); + if (mention.user.length && Config.get().federation.enabled) { + const { domain } = mention; + const { accountDomain, host } = Config.get().federation; + if (domain != accountDomain && domain != host) { + // this domain isn't ours, try a federated join + // send a follow request to the guild + + return res.json(await tryFederatedGuildJoin(code, req.user_id)); + } + } + const { guild_id } = await Invite.findOneOrFail({ where: { code: code }, }); -- cgit 1.5.1