mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-17 19:13:56 +02:00
move nostr-sdk repository into here because why not?
This commit is contained in:
41
sdk/relays.go
Normal file
41
sdk/relays.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
type RelayList = GenericList[Relay]
|
||||
|
||||
type Relay struct {
|
||||
URL string
|
||||
Inbox bool
|
||||
Outbox bool
|
||||
}
|
||||
|
||||
func (r Relay) Value() string { return r.URL }
|
||||
|
||||
func parseRelayFromKind10002(tag nostr.Tag) (rl Relay, ok bool) {
|
||||
if u := tag.Value(); u != "" && tag[0] == "r" {
|
||||
if !nostr.IsValidRelayURL(u) {
|
||||
return rl, false
|
||||
}
|
||||
u := nostr.NormalizeURL(u)
|
||||
|
||||
relay := Relay{
|
||||
URL: u,
|
||||
}
|
||||
|
||||
if len(tag) == 2 {
|
||||
relay.Inbox = true
|
||||
relay.Outbox = true
|
||||
} else if tag[2] == "write" {
|
||||
relay.Outbox = true
|
||||
} else if tag[2] == "read" {
|
||||
relay.Inbox = true
|
||||
}
|
||||
|
||||
return relay, true
|
||||
}
|
||||
|
||||
return rl, false
|
||||
}
|
Reference in New Issue
Block a user