pointer.MatchesEvent()

This commit is contained in:
fiatjaf
2025-01-23 16:53:15 -03:00
parent 2d941907e3
commit 550cf835be

View File

@@ -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)
} }