forked from dtonon/chronicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.go
86 lines (77 loc) · 1.85 KB
/
archive.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"context"
"log"
"time"
"github.com/fiatjaf/khatru"
"github.com/nbd-wtf/go-nostr"
)
var seedRelays = []string{
"wss://nos.lol",
"wss://nostr.mom",
"wss://purplepag.es",
"wss://purplerelay.com",
"wss://relay.damus.io",
"wss://relay.nostr.band",
"wss://relay.snort.social",
"wss://relayable.org",
"wss://relay.primal.net",
"wss://relay.nostr.bg",
"wss://no.str.cr",
"wss://nostr21.com",
"wss://nostrue.com",
"wss://relay.siamstr.com",
"wss://bitcoiner.social",
}
func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
timeout, cancel := context.WithTimeout(ctx, time.Duration(config.RefreshInterval)*time.Hour)
defer cancel()
go func() {
filters := []nostr.Filter{
{
Kinds: []int{
nostr.KindArticle,
nostr.KindDeletion,
nostr.KindEncryptedDirectMessage,
nostr.KindReaction,
nostr.KindRepost,
nostr.KindZapRequest,
nostr.KindZap,
nostr.KindTextNote,
},
Authors: []string{config.OwnerPubkey},
},
{
Kinds: []int{
nostr.KindArticle,
nostr.KindTextNote,
nostr.KindDeletion,
nostr.KindEncryptedDirectMessage,
nostr.KindReaction,
nostr.KindRepost,
nostr.KindZapRequest,
nostr.KindZap,
nostr.KindGiftWrap,
},
Tags: nostr.TagMap{"p": []string{config.OwnerPubkey}},
},
}
log.Println("📦 Archiving trusted notes...")
for ev := range pool.SubMany(timeout, seedRelays, filters) {
archiveEvent(ctx, relay, *ev.Event)
}
}()
<-timeout.Done()
log.Println("📦 Archived", trustedNotes, "trusted notes, discarded", untrustedNotes, "notes")
}
func archiveEvent(ctx context.Context, relay *khatru.Relay, event nostr.Event) {
if acceptedEvent(event) {
addEventToRootList(event)
fetchQuotedEvents(event)
wdb.Publish(ctx, event)
relay.BroadcastEvent(&event)
trustedNotes++
} else {
untrustedNotes++
}
}