Detect nip29 properly before choosing smart path, more robust auth error checking

This commit is contained in:
Jon Staab
2025-11-04 16:14:32 -08:00
parent 6429f82829
commit 501ce8067d
12 changed files with 56 additions and 45 deletions
+1
View File
@@ -6,6 +6,7 @@ import {page} from "$app/stores"
export type ModalOptions = {
drawer?: boolean
noEscape?: boolean
fullscreen?: boolean
replaceState?: boolean
path?: string
+1 -2
View File
@@ -62,11 +62,10 @@ export const mostlyRestrictedPolicy = (socket: Socket) => {
const pending = new Set<string>()
const updateStatus = () => {
const updateStatus = () =>
relaysMostlyRestricted.update(
restricted > total / 2 ? assoc(socket.url, error) : dissoc(socket.url),
)
}
const unsubscribers = [
on(socket, SocketEvent.Receive, (message: RelayMessage) => {
+14 -9
View File
@@ -4,7 +4,7 @@ import * as nip19 from "nostr-tools/nip19"
import {goto} from "$app/navigation"
import {nthEq, sleep} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
import {tracker, relaysByUrl} from "@welshman/app"
import {tracker, loadRelay} from "@welshman/app"
import {scrollToEvent} from "@lib/html"
import {identity} from "@welshman/lib"
import {
@@ -26,6 +26,7 @@ import {
hasNip29,
ROOM,
} from "@app/core/state"
import {lastPageBySpaceUrl} from "@app/util/history"
export const makeSpacePath = (url: string, ...extra: (string | undefined)[]) => {
let path = `/spaces/${encodeRelay(url)}`
@@ -37,19 +38,23 @@ export const makeSpacePath = (url: string, ...extra: (string | undefined)[]) =>
.filter(identity)
.map(s => encodeURIComponent(s as string))
.join("/")
} else {
const relay = relaysByUrl.get().get(url)
if (hasNip29(relay)) {
path += "/recent"
} else {
path += "/chat"
}
}
return path
}
export const goToSpace = async (url: string) => {
const prevPath = lastPageBySpaceUrl.get(encodeRelay(url))
if (prevPath) {
goto(prevPath)
} else if (hasNip29(await loadRelay(url))) {
goto(makeSpacePath(url, "recent"))
} else {
goto(makeSpacePath("chat"))
}
}
export const makeChatPath = (pubkeys: string[]) => `/chat/${makeChatId(pubkeys)}`
export const makeRoomPath = (url: string, h: string) => `/spaces/${encodeRelay(url)}/${h}`