Skip to content

Commit

Permalink
Add NIP-22 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dtonon committed Jan 1, 2025
1 parent ef0717a commit f4b2cd3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions kinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
KindChannelMuteUser int = 44
KindChess int = 64
KindMergeRequests int = 818
KindComment int = 1111
KindBid int = 1021
KindBidConfirmation int = 1022
KindOpenTimestamps int = 1040
Expand Down
24 changes: 24 additions & 0 deletions nip22/nip22.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nip22

import "github.com/nbd-wtf/go-nostr"

func GetThreadRoot(tags nostr.Tags) *nostr.Tag {
for _, tag := range tags {
if tag[0] == "E" || tag[0] == "A" || tag[0] == "I" {
return &tag
}
}
empty := nostr.Tag{}
return &empty
}

func GetImmediateReply(tags nostr.Tags) *nostr.Tag {
for _, tag := range tags {
if tag[0] == "e" || tag[0] == "a" || tag[0] == "i" {
return &tag
}
}

empty := nostr.Tag{}
return &empty
}
23 changes: 23 additions & 0 deletions sdk/thread.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sdk

import (
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip10"
"github.com/nbd-wtf/go-nostr/nip22"
)

func GetThreadRoot(evt *nostr.Event) *nostr.Tag {
if evt.Kind == nostr.KindComment {
return nip22.GetThreadRoot(evt.Tags)
} else {
return nip10.GetThreadRoot(evt.Tags)
}
}

func GetImmediateReply(evt *nostr.Event) *nostr.Tag {
if evt.Kind == nostr.KindComment {
return nip22.GetImmediateReply(evt.Tags)
} else {
return nip10.GetImmediateReply(evt.Tags)
}
}

0 comments on commit f4b2cd3

Please sign in to comment.