Include relays in the profile

This commit is contained in:
Daniele Tonon
2023-07-14 11:09:14 +02:00
parent b688f0ff41
commit df83b221a4
6 changed files with 57 additions and 10 deletions

View File

@@ -127,11 +127,10 @@ 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, code string, options ...int) []*nostr.Event {
func getLastNotes(ctx context.Context, code string, limit int) []*nostr.Event {
events_num := 10
if len(options) > 0 {
events_num = options[0]
if limit <= 0 {
limit = 10
}
pp := sdk.InputToProfile(ctx, code)
@@ -152,7 +151,7 @@ func getLastNotes(ctx context.Context, code string, options ...int) []*nostr.Eve
{
Kinds: []int{nostr.KindTextNote},
Authors: []string{pp.PublicKey},
Limit: events_num,
Limit: limit,
},
})
lastNotes := make([]*nostr.Event, 0, 20)

View File

@@ -54,11 +54,7 @@ func render(w http.ResponseWriter, r *http.Request) {
// If the protocol is present strip it and redirect
if strings.HasPrefix(code, "wss:/") || strings.HasPrefix(code, "ws:/") {
hostname := code
hostname = strings.TrimPrefix(hostname, "wss://")
hostname = strings.TrimPrefix(hostname, "ws://")
hostname = strings.TrimPrefix(hostname, "wss:/") // Some browsers replace upfront '//' with '/'
hostname = strings.TrimPrefix(hostname, "ws:/") // Some browsers replace upfront '//' with '/'
hostname := trimProtocol(code)
http.Redirect(w, r, "/"+hostname, http.StatusFound)
}
@@ -85,6 +81,7 @@ func render(w http.ResponseWriter, r *http.Request) {
author := event
var renderableLastNotes []*Event
parentNevent := ""
authorRelays := []string{}
if event.Kind == 0 {
key := ""
@@ -97,6 +94,13 @@ func render(w http.ResponseWriter, r *http.Request) {
key = "ln:" + event.PubKey
}
ctx, cancel := context.WithTimeout(r.Context(), time.Second*4)
authorRelays = relaysForPubkey(ctx, event.PubKey)
cancel()
for i, n := range authorRelays {
authorRelays[i] = trimProtocol(n)
}
var lastNotes []*nostr.Event
if ok := cache.GetJSON(key, &lastNotes); !ok {
@@ -295,6 +299,7 @@ func render(w http.ResponseWriter, r *http.Request) {
"kindNIP": kindNIP,
"lastNotes": renderableLastNotes,
"parentNevent": parentNevent,
"authorRelays": authorRelays,
}
// if a mapping is not found fallback to raw

View File

@@ -366,6 +366,20 @@ iframe {
.theme--dark .container .column_content .field a.nostr {
background-color: #42091e;
}
.container .column_content .field a.button {
border-bottom: 0;
border: 1px solid #c9c9c9;
border-radius: 8px;
padding: 2px 8px;
display: inline-block;
margin-top: 0.6em;
margin-right: 0.2em;
}
.container .column_content .field a.button:hover {
color: #ffffff;
background-color: #e32a6d;
border: 1px solid #e32a6d;
}
.container .column_content .field .label {
font-size: 0.8rem;
}

View File

@@ -376,6 +376,20 @@ iframe {
}
border-bottom: none;
}
a.button {
border-bottom: 0;
border: 1px solid $color-base4;
border-radius: 8px;
padding: 2px 8px;
display: inline-block;
margin-top: 0.6em;
margin-right: 0.2em;
&:hover {
color: $color-base1;
background-color: $color-accent1;
border: 1px solid $color-accent1;
}
}
.label {
font-size: 0.8rem;
@include themed() {

View File

@@ -56,6 +56,13 @@
{{.metadata.LUD16 | escapeString}}
</div>
<div class="field">
<div class="label">Last seen on these relays</div>
{{range $index, $element := .authorRelays}}
<a href="/{{$element | escapeString}}" class="button">{{$element}}</a>
{{end}}
</div>
<div class="field last_update">
Last update:<br />
{{.createdAt | escapeString}}

View File

@@ -336,3 +336,11 @@ func unique(strSlice []string) []string {
}
return list
}
func trimProtocol(relay string) string {
relay = strings.TrimPrefix(relay, "wss://")
relay = strings.TrimPrefix(relay, "ws://")
relay = strings.TrimPrefix(relay, "wss:/") // Some browsers replace upfront '//' with '/'
relay = strings.TrimPrefix(relay, "ws:/") // Some browsers replace upfront '//' with '/'
return relay
}