diff --git a/src/app/commands.ts b/src/app/commands.ts index ce4bef9c..11dff46f 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -189,39 +189,42 @@ export const setInboxRelayPolicy = (url: string, enabled: boolean) => { // Relay access -export const requestRelayAccess = (url: string, claim = "") => - publishThunk({ +export const checkRelayAccess = async (url: string, claim = "") => { + await ctx.net.pool.get(url).ensureAuth() + + const result = await publishThunk({ event: createEvent(28934, {tags: [["claim", claim]]}), relays: [url], }) -export const attemptRelayAccess = async (url: string, claim = "") => { - const relay = await loadRelay(url) - - // Make sure the relay has a profile - if (!relay?.profile) { - return "Sorry, we weren't able to find that relay." - } - - const connection = ctx.net.pool.get(url) - - // Check connection status - await connection.ensureConnected() - - if (![ConnectionStatus.Ok, ConnectionStatus.Slow].includes(connection.meta.getStatus())) { - return `Failed to connect: "${connection.meta.getDescription()}"` - } - - // Attempt to publish a join request - const result = await requestRelayAccess(url, claim) - if (result[url].status !== PublishStatus.Success) { const message = result[url].message?.replace(/^.*: /, '') || "join request rejected" return `Failed to join relay: ${message}` } +} + +export const checkRelayProfile = async (url: string) => { + const relay = await loadRelay(url) + + if (!relay?.profile) { + return "Sorry, we weren't able to find that relay." + } +} + +export const checkRelayConnection = async (url: string) => { + const connection = ctx.net.pool.get(url) + + await connection.ensureConnected() + + if (![ConnectionStatus.Ok, ConnectionStatus.Slow].includes(connection.meta.getStatus())) { + return `Failed to connect: "${connection.meta.getDescription()}"` + } +} + +export const checkRelayAuth = async (url: string) => { + const connection = ctx.net.pool.get(url) - // Check auth status await connection.ensureAuth() if (![AuthStatus.Ok, AuthStatus.Pending].includes(connection.meta.authStatus)) { @@ -229,6 +232,12 @@ export const attemptRelayAccess = async (url: string, claim = "") => { } } +export const attemptRelayAccess = async (url: string, claim = "") => + await checkRelayProfile(url) || + await checkRelayConnection(url) || + await checkRelayAccess(url, claim) || + await checkRelayAuth(url) + // Actions export const sendWrapped = async ({ diff --git a/src/app/components/PeopleItem.svelte b/src/app/components/PeopleItem.svelte index f9ec9aca..6493df9f 100644 --- a/src/app/components/PeopleItem.svelte +++ b/src/app/components/PeopleItem.svelte @@ -48,7 +48,7 @@ {@const following = getPubkeyTagValues(getListTags($userFollows)).includes(pubkey)}