mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-19 02:26:34 +01:00
some mildly useful helpers for pointers in general.
This commit is contained in:
42
pointers.go
42
pointers.go
@@ -1,10 +1,28 @@
|
|||||||
package nostr
|
package nostr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Pointer interface {
|
||||||
|
AsTagReference() string
|
||||||
|
AsTag() Tag
|
||||||
|
}
|
||||||
|
|
||||||
type ProfilePointer struct {
|
type ProfilePointer struct {
|
||||||
PublicKey string `json:"pubkey"`
|
PublicKey string `json:"pubkey"`
|
||||||
Relays []string `json:"relays,omitempty"`
|
Relays []string `json:"relays,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep ProfilePointer) AsTagReference() string { return ep.PublicKey }
|
||||||
|
|
||||||
|
func (ep ProfilePointer) AsTag() Tag {
|
||||||
|
if len(ep.Relays) > 0 {
|
||||||
|
return Tag{"p", ep.PublicKey, ep.Relays[0]}
|
||||||
|
}
|
||||||
|
return Tag{"p", ep.PublicKey}
|
||||||
|
}
|
||||||
|
|
||||||
type EventPointer struct {
|
type EventPointer struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Relays []string `json:"relays,omitempty"`
|
Relays []string `json:"relays,omitempty"`
|
||||||
@@ -12,9 +30,33 @@ type EventPointer struct {
|
|||||||
Kind int `json:"kind,omitempty"`
|
Kind int `json:"kind,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep EventPointer) AsTagReference() string { return ep.ID }
|
||||||
|
|
||||||
|
func (ep EventPointer) AsTag() Tag {
|
||||||
|
if len(ep.Relays) > 0 {
|
||||||
|
if ep.Author != "" {
|
||||||
|
return Tag{"e", ep.ID, ep.Relays[0], ep.Author}
|
||||||
|
} else {
|
||||||
|
return Tag{"e", ep.ID, ep.Relays[0]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Tag{"e", ep.ID}
|
||||||
|
}
|
||||||
|
|
||||||
type EntityPointer struct {
|
type EntityPointer struct {
|
||||||
PublicKey string `json:"pubkey"`
|
PublicKey string `json:"pubkey"`
|
||||||
Kind int `json:"kind,omitempty"`
|
Kind int `json:"kind,omitempty"`
|
||||||
Identifier string `json:"identifier,omitempty"`
|
Identifier string `json:"identifier,omitempty"`
|
||||||
Relays []string `json:"relays,omitempty"`
|
Relays []string `json:"relays,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep EntityPointer) AsTagReference() string {
|
||||||
|
return fmt.Sprintf("%d:%s:%s", ep.Kind, ep.PublicKey, ep.Identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ep EntityPointer) AsTag() Tag {
|
||||||
|
if len(ep.Relays) > 0 {
|
||||||
|
return Tag{"a", ep.AsTagReference(), ep.Relays[0]}
|
||||||
|
}
|
||||||
|
return Tag{"a", ep.AsTagReference()}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user