Add FORCE_RELAYS option

This commit is contained in:
Jonathan Staab 2023-03-16 15:20:37 -05:00
parent fe990f7d26
commit e775e4959c
8 changed files with 49 additions and 24 deletions

View File

@ -1,2 +0,0 @@
VITE_DUFFLEPUD_URL=http://localhost:8000
VITE_SHOW_DEBUG_ROUTE=true

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
.env.local
node_modules
dist

View File

@ -1,12 +1,17 @@
import type {Relay, Filter} from "nostr-tools"
import type {MyEvent} from "src/util/types"
import {relayInit} from "nostr-tools"
import {pluck, is} from "ramda"
import {pluck, objOf, identity, is} from "ramda"
import {ensurePlural} from "hurdak/lib/hurdak"
import {warn, log, error} from "src/util/logger"
import {union, now, difference} from "src/util/misc"
import {isRelay, normalizeRelayUrl} from "src/util/nostr"
const forceRelays = (import.meta.env.VITE_FORCE_RELAYS || "")
.split(",")
.filter(identity)
.map(objOf("url"))
// Connection management
const connections = {}
@ -138,6 +143,10 @@ const connect = url => {
// Public api - publish/subscribe
const publish = async ({relays, event, onProgress, timeout = 5000}) => {
if (forceRelays.length > 0) {
relays = forceRelays
}
if (relays.length === 0) {
error(`Attempted to publish to zero relays`, event)
} else {
@ -231,6 +240,10 @@ type SubscribeOpts = {
const subscribe = async ({relays, filter, onEvent, onEose, onError}: SubscribeOpts) => {
filter = ensurePlural(filter)
if (forceRelays.length > 0) {
relays = forceRelays
}
const id = createFilterId(filter)
const now = Date.now()
const seen = new Set()
@ -353,6 +366,7 @@ const describeFilter = ({kinds = [], ...filter}) => {
}
export default {
forceRelays,
getConnections,
getConnection,
connect,

View File

@ -1,5 +1,5 @@
<script lang="ts">
import {last, find} from "ramda"
import {last, identity, find} from "ramda"
import {onMount} from "svelte"
import {tweened} from "svelte/motion"
import {fly, fade} from "svelte/transition"
@ -16,6 +16,7 @@
import Likes from "src/views/person/Likes.svelte"
import Relays from "src/views/person/Relays.svelte"
import user from "src/agent/user"
import pool from "src/agent/pool"
import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays"
import network from "src/agent/network"
import {getPersonWithFallback, people} from "src/agent/tables"
@ -29,6 +30,7 @@
const interpolate = (a, b) => t => a + Math.round((b - a) * t)
const {petnamePubkeys, canPublish, mutes} = user
const getRelays = () => sampleRelays(relays.concat(getPubkeyWriteRelays(pubkey)))
const tabs = ["notes", "likes", pool.forceRelays.length === 0 && "relays"].filter(identity)
let pubkey = toHex(npub)
let following = false
@ -77,7 +79,9 @@
})
}
actions.push({onClick: openProfileInfo, label: "Profile", icon: "info"})
if (pool.forceRelays.length === 0) {
actions.push({onClick: openProfileInfo, label: "Profile", icon: "info"})
}
if (user.getPubkey() === pubkey && $canPublish) {
actions.push({
@ -234,7 +238,7 @@
</div>
</div>
<Tabs tabs={["notes", "likes", "relays"]} {activeTab} {setActiveTab} />
<Tabs {tabs} {activeTab} {setActiveTab} />
{#if activeTab === "notes"}
<Notes {pubkey} />

View File

@ -2,6 +2,7 @@
import cx from "classnames"
import {displayPerson} from "src/util/nostr"
import user from "src/agent/user"
import pool from "src/agent/pool"
import {menuIsOpen, installPrompt, routes} from "src/app/ui"
import {newNotifications, newDirectMessages, newChatMessages} from "src/app/listener"
import {slowConnections} from "src/app/connection"
@ -88,14 +89,16 @@
</a>
</li>
<li class="mx-3 my-4 h-px bg-gray-6" />
<li class="relative cursor-pointer">
<a class="block px-4 py-2 transition-all hover:bg-accent hover:text-white" href="/relays">
<i class="fa fa-server mr-2" /> Relays
{#if $slowConnections.length > 0}
<div class="absolute top-2 left-8 h-2 w-2 rounded bg-accent" />
{/if}
</a>
</li>
{#if pool.forceRelays.length === 0}
<li class="relative cursor-pointer">
<a class="block px-4 py-2 transition-all hover:bg-accent hover:text-white" href="/relays">
<i class="fa fa-server mr-2" /> Relays
{#if $slowConnections.length > 0}
<div class="absolute top-2 left-8 h-2 w-2 rounded bg-accent" />
{/if}
</a>
</li>
{/if}
{#if $profile.pubkey}
<li class="cursor-pointer">
<a class="block px-4 py-2 transition-all hover:bg-accent hover:text-white" href="/keys">

View File

@ -115,7 +115,9 @@
}}>here</Anchor
>.
</p>
{#if Object.values(currentRelays).length > 0}
{#if pool.forceRelays.length > 0}
<Spinner />
{:else if Object.values(currentRelays).length > 0}
<p>Currently searching:</p>
{#each Object.values(currentRelays) as relay}
<div class="h-12">

View File

@ -26,6 +26,7 @@
import Compose from "src/partials/Compose.svelte"
import Card from "src/partials/Card.svelte"
import user from "src/agent/user"
import pool from "src/agent/pool"
import keys from "src/agent/keys"
import network from "src/agent/network"
import {getEventPublishRelays, getRelaysForEventParent} from "src/agent/relays"
@ -445,13 +446,15 @@
let:instance
class="flex flex-col gap-2"
on:click={() => instance.hide()}>
<Anchor
type="button-circle"
on:click={() => {
showRelays = true
}}>
<i class="fa fa-server" />
</Anchor>
{#if pool.forceRelays.length === 0}
<Anchor
type="button-circle"
on:click={() => {
showRelays = true
}}>
<i class="fa fa-server" />
</Anchor>
{/if}
{#if muted}
<Anchor type="button-circle" on:click={unmute}>
<i class="fa fa-microphone" />

View File

@ -108,7 +108,9 @@
</div>
</div>
{/if}
<h1 class="staatliches mt-4 text-2xl">NIP05</h1>
{#if loaded && person.verified_as}
<div>
<div class="mb-1 text-lg">NIP05 Identifier</div>
@ -121,7 +123,6 @@
{person.verified_as || "?"}
</div>
</div>
<div>
<div class="mb-1 text-lg">NIP05 Validation Endpoint</div>
<div class="font-mono text-sm">
@ -134,7 +135,6 @@
{nip05QueryEndpoint || "?"}
</div>
</div>
{#if nip05ProfileData}
<div>
<div class="mb-2 text-lg">NIP05 Relay Configuration</div>