summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-28 16:10:57 +0000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-28 16:10:57 +0000
commitc82b71695d16b0ef19d5e976ea7ca47c62ef3345 (patch)
treefed0e8bc0273ec8fa4255a0aa40d29454d9066e6 /src/api
parentap guild endpoint (diff)
downloadserver-ts-c82b71695d16b0ef19d5e976ea7ca47c62ef3345.tar.xz
send Follow request to guild when remote invite code used
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts1
-rw-r--r--src/api/routes/guilds/#guild_id/welcome-screen.ts8
-rw-r--r--src/api/routes/invites/index.ts36
3 files changed, 36 insertions, 9 deletions
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); + const remoteGuild = await tryResolveWebfinger(inputValue); + if (remoteGuild) { + if (APObjectIsOrganisation(remoteGuild)) + return res.json( + await transformOrganisationToInvite( + inputValue, + remoteGuild, + ), + ); - if (APObjectIsOrganisation(remoteGuild)) - return res.json( - transformOrganisationToInvite(remoteGuild), - ); - - throw new APError("Remote resource is not a guild"); + 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 }, });