mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-01 02:30:06 +02:00
- make BatchedSubManyEose() use a single duplicate id index and use it for replaceable loaders; - fixes parsing follow entry from kind:3 events (and others); - adds a "cause" to most cancelation errors in relay/pool; - remove the inherent cache from dataloader (we have our own hopefully); - increase max frame size we can read from any websocket to 2**18 (262k), which gives over 2000 item lists.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package sdk
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/nbd-wtf/go-nostr"
|
|
)
|
|
|
|
type ProfileRef struct {
|
|
Pubkey string
|
|
Relay string
|
|
Petname string
|
|
}
|
|
|
|
func (f ProfileRef) Value() string { return f.Pubkey }
|
|
|
|
func (sys *System) FetchFollowList(ctx context.Context, pubkey string) GenericList[ProfileRef] {
|
|
fl, _ := fetchGenericList(sys, ctx, pubkey, 3, kind_3, parseProfileRef, sys.FollowListCache)
|
|
return fl
|
|
}
|
|
|
|
func (sys *System) FetchMuteList(ctx context.Context, pubkey string) GenericList[ProfileRef] {
|
|
ml, _ := fetchGenericList(sys, ctx, pubkey, 10000, kind_10000, parseProfileRef, sys.MuteListCache)
|
|
return ml
|
|
}
|
|
|
|
func (sys *System) FetchFollowSets(ctx context.Context, pubkey string) GenericSets[ProfileRef] {
|
|
ml, _ := fetchGenericSets(sys, ctx, pubkey, 30000, kind_30000, parseProfileRef, sys.FollowSetsCache)
|
|
return ml
|
|
}
|
|
|
|
func parseProfileRef(tag nostr.Tag) (fw ProfileRef, ok bool) {
|
|
if len(tag) < 2 {
|
|
return fw, false
|
|
}
|
|
if tag[0] != "p" {
|
|
return fw, false
|
|
}
|
|
|
|
fw.Pubkey = tag[1]
|
|
if !nostr.IsValidPublicKey(fw.Pubkey) {
|
|
return fw, false
|
|
}
|
|
|
|
if len(tag) > 2 {
|
|
if _, err := url.Parse(tag[2]); err == nil {
|
|
fw.Relay = nostr.NormalizeURL(tag[2])
|
|
}
|
|
|
|
if len(tag) > 3 {
|
|
fw.Petname = strings.TrimSpace(tag[3])
|
|
}
|
|
}
|
|
|
|
return fw, true
|
|
}
|