update nostr-sdk to fix relay lists and move things around.

This commit is contained in:
fiatjaf
2024-05-23 23:03:22 -03:00
parent 7a2aadb749
commit 5966234156
6 changed files with 27 additions and 28 deletions

37
data.go
View File

@@ -27,7 +27,7 @@ type Data struct {
modifiedAt string
parentLink template.HTML
metadata Metadata
authorRelays []string
authorRelaysPretty []string
authorLong string
renderableLastNotes []EnhancedEvent
kindDescription string
@@ -70,6 +70,20 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
},
}
data.authorRelaysPretty = make([]string, 0, len(relays))
for _, url := range relaysForPubkey(ctx, event.PubKey) {
if isntRealRelay(url) {
continue
}
for _, excluded := range relayConfig.ExcludedRelays {
if strings.Contains(url, excluded) {
continue
}
}
data.authorRelaysPretty = append(data.authorRelaysPretty, trimProtocol(url))
}
data.authorRelaysPretty = unique(data.authorRelaysPretty)
npub, _ := nip19.EncodePublicKey(event.PubKey)
npubShort := npub[:8] + "…" + npub[len(npub)-4:]
data.authorLong = npub // hopefully will be replaced later
@@ -79,7 +93,6 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
data.naddrNaked = ""
data.createdAt = time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02 15:04:05")
data.modifiedAt = time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02T15:04:05Z07:00")
data.authorRelays = []string{}
if event.Kind >= 30000 && event.Kind < 40000 {
if d := event.Tags.GetFirst([]string{"d", ""}); d != nil {
@@ -93,25 +106,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
switch event.Kind {
case 0:
data.templateId = Profile
{
rawAuthorRelays := []string{}
ctx, cancel := context.WithTimeout(ctx, time.Second*4)
rawAuthorRelays = relaysForPubkey(ctx, event.PubKey)
cancel()
for _, relay := range rawAuthorRelays {
for _, excluded := range relayConfig.ExcludedRelays {
if strings.Contains(relay, excluded) {
continue
}
}
if strings.Contains(relay, "/npub1") {
continue // skip relays with personalyzed query like filter.nostr.wine
}
data.authorRelays = append(data.authorRelays, trimProtocol(relay))
}
}
lastNotes := authorLastNotes(ctx, event.PubKey, data.authorRelays, isProfileSitemap)
lastNotes := authorLastNotes(ctx, event.PubKey, isProfileSitemap)
data.renderableLastNotes = make([]EnhancedEvent, len(lastNotes))
for i, levt := range lastNotes {
data.renderableLastNotes[i] = EnhancedEvent{levt, []string{}}

2
go.mod
View File

@@ -17,7 +17,7 @@ require (
github.com/microcosm-cc/bluemonday v1.0.24
github.com/nbd-wtf/emoji v0.0.3
github.com/nbd-wtf/go-nostr v0.30.2
github.com/nbd-wtf/nostr-sdk v0.2.0
github.com/nbd-wtf/nostr-sdk v0.2.1
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pelletier/go-toml v1.9.5
github.com/pemistahl/lingua-go v1.4.0

4
go.sum
View File

@@ -167,8 +167,8 @@ github.com/nbd-wtf/emoji v0.0.3 h1:YtkT7MVPXvqU1SQjvC/CShlWexnREzqNCxmhUnL00CA=
github.com/nbd-wtf/emoji v0.0.3/go.mod h1:tS6D9iI34qwBmWc5g8X7tVDkWXulqbTJRsvsM6QsS88=
github.com/nbd-wtf/go-nostr v0.30.2 h1:dG/2X52/XDg+7phZH+BClcvA5D+S6dXvxJKkBaySEzI=
github.com/nbd-wtf/go-nostr v0.30.2/go.mod h1:tiKJY6fWYSujbTQb201Y+IQ3l4szqYVt+fsTnsm7FCk=
github.com/nbd-wtf/nostr-sdk v0.2.0 h1:IYg5xuPLt0zmL7GiHWeixDO2f47NYaIwb0MmoJRnHWw=
github.com/nbd-wtf/nostr-sdk v0.2.0/go.mod h1:iYZYgu0lilem16G8fk08FipgMOzsQs2bO1j6uEnRhvA=
github.com/nbd-wtf/nostr-sdk v0.2.1 h1:Ae1186pm//Byy5gOIsB3Nhy6EQfTzOHeU9enRWVd204=
github.com/nbd-wtf/nostr-sdk v0.2.1/go.mod h1:iYZYgu0lilem16G8fk08FipgMOzsQs2bO1j6uEnRhvA=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=

View File

@@ -216,7 +216,7 @@ func getEvent(ctx context.Context, code string, relayHints []string) (*nostr.Eve
return result, allRelays, nil
}
func authorLastNotes(ctx context.Context, pubkey string, relays []string, isSitemap bool) []*nostr.Event {
func authorLastNotes(ctx context.Context, pubkey string, isSitemap bool) []*nostr.Event {
limit := 100
store := true
useLocalStore := true
@@ -242,7 +242,11 @@ func authorLastNotes(ctx context.Context, pubkey string, relays []string, isSite
lastNotes = make([]*nostr.Event, 0, filter.Limit)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
relays = unique(append(relays, getRandomRelay(), getRandomRelay()))
relays := limitAt(relaysForPubkey(ctx, pubkey), 5)
for len(relays) < 4 {
relays = unique(append(relays, getRandomRelay()))
}
ch := pool.SubManyEose(ctx, relays, nostr.Filters{filter})
out:
for {

View File

@@ -59,7 +59,7 @@ func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
Metadata: data.metadata,
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, true)),
AuthorRelays: data.authorRelays,
AuthorRelays: data.authorRelaysPretty,
})
default:
log.Error().Int("templateId", int(data.templateId)).Msg("no way to render")

View File

@@ -79,7 +79,7 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, false)),
Nprofile: data.nprofile,
AuthorRelays: data.authorRelays,
AuthorRelays: data.authorRelaysPretty,
LastNotes: data.renderableLastNotes,
Clients: generateClientList(data.event.Kind, data.nprofile,
func(c ClientReference, s string) string {