mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-19 07:14: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)
|
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)
|
ctx, cancel := context.WithTimeout(ctx, time.Millisecond*1500)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
relays := make([]string, 0, 20)
|
relays := pp.Relays
|
||||||
for _, relay := range sdk.FetchRelaysForPubkey(ctx, pool, pubkey, relays...) {
|
for _, relay := range sdk.FetchRelaysForPubkey(ctx, pool, pp.PublicKey, pp.Relays...) {
|
||||||
if relay.Outbox {
|
if relay.Outbox {
|
||||||
relays = append(relays, relay.URL)
|
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{
|
events := pool.SubManyEose(ctx, relays, nostr.Filters{
|
||||||
{
|
{
|
||||||
Kinds: []int{nostr.KindTextNote},
|
Kinds: []int{nostr.KindTextNote},
|
||||||
Authors: []string{pubkey},
|
Authors: []string{pp.PublicKey},
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
lastNotes := make([]nostr.Event, 0, 20)
|
lastNotes := make([]*nostr.Event, 0, 20)
|
||||||
for event := range events {
|
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 {
|
if event.Kind == 0 {
|
||||||
typ = "profile"
|
typ = "profile"
|
||||||
thisLastNotes, err := getLastNotes(r.Context(), code)
|
thisLastNotes := getLastNotes(r.Context(), code)
|
||||||
lastNotes = make([]Event, len(thisLastNotes))
|
lastNotes = make([]Event, len(thisLastNotes))
|
||||||
for i, n := range thisLastNotes {
|
for i, n := range thisLastNotes {
|
||||||
this_nevent, _ := nip19.EncodeEvent(n.ID, []string{}, n.PubKey)
|
this_nevent, _ := nip19.EncodeEvent(n.ID, []string{}, n.PubKey)
|
||||||
@@ -80,7 +80,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
Nevent: this_nevent,
|
Nevent: this_nevent,
|
||||||
Content: n.Content,
|
Content: n.Content,
|
||||||
CreatedAt: this_date,
|
CreatedAt: this_date,
|
||||||
ParentNevent: findParentNevent(&n),
|
ParentNevent: getParentNevent(n),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,7 +93,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
typ = "note"
|
typ = "note"
|
||||||
note, _ = nip19.EncodeNote(event.ID)
|
note, _ = nip19.EncodeNote(event.ID)
|
||||||
content = event.Content
|
content = event.Content
|
||||||
parentNevent = findParentNevent(event)
|
parentNevent = getParentNevent(event)
|
||||||
} else if event.Kind == 6 {
|
} else if event.Kind == 6 {
|
||||||
typ = "note"
|
typ = "note"
|
||||||
if reposted := event.Tags.GetFirst([]string{"e", ""}); reposted != nil {
|
if reposted := event.Tags.GetFirst([]string{"e", ""}); reposted != nil {
|
||||||
|
|||||||
2
utils.go
2
utils.go
@@ -181,7 +181,7 @@ func getPreviewStyle(r *http.Request) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func findParentNevent(event *nostr.Event) string {
|
func getParentNevent(event *nostr.Event) string {
|
||||||
parentNevent := ""
|
parentNevent := ""
|
||||||
replyTag := nip10.GetImmediateReply(event.Tags)
|
replyTag := nip10.GetImmediateReply(event.Tags)
|
||||||
if replyTag != nil {
|
if replyTag != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user