mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 14:54:24 +01:00
stop sending npubs to relays and use hints when fetching notes.
This commit is contained in:
19
nostr.go
19
nostr.go
@@ -121,12 +121,17 @@ func getEvent(ctx context.Context, code string) (*nostr.Event, error) {
|
||||
return nil, fmt.Errorf("couldn't find this %s", prefix)
|
||||
}
|
||||
|
||||
func getLastNotes(ctx context.Context, pubkey string) ([]nostr.Event, error) {
|
||||
func getLastNotes(ctx context.Context, code string) []*nostr.Event {
|
||||
pp := sdk.InputToProfile(ctx, code)
|
||||
if pp == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Millisecond*1500)
|
||||
defer cancel()
|
||||
|
||||
relays := make([]string, 0, 20)
|
||||
for _, relay := range sdk.FetchRelaysForPubkey(ctx, pool, pubkey, relays...) {
|
||||
relays := pp.Relays
|
||||
for _, relay := range sdk.FetchRelaysForPubkey(ctx, pool, pp.PublicKey, pp.Relays...) {
|
||||
if relay.Outbox {
|
||||
relays = append(relays, relay.URL)
|
||||
}
|
||||
@@ -140,13 +145,13 @@ func getLastNotes(ctx context.Context, pubkey string) ([]nostr.Event, error) {
|
||||
events := pool.SubManyEose(ctx, relays, nostr.Filters{
|
||||
{
|
||||
Kinds: []int{nostr.KindTextNote},
|
||||
Authors: []string{pubkey},
|
||||
Authors: []string{pp.PublicKey},
|
||||
Limit: 20,
|
||||
},
|
||||
})
|
||||
lastNotes := make([]nostr.Event, 0, 20)
|
||||
lastNotes := make([]*nostr.Event, 0, 20)
|
||||
for event := range events {
|
||||
lastNotes = append(lastNotes, *event)
|
||||
lastNotes = append(lastNotes, event)
|
||||
}
|
||||
return lastNotes, nil
|
||||
return lastNotes
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if event.Kind == 0 {
|
||||
typ = "profile"
|
||||
thisLastNotes, err := getLastNotes(r.Context(), code)
|
||||
thisLastNotes := getLastNotes(r.Context(), code)
|
||||
lastNotes = make([]Event, len(thisLastNotes))
|
||||
for i, n := range thisLastNotes {
|
||||
this_nevent, _ := nip19.EncodeEvent(n.ID, []string{}, n.PubKey)
|
||||
@@ -80,7 +80,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
Nevent: this_nevent,
|
||||
Content: n.Content,
|
||||
CreatedAt: this_date,
|
||||
ParentNevent: findParentNevent(&n),
|
||||
ParentNevent: getParentNevent(n),
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@@ -93,7 +93,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
typ = "note"
|
||||
note, _ = nip19.EncodeNote(event.ID)
|
||||
content = event.Content
|
||||
parentNevent = findParentNevent(event)
|
||||
parentNevent = getParentNevent(event)
|
||||
} else if event.Kind == 6 {
|
||||
typ = "note"
|
||||
if reposted := event.Tags.GetFirst([]string{"e", ""}); reposted != nil {
|
||||
|
||||
Reference in New Issue
Block a user