git clone https://garage44.eu/jeroen/cartopolis.gitcartopolis-agent · 2026-11-28T18:15:52Z
feat(web): an invite link names this page's server inviteLink wrote https://cartopolis.org/go?community=… on every server. It now uses location.origin, as the guest link already did; on a server of one's own the chat page at /go reads ?community= itself. Moved with inviteCode into lib/invite.ts so it has a test.
.../atlas/web/src/components/pages/chat/chat.tsx | 20 +------------------
crates/atlas/web/src/lib/invite.test.ts | 17 ++++++++++++++++
crates/atlas/web/src/lib/invite.ts | 23 ++++++++++++++++++++++
3 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/crates/atlas/web/src/components/pages/chat/chat.tsx b/crates/atlas/web/src/components/pages/chat/chat.tsx
index 18091b5f..fd8a1cd1 100644
--- a/crates/atlas/web/src/components/pages/chat/chat.tsx
+++ b/crates/atlas/web/src/components/pages/chat/chat.tsx
@@ -14,6 +14,7 @@ import {
} from '@/lib/chat'
import {type CallMember, callName, readGuestLink} from '@/lib/call'
import {CAPTION_LANGUAGES} from '@/lib/call-captions'
+import {inviteCode, inviteLink} from '@/lib/invite'
import {
type AnswerFor,
type Meetings,
@@ -4764,22 +4765,3 @@ function distanceWords(m: number): string {
function placeWords(p: CommunityPlace): string {
return p.name.trim() || `${p.latitude.toFixed(4)}, ${p.longitude.toFixed(4)}`
}
-
-/** The code in an invite link (`…/go?community=CODE`), or a bare code. */
-function inviteCode(input: string): string | null {
- const text = input.trim()
- let code = text
- if (/^[a-z]+:\/\//i.test(text)) {
- try {
- code = new URL(text).searchParams.get('community') ?? ''
- } catch {
- return null
- }
- }
- return /^[A-Za-z0-9]{1,64}$/.test(code) ? code : null
-}
-
-/** The link that opens an invite, in the app on a phone that has it and here otherwise. */
-function inviteLink(code: string): string {
- return `https://cartopolis.org/go?community=${code}`
-}
diff --git a/crates/atlas/web/src/lib/invite.test.ts b/crates/atlas/web/src/lib/invite.test.ts
new file mode 100644
index 00000000..c9c1f864
--- /dev/null
+++ b/crates/atlas/web/src/lib/invite.test.ts
@@ -0,0 +1,17 @@
+import {describe, expect, test} from 'bun:test'
+
+import {inviteCode, inviteLink} from './invite'
+
+describe('invite links', () => {
+ test('an invite link names the server that made it', () => {
+ expect(inviteLink('abc123', 'https://rug.example')).toBe('https://rug.example/go?community=abc123')
+ expect(inviteLink('abc123', 'https://cartopolis.org')).toBe('https://cartopolis.org/go?community=abc123')
+ })
+
+ test('an invite link from any server reads back as its code', () => {
+ expect(inviteCode(inviteLink('abc123', 'https://rug.example'))).toBe('abc123')
+ expect(inviteCode(' abc123 ')).toBe('abc123')
+ expect(inviteCode('https://rug.example/go?place=1,2')).toBeNull()
+ expect(inviteCode('../etc')).toBeNull()
+ })
+})
diff --git a/crates/atlas/web/src/lib/invite.ts b/crates/atlas/web/src/lib/invite.ts
new file mode 100644
index 00000000..9191ccc1
--- /dev/null
+++ b/crates/atlas/web/src/lib/invite.ts
@@ -0,0 +1,23 @@
+/** The code in an invite link (`…/go?community=CODE`), or a bare code. */
+export function inviteCode(input: string): string | null {
+ const text = input.trim()
+ let code = text
+ if (/^[a-z]+:\/\//i.test(text)) {
+ try {
+ code = new URL(text).searchParams.get('community') ?? ''
+ } catch {
+ return null
+ }
+ }
+ return /^[A-Za-z0-9]{1,64}$/.test(code) ? code : null
+}
+
+/**
+ * The link that opens an invite, in the app on a phone that has it and here
+ * otherwise: on this page's own server, whose `/go` opens the invite (the
+ * viewer on cartopolis.org, this page on a server of one's own), as the app's
+ * `place_link::invite_link` names the server it is signed in to.
+ */
+export function inviteLink(code: string, origin = location.origin): string {
+ return `${origin}/go?community=${code}`
+}