Normalize relay urls before putting them in the database
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import {uniq} from '@welshman/lib'
|
||||
import {INBOX_RELAYS, RELAYS, getRelayTags, normalizeRelayUrl, type TrustedEvent} from '@welshman/util'
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {deriveEvents, withGetter} from '@welshman/store'
|
||||
@@ -5,18 +6,24 @@ import {load, repository} from './core'
|
||||
import {collection} from './collection'
|
||||
|
||||
export const getRelayUrls = (event?: TrustedEvent): string[] =>
|
||||
getRelayTags(event?.tags || [])
|
||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||
uniq(
|
||||
getRelayTags(event?.tags || [])
|
||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||
)
|
||||
|
||||
export const getReadRelayUrls = (event?: TrustedEvent): string[] =>
|
||||
getRelayTags(event?.tags || [])
|
||||
.filter((t: string[]) => !t[2] || t[2] === "read")
|
||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||
uniq(
|
||||
getRelayTags(event?.tags || [])
|
||||
.filter((t: string[]) => !t[2] || t[2] === "read")
|
||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||
)
|
||||
|
||||
export const getWriteRelayUrls = (event?: TrustedEvent): string[] =>
|
||||
getRelayTags(event?.tags || [])
|
||||
.filter((t: string[]) => !t[2] || t[2] === "write")
|
||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||
uniq(
|
||||
getRelayTags(event?.tags || [])
|
||||
.filter((t: string[]) => !t[2] || t[2] === "write")
|
||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||
)
|
||||
|
||||
export const relaySelections = withGetter(deriveEvents(repository, {filters: [{kinds: [RELAYS]}]}))
|
||||
|
||||
@@ -24,6 +31,7 @@ export const {
|
||||
indexStore: relaySelectionsByPubkey,
|
||||
deriveItem: deriveRelaySelections,
|
||||
loadItem: loadRelaySelections,
|
||||
getItem: getRelaySelections,
|
||||
} = collection({
|
||||
name: "relaySelections",
|
||||
store: relaySelections,
|
||||
@@ -38,6 +46,7 @@ export const {
|
||||
indexStore: inboxRelaySelectionsByPubkey,
|
||||
deriveItem: deriveInboxRelaySelections,
|
||||
loadItem: loadInboxRelaySelections,
|
||||
getItem: getInboxRelaySelections,
|
||||
} = collection({
|
||||
name: "inboxRelaySelections",
|
||||
store: inboxRelaySelections,
|
||||
|
||||
Reference in New Issue
Block a user