Skip to content

Commit

Permalink
Merge pull request #28 from bitvora/dev-profileRefresh
Browse files Browse the repository at this point in the history
refresh profiles of the trust network
  • Loading branch information
barrydeen authored Sep 12, 2024
2 parents 5193f93 + 10b2e07 commit 434b3fb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ func updateTrustNetworkFilter() {
}
}

func refreshProfiles(ctx context.Context, relay *khatru.Relay) {
mu.Lock()
defer mu.Unlock()

for i := 0; i < len(trustNetwork); i += 200 {
timeout, cancel := context.WithTimeout(ctx, 4*time.Second)
defer cancel()

end := i + 200
if end > len(trustNetwork) {
end = len(trustNetwork)
}

filters := []nostr.Filter{{
Authors: trustNetwork[i:end],
Kinds: []int{nostr.KindProfileMetadata},
}}

for ev := range pool.SubManyEose(timeout, seedRelays, filters) {
relay.AddEvent(ctx, ev.Event)
log.Println("👤 profile updated: ", ev.Event.PubKey)
}
}
}

func refreshTrustNetwork(relay *khatru.Relay, ctx context.Context) {

runTrustNetworkRefresh := func() {
Expand Down Expand Up @@ -315,6 +340,7 @@ func appendOneHopNetwork(pubkey string) {

func archiveTrustedNotes(relay *khatru.Relay, ctx context.Context) {
timeout := time.After(time.Duration(config.RefreshInterval) * time.Hour)
go refreshProfiles(ctx, relay)

filters := []nostr.Filter{{
Kinds: []int{
Expand Down

0 comments on commit 434b3fb

Please sign in to comment.