Fix broadcasting user profiles when protected

This commit is contained in:
Jon Staab
2025-06-16 16:56:59 -07:00
parent d99ada44f5
commit 2fae3ca248
5 changed files with 31 additions and 11 deletions

View File

@@ -233,6 +233,11 @@ export const checkRelayAccess = async (url: string, claim = "") => {
// Ignore messages about the relay ignoring ours // Ignore messages about the relay ignoring ours
if (error?.startsWith("mute: ")) return if (error?.startsWith("mute: ")) return
// Ignore rejected empty claims
if (!claim && error?.includes("invite code")) {
return `failed to request access to relay`
}
return message return message
} }
} }

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import {nthEq} from "@welshman/lib" import {nthNe} from "@welshman/lib"
import type {Profile} from "@welshman/util" import type {Profile} from "@welshman/util"
import { import {
getTag, getTag,
@@ -10,7 +10,7 @@
isPublishedProfile, isPublishedProfile,
uniqTags, uniqTags,
} from "@welshman/util" } from "@welshman/util"
import {Router, addMaximalFallbacks} from "@welshman/router" import {Router} from "@welshman/router"
import {pubkey, profilesByPubkey, publishThunk} from "@welshman/app" import {pubkey, profilesByPubkey, publishThunk} from "@welshman/app"
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
import ProfileEditForm from "@app/components/ProfileEditForm.svelte" import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
@@ -25,20 +25,19 @@
const back = () => history.back() const back = () => history.back()
const onsubmit = ({profile, shouldBroadcast}: {profile: Profile; shouldBroadcast: boolean}) => { const onsubmit = ({profile, shouldBroadcast}: {profile: Profile; shouldBroadcast: boolean}) => {
const router = Router.get()
const template = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile) const template = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile)
const relays = [...getMembershipUrls($userMembership)] const scenarios = [router.FromRelays(getMembershipUrls($userMembership))]
if (shouldBroadcast) { if (shouldBroadcast) {
const router = Router.get() scenarios.push(router.FromUser(), router.Index())
const scenario = router.merge([router.FromUser(), router.Index()]) template.tags = template.tags.filter(nthNe(0, "-"))
relays.push(...scenario.policy(addMaximalFallbacks).getUrls())
template.tags = template.tags.filter(nthEq(0, "-"))
} else { } else {
template.tags = uniqTags([...template.tags, PROTECTED]) template.tags = uniqTags([...template.tags, PROTECTED])
} }
const event = makeEvent(template.kind, template) const event = makeEvent(template.kind, template)
const relays = router.merge(scenarios).getUrls()
publishThunk({event, relays}) publishThunk({event, relays})
pushToast({message: "Your profile has been updated!"}) pushToast({message: "Your profile has been updated!"})

View File

@@ -7,7 +7,7 @@
import ModalHeader from "@lib/components/ModalHeader.svelte" import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte" import ModalFooter from "@lib/components/ModalFooter.svelte"
import {clearModals} from "@app/modal" import {clearModals} from "@app/modal"
import {addSpaceMembership} from "@app/commands" import {addSpaceMembership, broadcastUserData} from "@app/commands"
const {url} = $props() const {url} = $props()
@@ -16,6 +16,7 @@
const tryJoin = async () => { const tryJoin = async () => {
await addSpaceMembership(url) await addSpaceMembership(url)
broadcastUserData([url])
clearModals() clearModals()
} }

View File

@@ -1,13 +1,26 @@
<script module lang="ts"> <script module lang="ts">
import {goto} from "$app/navigation" import {goto} from "$app/navigation"
import {ROOM_META} from "@welshman/util"
import {load} from "@welshman/net"
import {makeSpacePath} from "@app/routes" import {makeSpacePath} from "@app/routes"
import {addSpaceMembership} from "@app/commands" import {addSpaceMembership, broadcastUserData} from "@app/commands"
import {pushToast} from "@app/toast" import {pushToast} from "@app/toast"
export const confirmSpaceJoin = async (url: string) => { export const confirmSpaceJoin = async (url: string) => {
await addSpaceMembership(url) await addSpaceMembership(url)
goto(makeSpacePath(url), {replaceState: true}) const path = makeSpacePath(url)
if (window.location.pathname === path) {
load({
relays: [url],
filters: [{kinds: [ROOM_META]}],
})
}
broadcastUserData([url])
goto(path, {replaceState: true})
pushToast({ pushToast({
message: "Welcome to the space!", message: "Welcome to the space!",

View File

@@ -44,6 +44,7 @@
} from "@welshman/app" } from "@welshman/app"
import * as lib from "@welshman/lib" import * as lib from "@welshman/lib"
import * as util from "@welshman/util" import * as util from "@welshman/util"
import * as router from "@welshman/router"
import * as welshmanSigner from "@welshman/signer" import * as welshmanSigner from "@welshman/signer"
import * as net from "@welshman/net" import * as net from "@welshman/net"
import * as app from "@welshman/app" import * as app from "@welshman/app"
@@ -81,6 +82,7 @@
nip19, nip19,
...lib, ...lib,
...welshmanSigner, ...welshmanSigner,
...router,
...util, ...util,
...net, ...net,
...app, ...app,