mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 00:59:07 -04:00
fetch: use relay hints from author pubkeys.
This commit is contained in:
parent
db157e6181
commit
459b127988
21
fetch.go
21
fetch.go
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nip19"
|
||||
"github.com/nbd-wtf/go-nostr/sdk"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -24,12 +25,14 @@ var fetch = &cli.Command{
|
|||
}
|
||||
|
||||
var relays []string
|
||||
var authorHint string
|
||||
|
||||
switch prefix {
|
||||
case "nevent":
|
||||
v := value.(nostr.EventPointer)
|
||||
filter.IDs = append(filter.IDs, v.ID)
|
||||
if v.Author != "" {
|
||||
// TODO fetch relays from nip65
|
||||
authorHint = v.Author
|
||||
}
|
||||
relays = v.Relays
|
||||
case "naddr":
|
||||
|
@ -37,20 +40,30 @@ var fetch = &cli.Command{
|
|||
filter.Tags = nostr.TagMap{"d": []string{v.Identifier}}
|
||||
filter.Kinds = append(filter.Kinds, v.Kind)
|
||||
filter.Authors = append(filter.Authors, v.PublicKey)
|
||||
// TODO fetch relays from nip65
|
||||
authorHint = v.PublicKey
|
||||
relays = v.Relays
|
||||
case "nprofile":
|
||||
v := value.(nostr.ProfilePointer)
|
||||
filter.Authors = append(filter.Authors, v.PublicKey)
|
||||
// TODO fetch relays from nip65
|
||||
authorHint = v.PublicKey
|
||||
relays = v.Relays
|
||||
}
|
||||
|
||||
pool := nostr.NewSimplePool(c.Context)
|
||||
if authorHint != "" {
|
||||
relayList := sdk.FetchRelaysForPubkey(c.Context, pool, authorHint,
|
||||
"wss://purplepag.es", "wss://offchain.pub", "wss://public.relaying.io")
|
||||
for _, relayListItem := range relayList {
|
||||
if relayListItem.Outbox {
|
||||
relays = append(relays, relayListItem.URL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(relays) == 0 {
|
||||
return fmt.Errorf("no relay hints found")
|
||||
}
|
||||
|
||||
pool := nostr.NewSimplePool(c.Context)
|
||||
for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) {
|
||||
fmt.Println(ie.Event)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user