Move getRelayUrls to getRelaysFromList

This commit is contained in:
Jon Staab
2025-04-24 17:10:41 -07:00
parent 3d1a6a106e
commit 3636064f25
6 changed files with 46 additions and 48 deletions
+13 -3
View File
@@ -1,7 +1,7 @@
import {parseJson, nthEq} from "@welshman/lib"
import {parseJson, uniq, nthEq} from "@welshman/lib"
import {Address} from "./Address.js"
import {uniqTags} from "./Tags.js"
import {isRelayUrl} from "./Relay.js"
import {uniqTags, getRelayTags} from "./Tags.js"
import {isRelayUrl, normalizeRelayUrl} from "./Relay.js"
import {Encryptable, DecryptedEvent} from "./Encryptable.js"
import type {EncryptableUpdates} from "./Encryptable.js"
@@ -88,3 +88,13 @@ export const addToListPrivately = (list: List, ...tags: string[][]) => {
content: JSON.stringify(uniqTags([...list.privateTags, ...tags])),
})
}
export const getRelaysFromList = (list?: List, mode?: string): string[] => {
let tags = getRelayTags(getListTags(list))
if (mode) {
tags = tags.filter((t: string[]) => !t[2] || t[2] === mode)
}
return uniq(tags.map(t => normalizeRelayUrl(t[1])))
}
+6
View File
@@ -2,6 +2,12 @@ import {last, normalizeUrl, stripProtocol} from "@welshman/lib"
// Constants and types
export enum RelayMode {
Read = "read",
Write = "write",
Inbox = "inbox",
}
export type RelayProfile = {
url: string
icon?: string