-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
bookmark.go
64 lines (54 loc) · 1.2 KB
/
bookmark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"errors"
"github.com/urfave/cli/v2"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19"
)
func doBMList(cCtx *cli.Context) error {
n := cCtx.Int("n")
j := cCtx.Bool("json")
extra := cCtx.Bool("extra")
cfg := cCtx.App.Metadata["config"].(*Config)
// get followers
followsMap, err := cfg.GetFollows(cCtx.String("a"))
if err != nil {
return err
}
var sk string
var npub string
if _, s, err := nip19.Decode(cfg.PrivateKey); err == nil {
sk = s.(string)
} else {
return err
}
if npub, err = nostr.GetPublicKey(sk); err != nil {
return err
}
// get timeline
filter := nostr.Filter{
Kinds: []int{nostr.KindCategorizedBookmarksList},
Authors: []string{npub},
Tags: nostr.TagMap{"d": []string{"bookmark"}},
Limit: n,
}
be := []string{}
evs := cfg.Events(filter)
for _, ev := range evs {
for _, tag := range ev.Tags {
if len(tag) > 1 && tag[0] == "e" {
be = append(be, tag[1:]...)
}
}
}
filter = nostr.Filter{
Kinds: []int{nostr.KindTextNote},
IDs: be,
}
eevs := cfg.Events(filter)
cfg.PrintEvents(eevs, followsMap, j, extra)
return nil
}
func doBMPost(cCtx *cli.Context) error {
return errors.New("Not Implemented")
}