-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
449 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nostrudel": patch | ||
--- | ||
|
||
Add explanations to relay views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import RelaySet from "../classes/relay-set"; | ||
import { safeRelayUrls } from "./relay"; | ||
|
||
export async function getRelaysFromExt() { | ||
if (!window.nostr) throw new Error("Missing extension"); | ||
const read = new RelaySet(); | ||
const write = new RelaySet(); | ||
const extRelays = (await window.nostr.getRelays?.()) ?? []; | ||
if (Array.isArray(extRelays)) { | ||
const safeUrls = safeRelayUrls(extRelays); | ||
read.merge(safeUrls); | ||
write.merge(safeUrls); | ||
} else { | ||
read.merge(safeRelayUrls(Object.keys(extRelays).filter((url) => extRelays[url].read))); | ||
write.merge(safeRelayUrls(Object.keys(extRelays).filter((url) => extRelays[url].write))); | ||
} | ||
|
||
return { read, write }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NostrEvent } from "nostr-tools"; | ||
import { RelayMode } from "../../classes/relay"; | ||
import { safeJson } from "../parse"; | ||
import { safeRelayUrl } from "../relay"; | ||
|
||
type RelayJson = Record<string, { read: boolean; write: boolean }>; | ||
export function relaysFromContactsEvent(event: NostrEvent) { | ||
const relayJson = safeJson(event.content, {}) as RelayJson; | ||
|
||
const relays: { url: string; mode: RelayMode }[] = []; | ||
for (const [url, opts] of Object.entries(relayJson)) { | ||
const safeUrl = safeRelayUrl(url); | ||
if (!safeUrl) continue; | ||
let mode = RelayMode.NONE; | ||
if (opts.write) mode = mode | RelayMode.WRITE; | ||
if (opts.read) mode = mode | RelayMode.READ; | ||
if (mode === RelayMode.NONE) mode = RelayMode.ALL; | ||
relays.push({ url: safeUrl, mode }); | ||
} | ||
return relays; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useMemo } from "react"; | ||
import { RequestOptions } from "../services/replaceable-event-requester"; | ||
import RelaySet from "../classes/relay-set"; | ||
import useUserContactList from "./use-user-contact-list"; | ||
import { RelayMode } from "../classes/relay"; | ||
import { relaysFromContactsEvent } from "../helpers/nostr/contacts"; | ||
|
||
export default function useUserContactRelays( | ||
pubkey?: string, | ||
additionalRelays?: Iterable<string>, | ||
opts: RequestOptions = {}, | ||
) { | ||
const contacts = useUserContactList(pubkey, additionalRelays, opts); | ||
|
||
return useMemo(() => { | ||
if (!contacts) return undefined; | ||
if (contacts.content.length === 0) return null; | ||
|
||
const relays = relaysFromContactsEvent(contacts); | ||
const inbox = new RelaySet(relays.filter((r) => r.mode & RelayMode.READ).map((r) => r.url)); | ||
const outbox = new RelaySet(relays.filter((r) => r.mode & RelayMode.WRITE).map((r) => r.url)); | ||
|
||
return { inbox, outbox }; | ||
}, [contacts]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useDnsIdentity } from "./use-dns-identity"; | ||
import { useUserMetadata } from "./use-user-metadata"; | ||
|
||
export function useUserDNSIdentity(pubkey?: string) { | ||
const metadata = useUserMetadata(pubkey); | ||
return useDnsIdentity(metadata?.nip05); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.