2023-02-05 16:25:00 -03:00
|
|
|
package nostr
|
|
|
|
|
2025-01-01 15:04:54 -03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Pointer interface {
|
|
|
|
AsTagReference() string
|
|
|
|
AsTag() Tag
|
2025-01-23 16:53:15 -03:00
|
|
|
MatchesEvent(Event) bool
|
2025-01-01 15:04:54 -03:00
|
|
|
}
|
|
|
|
|
2023-02-05 16:25:00 -03:00
|
|
|
type ProfilePointer struct {
|
2023-05-04 08:22:17 -03:00
|
|
|
PublicKey string `json:"pubkey"`
|
|
|
|
Relays []string `json:"relays,omitempty"`
|
2023-02-05 16:25:00 -03:00
|
|
|
}
|
|
|
|
|
2025-01-23 16:53:15 -03:00
|
|
|
func (ep ProfilePointer) MatchesEvent(_ Event) bool { return false }
|
|
|
|
func (ep ProfilePointer) AsTagReference() string { return ep.PublicKey }
|
2025-01-01 15:04:54 -03:00
|
|
|
|
|
|
|
func (ep ProfilePointer) AsTag() Tag {
|
|
|
|
if len(ep.Relays) > 0 {
|
|
|
|
return Tag{"p", ep.PublicKey, ep.Relays[0]}
|
|
|
|
}
|
|
|
|
return Tag{"p", ep.PublicKey}
|
|
|
|
}
|
|
|
|
|
2023-02-05 16:25:00 -03:00
|
|
|
type EventPointer struct {
|
2023-05-04 08:22:17 -03:00
|
|
|
ID string `json:"id"`
|
|
|
|
Relays []string `json:"relays,omitempty"`
|
|
|
|
Author string `json:"author,omitempty"`
|
|
|
|
Kind int `json:"kind,omitempty"`
|
2023-02-05 16:25:00 -03:00
|
|
|
}
|
2023-02-27 16:15:04 -03:00
|
|
|
|
2025-01-23 16:53:15 -03:00
|
|
|
func (ep EventPointer) MatchesEvent(evt Event) bool { return evt.ID == ep.ID }
|
|
|
|
func (ep EventPointer) AsTagReference() string { return ep.ID }
|
2025-01-01 15:04:54 -03:00
|
|
|
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2023-02-27 16:15:04 -03:00
|
|
|
type EntityPointer struct {
|
2023-05-04 08:22:17 -03:00
|
|
|
PublicKey string `json:"pubkey"`
|
|
|
|
Kind int `json:"kind,omitempty"`
|
|
|
|
Identifier string `json:"identifier,omitempty"`
|
|
|
|
Relays []string `json:"relays,omitempty"`
|
2023-02-27 16:15:04 -03:00
|
|
|
}
|
2025-01-01 15:04:54 -03:00
|
|
|
|
2025-01-23 16:53:15 -03:00
|
|
|
func (ep EntityPointer) MatchesEvent(evt Event) bool {
|
|
|
|
return ep.PublicKey == evt.PubKey &&
|
|
|
|
ep.Kind == evt.Kind &&
|
|
|
|
evt.Tags.GetD() == ep.Identifier
|
|
|
|
}
|
|
|
|
|
2025-01-01 15:04:54 -03:00
|
|
|
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()}
|
|
|
|
}
|