mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 08:21:20 +00:00
Re-introduce FORCE_RELAYS setting
This commit is contained in:
parent
4aa1a6cc0a
commit
933fce22cf
@ -58,7 +58,7 @@
|
||||
<h1 class="staatliches text-4xl leading-none">{appName}</h1>
|
||||
</Anchor>
|
||||
<MenuDesktopItem path="/notes">Feed</MenuDesktopItem>
|
||||
{#if !$env.FORCE_GROUP}
|
||||
{#if !$env.FORCE_GROUP && $env.FORCE_RELAYS.length === 0}
|
||||
<MenuDesktopItem path="/settings/relays">
|
||||
<div class="relative inline-block">
|
||||
Relays
|
||||
|
@ -72,7 +72,7 @@
|
||||
<MenuMobileItem stopPropagation on:click={openSettings}>
|
||||
<i class="fa fa-cog" /> Settings
|
||||
</MenuMobileItem>
|
||||
{#if !$env.FORCE_GROUP}
|
||||
{#if !$env.FORCE_GROUP && $env.FORCE_RELAYS.length === 0}
|
||||
<MenuMobileItem href="/settings/relays">
|
||||
<i class="fa fa-server" />
|
||||
<div class="relative inline-block">
|
||||
|
@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {Storage} from "hurdak"
|
||||
import {uniq} from 'ramda'
|
||||
import {uniq} from "ramda"
|
||||
import {FeedLoader} from "src/engine"
|
||||
import {createScroller} from "src/util/misc"
|
||||
import {LOCAL_RELAY_URL} from "src/util/nostr"
|
||||
@ -14,6 +14,7 @@
|
||||
import {
|
||||
readable,
|
||||
writable,
|
||||
selectHints,
|
||||
compileFilters,
|
||||
searchableRelays,
|
||||
getRelaysFromFilters,
|
||||
@ -56,7 +57,7 @@
|
||||
|
||||
feed = new FeedLoader({
|
||||
filters: compileFilters([filter], {includeReposts: true}),
|
||||
relays: getRelays(),
|
||||
relays: selectHints(getRelays()),
|
||||
anchor,
|
||||
shouldListen,
|
||||
shouldDefer: true,
|
||||
|
@ -204,7 +204,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (!$env.FORCE_GROUP && !note.wrap) {
|
||||
if (!$env.FORCE_GROUP && $env.FORCE_RELAYS.length === 0 && !note.wrap) {
|
||||
actions.push({label: "Broadcast", icon: "rss", onClick: broadcast})
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{#if note.seen_on.length > 0}
|
||||
{#if note.seen_on.length > 0 && $env.FORCE_RELAYS.length < 2}
|
||||
<h1 class="staatliches text-2xl">Relays</h1>
|
||||
<p>This note was found on {quantify(note.seen_on.length, "relay")} below.</p>
|
||||
<div class="flex flex-col gap-2">
|
||||
|
@ -13,7 +13,7 @@
|
||||
import RelayCard from "src/app/shared/RelayCard.svelte"
|
||||
import GroupSummary from "src/app/shared/GroupSummary.svelte"
|
||||
import RelaySearch from "src/app/shared/RelaySearch.svelte"
|
||||
import {getGroupPublishHints, deriveGroupOptions, displayRelay} from "src/engine"
|
||||
import {env, getGroupPublishHints, deriveGroupOptions, displayRelay} from "src/engine"
|
||||
|
||||
export let hideFields = []
|
||||
export let initialValues: {
|
||||
@ -98,7 +98,7 @@
|
||||
</div>
|
||||
</Field>
|
||||
{/if}
|
||||
{#if !hideFields.includes("relays")}
|
||||
{#if !hideFields.includes("relays") && $env.FORCE_RELAYS.length === 0}
|
||||
<Field icon="fa-database" label="Select which relays to publish to">
|
||||
<div>
|
||||
{#each values.relays as url}
|
||||
|
@ -5,7 +5,7 @@
|
||||
import Chip from "src/partials/Chip.svelte"
|
||||
import Subheading from "src/partials/Subheading.svelte"
|
||||
import Note from "src/app/shared/Note.svelte"
|
||||
import {load, getUserRelayUrls} from "src/engine"
|
||||
import {load, getUserHints} from "src/engine"
|
||||
|
||||
export let pubkey
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
}
|
||||
|
||||
load({
|
||||
relays: getUserRelayUrls("write"),
|
||||
relays: getUserHints("write"),
|
||||
filters: [{kinds: [1985], authors: [pubkey], "#L": ["#t"]}],
|
||||
onEvent: batch(300, chunk => {
|
||||
events = [...events, ...chunk]
|
||||
|
@ -15,7 +15,7 @@
|
||||
import Compose from "src/app/shared/Compose.svelte"
|
||||
import {router} from "src/app/router"
|
||||
import {toastProgress} from "src/app/state"
|
||||
import {dereferenceNote, publishToZeroOrMoreGroups, getUserRelayUrls} from "src/engine"
|
||||
import {dereferenceNote, publishToZeroOrMoreGroups, getUserHints} from "src/engine"
|
||||
|
||||
export let address
|
||||
export let event
|
||||
@ -33,7 +33,7 @@
|
||||
builder.setImageMeta(images.getValue())
|
||||
|
||||
const {pubs} = await publishToZeroOrMoreGroups(values.groups, builder.template, {
|
||||
relays: getUserRelayUrls("write"),
|
||||
relays: getUserHints("write"),
|
||||
})
|
||||
|
||||
pubs[0].on("progress", toastProgress)
|
||||
|
@ -24,6 +24,7 @@
|
||||
displayGroup,
|
||||
session,
|
||||
subscribe,
|
||||
loadPubkeys,
|
||||
publishGroupEntryRequest,
|
||||
groupRequests,
|
||||
deriveGroup,
|
||||
@ -76,6 +77,7 @@
|
||||
let tabs
|
||||
|
||||
$: relays = relays || info.relays
|
||||
$: loadPubkeys($group.members || [])
|
||||
|
||||
$: {
|
||||
tabs = ["notes"]
|
||||
|
@ -12,6 +12,7 @@
|
||||
import SearchSelect from "src/partials/SearchSelect.svelte"
|
||||
import {router} from "src/app/router"
|
||||
import {
|
||||
env,
|
||||
userLists,
|
||||
searchPeople,
|
||||
searchTopics,
|
||||
@ -99,6 +100,7 @@
|
||||
</SearchSelect>
|
||||
<p slot="info">Type "@" to look for people, and "#" to look for topics.</p>
|
||||
</Field>
|
||||
{#if $env.FORCE_RELAYS.length === 0}
|
||||
<Field label="Relays">
|
||||
<SearchSelect multiple search={searchRelayTags} bind:value={values.relays}>
|
||||
<div slot="item" let:item>
|
||||
@ -110,6 +112,7 @@
|
||||
will be used.
|
||||
</p>
|
||||
</Field>
|
||||
{/if}
|
||||
<Anchor button tag="button" type="submit">Save</Anchor>
|
||||
</div>
|
||||
</FlexColumn>
|
||||
|
@ -18,7 +18,7 @@
|
||||
import Compose from "src/app/shared/Compose.svelte"
|
||||
import {router} from "src/app/router"
|
||||
import {toastProgress} from "src/app/state"
|
||||
import {dereferenceNote, publishToZeroOrMoreGroups, getUserRelayUrls} from "src/engine"
|
||||
import {dereferenceNote, publishToZeroOrMoreGroups, getUserHints} from "src/engine"
|
||||
|
||||
export let address
|
||||
export let event
|
||||
@ -41,7 +41,7 @@
|
||||
builder.setImages(images.getValue())
|
||||
|
||||
const {pubs} = await publishToZeroOrMoreGroups(values.groups, builder.template, {
|
||||
relays: getUserRelayUrls("write"),
|
||||
relays: getUserHints("write"),
|
||||
})
|
||||
|
||||
pubs[0].on("progress", toastProgress)
|
||||
|
@ -306,7 +306,9 @@
|
||||
<i class="fa fa-circle-nodes" />
|
||||
{opts.groups.length}
|
||||
</span>
|
||||
{#if $env.FORCE_RELAYS.length === 0}
|
||||
<span><i class="fa fa-server" /> {opts.relays?.length}</span>
|
||||
{/if}
|
||||
<span><i class="fa fa-warning" /> {opts.warning || 0}</span>
|
||||
</small>
|
||||
{/if}
|
||||
|
@ -4,7 +4,7 @@ import {createEvent, now} from "paravel"
|
||||
import {generatePrivateKey} from "src/util/nostr"
|
||||
import {pubkey} from "src/engine/session/state"
|
||||
import {signer, nip44, nip59} from "src/engine/session/derived"
|
||||
import {getUserRelayUrls} from "src/engine/relays/utils"
|
||||
import {getUserHints} from "src/engine/relays/utils"
|
||||
import {Publisher} from "src/engine/network/utils"
|
||||
import type {Event} from "./model"
|
||||
import {seenIds} from "./state"
|
||||
@ -20,7 +20,7 @@ export const markAsSeenPublicly = batch(5000, async idChunks => {
|
||||
for (const ids of chunk(500, uniq(flatten(idChunks)))) {
|
||||
Publisher.publish({
|
||||
event: await signer.get().signAsUser(createReadReceipt(ids)),
|
||||
relays: getUserRelayUrls("write"),
|
||||
relays: getUserHints("write"),
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -40,7 +40,7 @@ export const markAsSeenPrivately = batch(5000, async idChunks => {
|
||||
|
||||
Publisher.publish({
|
||||
event: rumor.wrap,
|
||||
relays: getUserRelayUrls("write"),
|
||||
relays: getUserHints("write"),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -2,7 +2,7 @@ import {now} from "paravel"
|
||||
import {seconds} from "hurdak"
|
||||
import {Naddr, noteKinds, repostKinds} from "src/util/nostr"
|
||||
import {load} from "src/engine/network/utils"
|
||||
import {getUserHints} from "src/engine/relays/utils"
|
||||
import {selectHintsWithFallback} from "src/engine/relays/utils"
|
||||
import {updateCurrentSession} from "src/engine/session/commands"
|
||||
import {groups} from "./state"
|
||||
import {
|
||||
@ -44,7 +44,7 @@ export const loadGroups = async (rawAddrs: string[], relays: string[] = null) =>
|
||||
|
||||
if (naddrs.length > 0) {
|
||||
load({
|
||||
relays: relays || getUserHints("read"),
|
||||
relays: selectHintsWithFallback(relays),
|
||||
filters: [{kinds: [34550, 35834], authors, "#d": identifiers}],
|
||||
})
|
||||
}
|
||||
@ -59,11 +59,11 @@ export const loadGroupMessages = async () => {
|
||||
}
|
||||
|
||||
for (const address of deriveUserCommunities().get()) {
|
||||
const info = getCommunityReqInfo(address)
|
||||
const {relays, ...info} = getCommunityReqInfo(address)
|
||||
const kinds = [...noteKinds, ...repostKinds]
|
||||
const since = Math.max(now() - seconds(7, "day"), info.since)
|
||||
|
||||
load({relays: info.relays, filters: [{kinds, "#a": [address], since}]})
|
||||
load({relays, filters: [{kinds, "#a": [address], since}]})
|
||||
}
|
||||
|
||||
updateCurrentSession($session => {
|
||||
|
@ -5,7 +5,7 @@ import {Naddr} from "src/util/nostr"
|
||||
import type {GroupStatus, Session} from "src/engine/session/model"
|
||||
import {pubkey} from "src/engine/session/state"
|
||||
import {session} from "src/engine/session/derived"
|
||||
import {getUserRelayUrls, getGroupHints, mergeHints} from "src/engine/relays/utils"
|
||||
import {getUserHints, getGroupHints, mergeHints} from "src/engine/relays/utils"
|
||||
import {groups, groupSharedKeys, groupAdminKeys} from "./state"
|
||||
import {GroupAccess} from "./model"
|
||||
import type {Group} from "./model"
|
||||
@ -66,7 +66,7 @@ export const getGroupReqInfo = (address = null) => {
|
||||
recipients.push(key.pubkey)
|
||||
}
|
||||
|
||||
const relays = mergeHints([...addresses.map(getGroupHints), getUserRelayUrls("read")])
|
||||
const relays = mergeHints([...addresses.map(getGroupHints), getUserHints("read")])
|
||||
|
||||
return {admins, recipients, relays, since}
|
||||
}
|
||||
@ -77,7 +77,7 @@ export const getCommunityReqInfo = (address = null) => {
|
||||
|
||||
return {
|
||||
since: since - seconds(6, "hour"),
|
||||
relays: mergeHints([getGroupHints(address), getUserRelayUrls("read")]),
|
||||
relays: mergeHints([getGroupHints(address), getUserHints("read")]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import {first} from "hurdak"
|
||||
import {cached, Tags} from "paravel"
|
||||
import {derived} from "src/engine/core/utils"
|
||||
import {load} from "src/engine/network/utils"
|
||||
import {getUserRelayUrls} from "src/engine/relays/utils"
|
||||
import {getUserHints} from "src/engine/relays/utils"
|
||||
import {follows} from "src/engine/people/derived"
|
||||
import {handlers, handlerRecs} from "./state"
|
||||
|
||||
@ -14,7 +14,7 @@ export const deriveHandlers = cached({
|
||||
const $follows = follows.get()
|
||||
|
||||
load({
|
||||
relays: getUserRelayUrls("read"),
|
||||
relays: getUserHints("read"),
|
||||
filters: [
|
||||
{kinds: [31989], "#d": [String(kind)], authors: Array.from($follows)},
|
||||
{kinds: [31990], "#k": [String(kind)]},
|
||||
|
@ -1,10 +1,11 @@
|
||||
import {max, partition, equals} from "ramda"
|
||||
import {max, without, uniq, partition, equals} from "ramda"
|
||||
import {noop, pickVals} from "hurdak"
|
||||
import {Plex, Relays, Executor, Multi, createEvent} from "paravel"
|
||||
import {error, warn} from "src/util/logger"
|
||||
import {LOCAL_RELAY_URL} from "src/util/nostr"
|
||||
import {normalizeRelayUrl} from "src/engine/relays/utils"
|
||||
import {pool} from "src/engine/network/state"
|
||||
import {env} from "src/engine/session/state"
|
||||
import {getSetting} from "src/engine/session/utils"
|
||||
import {signer, canSign} from "src/engine/session/derived"
|
||||
import {LocalTarget} from "./targets"
|
||||
@ -14,13 +15,20 @@ export const getUrls = (relays: string[]) => {
|
||||
error(`Attempted to connect to zero urls`)
|
||||
}
|
||||
|
||||
const urls = new Set(relays.map(normalizeRelayUrl))
|
||||
const urls = uniq(relays.map(normalizeRelayUrl))
|
||||
|
||||
if (urls.size !== relays.length) {
|
||||
if (urls.length !== relays.length) {
|
||||
warn(`Attempted to connect to non-unique relays`)
|
||||
}
|
||||
|
||||
return Array.from(urls)
|
||||
const {FORCE_RELAYS} = env.get()
|
||||
const nonLocalRelays = without([LOCAL_RELAY_URL], urls)
|
||||
|
||||
if (FORCE_RELAYS.length > 0 && nonLocalRelays.some(url => !FORCE_RELAYS.includes(url))) {
|
||||
warn(`Attempted to connect to something other than FORCE_RELAYS`, urls)
|
||||
}
|
||||
|
||||
return urls
|
||||
}
|
||||
|
||||
export const getTarget = (urls: string[]) => {
|
||||
|
@ -7,6 +7,7 @@ import logger from "src/util/logger"
|
||||
import {getSetting} from "src/engine/session/utils"
|
||||
import type {Event} from "src/engine/events/model"
|
||||
import {mergeHints} from "src/engine/relays/utils"
|
||||
import {getUrls} from "src/engine/network/utils"
|
||||
import type {Filter} from "../model"
|
||||
import {combineFilters} from "./filters"
|
||||
import {subscribe} from "./subscribe"
|
||||
@ -120,6 +121,9 @@ export const load = (request: LoadOpts) => {
|
||||
const result = defer()
|
||||
const tracker = new Tracker()
|
||||
|
||||
// Just a dumb hack to get a warning about relay urls before we lose the stack trace
|
||||
getUrls(request.relays)
|
||||
|
||||
execute({tracker, request, result, results: []})
|
||||
|
||||
return result
|
||||
|
@ -3,6 +3,7 @@ import {Tags, isShareableRelay, normalizeRelayUrl as normalize, fromNostrURI} fr
|
||||
import {sortBy, whereEq, pluck, uniq, nth, prop, last} from "ramda"
|
||||
import {chain, displayList, first} from "hurdak"
|
||||
import {fuzzy} from "src/util/misc"
|
||||
import {warn} from "src/util/logger"
|
||||
import {LOCAL_RELAY_URL, Naddr} from "src/util/nostr"
|
||||
import type {Event} from "src/engine/events/model"
|
||||
import {env} from "src/engine/session/state"
|
||||
@ -102,6 +103,7 @@ export const getGroupRelayUrls = address => {
|
||||
// 5) Advertise relays — write and read back your own relay list
|
||||
|
||||
export const selectHints = (hints: Iterable<string>, limit: number = null) => {
|
||||
const {FORCE_RELAYS} = env.get()
|
||||
const seen = new Set()
|
||||
const ok = []
|
||||
const bad = []
|
||||
@ -110,7 +112,7 @@ export const selectHints = (hints: Iterable<string>, limit: number = null) => {
|
||||
limit = getSetting("relay_limit")
|
||||
}
|
||||
|
||||
for (const url of chain(hints, getUserRelayUrls(RelayMode.Read), env.get().DEFAULT_RELAYS)) {
|
||||
for (const url of FORCE_RELAYS.length > 0 ? FORCE_RELAYS : hints) {
|
||||
if (seen.has(url)) {
|
||||
continue
|
||||
}
|
||||
@ -135,9 +137,18 @@ export const selectHints = (hints: Iterable<string>, limit: number = null) => {
|
||||
}
|
||||
|
||||
// If we don't have enough hints, use the broken ones
|
||||
return ok.concat(bad).slice(0, limit)
|
||||
const result = ok.concat(bad).slice(0, limit)
|
||||
|
||||
if (result.length === 0) {
|
||||
warn("No results returned from selectHints")
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export const selectHintsWithFallback = (hints: Iterable<string> = null, limit = null) =>
|
||||
selectHints(chain(hints || [], getUserRelayUrls(RelayMode.Read), env.get().DEFAULT_RELAYS), limit)
|
||||
|
||||
export class HintSelector {
|
||||
constructor(
|
||||
readonly generateHints,
|
||||
@ -219,7 +230,7 @@ export const getPublishHints = hintSelector(function* (event: Event) {
|
||||
const hintGroups = pubkeys.map(pubkey => getPubkeyRelayUrls(pubkey, RelayMode.Read))
|
||||
const authorRelays = getPubkeyRelayUrls(event.pubkey, RelayMode.Write)
|
||||
|
||||
yield* mergeHints([...hintGroups, authorRelays, getUserRelayUrls(RelayMode.Write)])
|
||||
yield* mergeHints([...hintGroups, authorRelays, getUserHints(RelayMode.Write)])
|
||||
})
|
||||
|
||||
export const getInboxHints = hintSelector(function* (pubkeys: string[]) {
|
||||
@ -234,7 +245,7 @@ export const getGroupHints = hintSelector(function* (address: string) {
|
||||
export const getGroupPublishHints = (addresses: string[]) => {
|
||||
const urls = mergeHints(addresses.map(getGroupRelayUrls))
|
||||
|
||||
return urls.length === 0 ? getUserRelayUrls("write") : urls
|
||||
return urls.length === 0 ? getUserHints("write") : urls
|
||||
}
|
||||
|
||||
export const mergeHints = (groups: string[][], limit: number = null) => {
|
||||
|
10
src/main.js
10
src/main.js
@ -2,6 +2,7 @@ import "src/app.css"
|
||||
|
||||
import {identity} from "ramda"
|
||||
import {Fetch} from "hurdak"
|
||||
import {normalizeRelayUrl} from "paravel"
|
||||
import Bugsnag from "@bugsnag/js"
|
||||
import {tryFetch} from "src/util/misc"
|
||||
import {env, saveRelay} from "src/engine"
|
||||
@ -39,11 +40,13 @@ const NIP96_URLS = fromCsv(import.meta.env.VITE_NIP96_URLS)
|
||||
|
||||
const FORCE_GROUP = import.meta.env.VITE_FORCE_GROUP
|
||||
|
||||
const DVM_RELAYS = fromCsv(import.meta.env.VITE_DVM_RELAYS)
|
||||
const FORCE_RELAYS = fromCsv(import.meta.env.VITE_FORCE_RELAYS).map(normalizeRelayUrl)
|
||||
|
||||
const SEARCH_RELAYS = ["wss://relay.nostr.band", "wss://nostr.wine", "wss://search.nos.today"]
|
||||
const DVM_RELAYS = fromCsv(import.meta.env.VITE_DVM_RELAYS).map(normalizeRelayUrl)
|
||||
|
||||
const DEFAULT_RELAYS = fromCsv(import.meta.env.VITE_DEFAULT_RELAYS)
|
||||
const SEARCH_RELAYS = fromCsv(import.meta.env.VITE_SEARCH_RELAYS).map(normalizeRelayUrl)
|
||||
|
||||
const DEFAULT_RELAYS = fromCsv(import.meta.env.VITE_DEFAULT_RELAYS).map(normalizeRelayUrl)
|
||||
|
||||
const DEFAULT_FOLLOWS = fromCsv(import.meta.env.VITE_DEFAULT_FOLLOWS)
|
||||
|
||||
@ -62,6 +65,7 @@ env.set({
|
||||
DUFFLEPUD_URL,
|
||||
MULTIPLEXTR_URL,
|
||||
FORCE_GROUP,
|
||||
FORCE_RELAYS,
|
||||
DVM_RELAYS,
|
||||
SEARCH_RELAYS,
|
||||
DEFAULT_RELAYS,
|
||||
|
Loading…
Reference in New Issue
Block a user