move ExternalPointer to nip73 and write nip27.Parse() that gets all the parts of the text including URLs, Nostr URIs and just raw text.

This commit is contained in:
fiatjaf
2025-03-21 23:43:23 -03:00
parent 3ebfc7812b
commit e18528c043
6 changed files with 232 additions and 22 deletions

23
nip73/pointer.go Normal file
View File

@@ -0,0 +1,23 @@
package nip73
import "github.com/nbd-wtf/go-nostr"
var _ nostr.Pointer = (*ExternalPointer)(nil)
// ExternalPointer represents a pointer to a URL or something else.
type ExternalPointer struct {
Thing string
}
// ExternalPointerFromTag creates a ExternalPointer from an "i" tag
func ExternalPointerFromTag(refTag nostr.Tag) (ExternalPointer, error) {
return ExternalPointer{refTag[1]}, nil
}
func (ep ExternalPointer) MatchesEvent(_ nostr.Event) bool { return false }
func (ep ExternalPointer) AsTagReference() string { return ep.Thing }
func (ep ExternalPointer) AsFilter() nostr.Filter { return nostr.Filter{} }
func (ep ExternalPointer) AsTag() nostr.Tag {
return nostr.Tag{"i", ep.Thing}
}