mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-08-31 08:11:35 +02:00
pointer.MatchesEvent()
This commit is contained in:
13
pointers.go
13
pointers.go
@@ -7,6 +7,7 @@ import (
|
|||||||
type Pointer interface {
|
type Pointer interface {
|
||||||
AsTagReference() string
|
AsTagReference() string
|
||||||
AsTag() Tag
|
AsTag() Tag
|
||||||
|
MatchesEvent(Event) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfilePointer struct {
|
type ProfilePointer struct {
|
||||||
@@ -14,7 +15,8 @@ type ProfilePointer struct {
|
|||||||
Relays []string `json:"relays,omitempty"`
|
Relays []string `json:"relays,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep ProfilePointer) AsTagReference() string { return ep.PublicKey }
|
func (ep ProfilePointer) MatchesEvent(_ Event) bool { return false }
|
||||||
|
func (ep ProfilePointer) AsTagReference() string { return ep.PublicKey }
|
||||||
|
|
||||||
func (ep ProfilePointer) AsTag() Tag {
|
func (ep ProfilePointer) AsTag() Tag {
|
||||||
if len(ep.Relays) > 0 {
|
if len(ep.Relays) > 0 {
|
||||||
@@ -30,7 +32,8 @@ type EventPointer struct {
|
|||||||
Kind int `json:"kind,omitempty"`
|
Kind int `json:"kind,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep EventPointer) AsTagReference() string { return ep.ID }
|
func (ep EventPointer) MatchesEvent(evt Event) bool { return evt.ID == ep.ID }
|
||||||
|
func (ep EventPointer) AsTagReference() string { return ep.ID }
|
||||||
|
|
||||||
func (ep EventPointer) AsTag() Tag {
|
func (ep EventPointer) AsTag() Tag {
|
||||||
if len(ep.Relays) > 0 {
|
if len(ep.Relays) > 0 {
|
||||||
@@ -50,6 +53,12 @@ type EntityPointer struct {
|
|||||||
Relays []string `json:"relays,omitempty"`
|
Relays []string `json:"relays,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep EntityPointer) MatchesEvent(evt Event) bool {
|
||||||
|
return ep.PublicKey == evt.PubKey &&
|
||||||
|
ep.Kind == evt.Kind &&
|
||||||
|
evt.Tags.GetD() == ep.Identifier
|
||||||
|
}
|
||||||
|
|
||||||
func (ep EntityPointer) AsTagReference() string {
|
func (ep EntityPointer) AsTagReference() string {
|
||||||
return fmt.Sprintf("%d:%s:%s", ep.Kind, ep.PublicKey, ep.Identifier)
|
return fmt.Sprintf("%d:%s:%s", ep.Kind, ep.PublicKey, ep.Identifier)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user