feat: others relays

This commit is contained in:
codytseng
2025-01-17 12:07:22 +08:00
parent 6543f29529
commit 64a5573969
12 changed files with 174 additions and 36 deletions

View File

@@ -90,10 +90,10 @@ export function getRelayListFromRelayListEvent(event?: Event) {
const normalizedUrl = normalizeUrl(url)
switch (type) {
case 'w':
case 'write':
relayList.write.push(normalizedUrl)
break
case 'r':
case 'read':
relayList.read.push(normalizedUrl)
break
default:
@@ -102,8 +102,8 @@ export function getRelayListFromRelayListEvent(event?: Event) {
}
})
return {
write: relayList.write.length ? relayList.write.slice(0, 10) : BIG_RELAY_URLS,
read: relayList.read.length ? relayList.read.slice(0, 10) : BIG_RELAY_URLS
write: relayList.write.length ? relayList.write : BIG_RELAY_URLS,
read: relayList.read.length ? relayList.read : BIG_RELAY_URLS
}
}

View File

@@ -37,6 +37,10 @@ export const toFollowingList = (pubkey: string) => {
const npub = nip19.npubEncode(pubkey)
return `/users/${npub}/following`
}
export const toOthersRelaySettings = (pubkey: string) => {
const npub = nip19.npubEncode(pubkey)
return `/users/${npub}/relays`
}
export const toRelaySettings = () => '/relay-settings'
export const toSettings = () => '/settings'
export const toProfileEditor = () => '/profile-editor'

View File

@@ -1,4 +1,4 @@
import { TRelayInfo } from '@/types'
import { TMailboxRelay, TRelayInfo, TRelayList } from '@/types'
export function checkAlgoRelay(relayInfo: TRelayInfo | undefined) {
return relayInfo?.software === 'https://github.com/bitvora/algo-relay' // hardcode for now
@@ -7,3 +7,16 @@ export function checkAlgoRelay(relayInfo: TRelayInfo | undefined) {
export function checkSearchRelay(relayInfo: TRelayInfo | undefined) {
return relayInfo?.supported_nips?.includes(50)
}
export function relayListToMailboxRelay(relayList: TRelayList): TMailboxRelay[] {
const mailboxRelays: TMailboxRelay[] = relayList.read.map((url) => ({ url, scope: 'read' }))
relayList.write.forEach((url) => {
const item = mailboxRelays.find((r) => r.url === url)
if (item) {
item.scope = 'both'
} else {
mailboxRelays.push({ url, scope: 'write' })
}
})
return mailboxRelays
}