From bd94cc502bdaf46c6ac06597a6e4f6bbfa466994 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Wed, 16 Oct 2024 10:14:33 -0700 Subject: [PATCH] Add invite code creation --- src/app/commands.ts | 4 +- src/app/components/SpaceInvite.svelte | 79 +++++++++++++++++++++ src/app/components/SpaceInviteAccept.svelte | 2 +- src/app/state.ts | 4 +- src/routes/spaces/[nrelay]/+layout.svelte | 23 +++--- 5 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 src/app/components/SpaceInvite.svelte diff --git a/src/app/commands.ts b/src/app/commands.ts index 5127951..1221743 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -7,6 +7,7 @@ import { RELAYS, FOLLOWS, REACTION, + AUTH_JOIN, isSignedEvent, createEvent, displayProfile, @@ -196,7 +197,7 @@ export const checkRelayAccess = async (url: string, claim = "") => { await connection.auth.waitIfPending() const result = await publishThunk({ - event: createEvent(28934, {tags: [["claim", claim]]}), + event: createEvent(AUTH_JOIN, {tags: [["claim", claim]]}), relays: [url], }) @@ -234,6 +235,7 @@ export const checkRelayAuth = async (url: string) => { await connection.auth.waitIfPending() if (!okStatuses.includes(connection.auth.status)) { + console.log(connection.auth.status, connection) return `Failed to authenticate: "${connection.auth.message}"` } } diff --git a/src/app/components/SpaceInvite.svelte b/src/app/components/SpaceInvite.svelte new file mode 100644 index 0000000..fd9dad6 --- /dev/null +++ b/src/app/components/SpaceInvite.svelte @@ -0,0 +1,79 @@ + + +
+ +
+ Create an Invite +
+
+ Get a link that you can use to invite people to + {displayRelayUrl(url)} +
+
+
+ {#if loading} +

+ Requesting an invite code... +

+ {:else} +
+ + +

+ This invite link can be used by clicking "Add Space" and pasting it there. + {#if !claim} + This space did not issue a claim for this link, so additional steps might be + required for people using this invite link. + {/if} +

+
+
+ {/if} +
+ + + +
diff --git a/src/app/components/SpaceInviteAccept.svelte b/src/app/components/SpaceInviteAccept.svelte index 69f2c1f..1a5a63a 100644 --- a/src/app/components/SpaceInviteAccept.svelte +++ b/src/app/components/SpaceInviteAccept.svelte @@ -28,7 +28,7 @@ } const joinRelay = async (invite: string) => { - const [raw, claim] = invite.split("'") + const [raw, claim] = invite.split("|") const url = normalizeRelayUrl(raw) const error = await attemptRelayAccess(url, claim) diff --git a/src/app/state.ts b/src/app/state.ts index 2400ce0..2682eae 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -298,9 +298,9 @@ export type Channel = { messages: ChannelMessage[] } -export const makeChannelId = (url: string, room: string) => `${url}'${room}` +export const makeChannelId = (url: string, room: string) => `${url}|${room}` -export const splitChannelId = (id: string) => id.split("'") +export const splitChannelId = (id: string) => id.split("|") export const channels = derived(channelMessages, $channelMessages => { const messagesByChannelId = new Map() diff --git a/src/routes/spaces/[nrelay]/+layout.svelte b/src/routes/spaces/[nrelay]/+layout.svelte index 421a7da..275fdaf 100644 --- a/src/routes/spaces/[nrelay]/+layout.svelte +++ b/src/routes/spaces/[nrelay]/+layout.svelte @@ -11,6 +11,7 @@ import SecondaryNavItem from "@lib/components/SecondaryNavItem.svelte" import SecondaryNavHeader from "@lib/components/SecondaryNavHeader.svelte" import SecondaryNavSection from "@lib/components/SecondaryNavSection.svelte" + import SpaceInvite from "@app/components/SpaceInvite.svelte" import SpaceExit from "@app/components/SpaceExit.svelte" import SpaceJoin from "@app/components/SpaceJoin.svelte" import RoomCreate from "@app/components/RoomCreate.svelte" @@ -35,6 +36,8 @@ showMenu = !showMenu } + const createInvite = () => pushModal(SpaceInvite, {url}) + const leaveSpace = () => pushModal(SpaceExit, {url}) const joinSpace = () => pushModal(SpaceJoin, {url}) @@ -80,21 +83,25 @@ {/if}