mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-08-29 15:22:28 +02:00
sdk: beginnings of basic wot helpers.
This commit is contained in:
44
sdk/wot.go
Normal file
44
sdk/wot.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"maps"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/FastFilter/xorfilter"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (sys *System) GetWoT(ctx context.Context, pubkey string) (map[uint64]struct{}, error) {
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
res := make(chan uint64)
|
||||
for _, f := range sys.FetchFollowList(ctx, pubkey).Items {
|
||||
g.Go(func() error {
|
||||
for _, f2 := range sys.FetchFollowList(ctx, f.Pubkey).Items {
|
||||
shid, _ := strconv.ParseUint(f2.Pubkey[32:48], 16, 64)
|
||||
res <- shid
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
result := make(map[uint64]struct{})
|
||||
go func() {
|
||||
for shid := range res {
|
||||
result[shid] = struct{}{}
|
||||
}
|
||||
}()
|
||||
|
||||
return result, g.Wait()
|
||||
}
|
||||
|
||||
func (sys *System) GetWoTFilter(ctx context.Context, pubkey string) (*xorfilter.Xor8, error) {
|
||||
m, err := sys.GetWoT(ctx, pubkey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return xorfilter.Populate(slices.Collect(maps.Keys(m)))
|
||||
}
|
Reference in New Issue
Block a user