refactor: 🏗️
This commit is contained in:
@@ -81,10 +81,10 @@ export function getFollowingsFromFollowListEvent(event: Event) {
|
||||
|
||||
export function getRelayListFromRelayListEvent(event?: Event) {
|
||||
if (!event) {
|
||||
return { write: BIG_RELAY_URLS, read: BIG_RELAY_URLS }
|
||||
return { write: BIG_RELAY_URLS, read: BIG_RELAY_URLS, originalRelays: [] }
|
||||
}
|
||||
|
||||
const relayList = { write: [], read: [] } as TRelayList
|
||||
const relayList = { write: [], read: [], originalRelays: [] } as TRelayList
|
||||
event.tags.filter(tagNameEquals('r')).forEach(([, url, type]) => {
|
||||
if (!url || !isWebsocketUrl(url)) return
|
||||
|
||||
@@ -92,18 +92,22 @@ export function getRelayListFromRelayListEvent(event?: Event) {
|
||||
switch (type) {
|
||||
case 'write':
|
||||
relayList.write.push(normalizedUrl)
|
||||
relayList.originalRelays.push({ url: normalizedUrl, scope: 'write' })
|
||||
break
|
||||
case 'read':
|
||||
relayList.read.push(normalizedUrl)
|
||||
relayList.originalRelays.push({ url: normalizedUrl, scope: 'read' })
|
||||
break
|
||||
default:
|
||||
relayList.write.push(normalizedUrl)
|
||||
relayList.read.push(normalizedUrl)
|
||||
relayList.originalRelays.push({ url: normalizedUrl, scope: 'both' })
|
||||
}
|
||||
})
|
||||
return {
|
||||
write: relayList.write.length ? relayList.write : BIG_RELAY_URLS,
|
||||
read: relayList.read.length ? relayList.read : BIG_RELAY_URLS
|
||||
read: relayList.read.length ? relayList.read : BIG_RELAY_URLS,
|
||||
originalRelays: relayList.originalRelays
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TMailboxRelay, TRelayInfo, TRelayList } from '@/types'
|
||||
import { TRelayInfo } from '@/types'
|
||||
|
||||
export function checkAlgoRelay(relayInfo: TRelayInfo | undefined) {
|
||||
return relayInfo?.software === 'https://github.com/bitvora/algo-relay' // hardcode for now
|
||||
@@ -7,16 +7,3 @@ 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user