feat: allow changing default relays
This commit is contained in:
parent
36959a1052
commit
53a67d8233
44 changed files with 356 additions and 92 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import { BIG_RELAY_URLS } from '@/constants'
|
||||
import { createFavoriteRelaysDraftEvent, createRelaySetDraftEvent } from '@/lib/draft-event'
|
||||
import { getReplaceableEventIdentifier } from '@/lib/event'
|
||||
import { getRelaySetFromEvent } from '@/lib/event-metadata'
|
||||
import { randomString } from '@/lib/random'
|
||||
import { getDefaultRelayUrls } from '@/lib/relay'
|
||||
import { isWebsocketUrl, normalizeUrl } from '@/lib/url'
|
||||
import client from '@/services/client.service'
|
||||
import indexedDb from '@/services/indexed-db.service'
|
||||
|
|
@ -94,7 +94,7 @@ export function FavoriteRelaysProvider({ children }: { children: React.ReactNode
|
|||
setRelaySetEvents(storedRelaySetEvents.filter(Boolean) as Event[])
|
||||
|
||||
const newRelaySetEvents = await client.fetchEvents(
|
||||
(relayList?.write ?? []).concat(BIG_RELAY_URLS).slice(0, 5),
|
||||
(relayList?.write ?? []).concat(getDefaultRelayUrls()).slice(0, 5),
|
||||
{
|
||||
kinds: [kinds.Relaysets],
|
||||
authors: [pubkey],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import LoginDialog from '@/components/LoginDialog'
|
||||
import PasswordInputDialog from '@/components/PasswordInputDialog'
|
||||
import { ApplicationDataKey, BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
||||
import { ApplicationDataKey, ExtendedKind } from '@/constants'
|
||||
import {
|
||||
createDeletionRequestDraftEvent,
|
||||
createFollowListDraftEvent,
|
||||
|
|
@ -16,6 +16,7 @@ import {
|
|||
} from '@/lib/event'
|
||||
import { getProfileFromEvent, getRelayListFromEvent } from '@/lib/event-metadata'
|
||||
import { formatPubkey, pubkeyToNpub } from '@/lib/pubkey'
|
||||
import { getDefaultRelayUrls } from '@/lib/relay'
|
||||
import client from '@/services/client.service'
|
||||
import customEmojiService from '@/services/custom-emoji.service'
|
||||
import indexedDb from '@/services/indexed-db.service'
|
||||
|
|
@ -246,7 +247,8 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
setPinnedUsersEvent(storedPinnedUsersEvent)
|
||||
}
|
||||
|
||||
const relayListEvents = await client.fetchEvents(BIG_RELAY_URLS, {
|
||||
const defaultRelays = getDefaultRelayUrls()
|
||||
const relayListEvents = await client.fetchEvents(defaultRelays, {
|
||||
kinds: [kinds.RelayList],
|
||||
authors: [account.pubkey]
|
||||
})
|
||||
|
|
@ -258,7 +260,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
}
|
||||
setRelayList(relayList)
|
||||
|
||||
const events = await client.fetchEvents(relayList.write.concat(BIG_RELAY_URLS).slice(0, 4), [
|
||||
const events = await client.fetchEvents(relayList.write.concat(defaultRelays).slice(0, 4), [
|
||||
{
|
||||
kinds: [
|
||||
kinds.Metadata,
|
||||
|
|
@ -637,13 +639,14 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
}
|
||||
|
||||
const setupNewUser = async (signer: ISigner) => {
|
||||
const defaultRelays = getDefaultRelayUrls()
|
||||
await Promise.allSettled([
|
||||
client.publishEvent(BIG_RELAY_URLS, await signer.signEvent(createFollowListDraftEvent([]))),
|
||||
client.publishEvent(BIG_RELAY_URLS, await signer.signEvent(createMuteListDraftEvent([]))),
|
||||
client.publishEvent(defaultRelays, await signer.signEvent(createFollowListDraftEvent([]))),
|
||||
client.publishEvent(defaultRelays, await signer.signEvent(createMuteListDraftEvent([]))),
|
||||
client.publishEvent(
|
||||
BIG_RELAY_URLS,
|
||||
defaultRelays,
|
||||
await signer.signEvent(
|
||||
createRelayListDraftEvent(BIG_RELAY_URLS.map((url) => ({ url, scope: 'both' })))
|
||||
createRelayListDraftEvent(defaultRelays.map((url) => ({ url, scope: 'both' })))
|
||||
)
|
||||
)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
||||
import { ExtendedKind } from '@/constants'
|
||||
import { compareEvents } from '@/lib/event'
|
||||
import { notificationFilter } from '@/lib/notification'
|
||||
import { getDefaultRelayUrls } from '@/lib/relay'
|
||||
import { usePrimaryPage } from '@/PageManager'
|
||||
import client from '@/services/client.service'
|
||||
import storage from '@/services/local-storage.service'
|
||||
|
|
@ -103,7 +104,8 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
|
|||
try {
|
||||
let eosed = false
|
||||
const relayList = await client.fetchRelayList(pubkey)
|
||||
const relays = relayList.read.length > 0 ? relayList.read.slice(0, 5) : BIG_RELAY_URLS
|
||||
const relays =
|
||||
relayList.read.length > 0 ? relayList.read.slice(0, 5) : getDefaultRelayUrls()
|
||||
const subCloser = client.subscribe(
|
||||
relays,
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue