mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-19 07:14:24 +01:00
Include relays in the profile
This commit is contained in:
9
nostr.go
9
nostr.go
@@ -127,11 +127,10 @@ 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, code string, options ...int) []*nostr.Event {
|
func getLastNotes(ctx context.Context, code string, limit int) []*nostr.Event {
|
||||||
|
|
||||||
events_num := 10
|
if limit <= 0 {
|
||||||
if len(options) > 0 {
|
limit = 10
|
||||||
events_num = options[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pp := sdk.InputToProfile(ctx, code)
|
pp := sdk.InputToProfile(ctx, code)
|
||||||
@@ -152,7 +151,7 @@ func getLastNotes(ctx context.Context, code string, options ...int) []*nostr.Eve
|
|||||||
{
|
{
|
||||||
Kinds: []int{nostr.KindTextNote},
|
Kinds: []int{nostr.KindTextNote},
|
||||||
Authors: []string{pp.PublicKey},
|
Authors: []string{pp.PublicKey},
|
||||||
Limit: events_num,
|
Limit: limit,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
lastNotes := make([]*nostr.Event, 0, 20)
|
lastNotes := make([]*nostr.Event, 0, 20)
|
||||||
|
|||||||
15
render.go
15
render.go
@@ -54,11 +54,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// If the protocol is present strip it and redirect
|
// If the protocol is present strip it and redirect
|
||||||
if strings.HasPrefix(code, "wss:/") || strings.HasPrefix(code, "ws:/") {
|
if strings.HasPrefix(code, "wss:/") || strings.HasPrefix(code, "ws:/") {
|
||||||
hostname := code
|
hostname := trimProtocol(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 '/'
|
|
||||||
http.Redirect(w, r, "/"+hostname, http.StatusFound)
|
http.Redirect(w, r, "/"+hostname, http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +81,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
author := event
|
author := event
|
||||||
var renderableLastNotes []*Event
|
var renderableLastNotes []*Event
|
||||||
parentNevent := ""
|
parentNevent := ""
|
||||||
|
authorRelays := []string{}
|
||||||
|
|
||||||
if event.Kind == 0 {
|
if event.Kind == 0 {
|
||||||
key := ""
|
key := ""
|
||||||
@@ -97,6 +94,13 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
key = "ln:" + event.PubKey
|
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
|
var lastNotes []*nostr.Event
|
||||||
|
|
||||||
if ok := cache.GetJSON(key, &lastNotes); !ok {
|
if ok := cache.GetJSON(key, &lastNotes); !ok {
|
||||||
@@ -295,6 +299,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
"kindNIP": kindNIP,
|
"kindNIP": kindNIP,
|
||||||
"lastNotes": renderableLastNotes,
|
"lastNotes": renderableLastNotes,
|
||||||
"parentNevent": parentNevent,
|
"parentNevent": parentNevent,
|
||||||
|
"authorRelays": authorRelays,
|
||||||
}
|
}
|
||||||
|
|
||||||
// if a mapping is not found fallback to raw
|
// if a mapping is not found fallback to raw
|
||||||
|
|||||||
@@ -366,6 +366,20 @@ iframe {
|
|||||||
.theme--dark .container .column_content .field a.nostr {
|
.theme--dark .container .column_content .field a.nostr {
|
||||||
background-color: #42091e;
|
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 {
|
.container .column_content .field .label {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,6 +376,20 @@ iframe {
|
|||||||
}
|
}
|
||||||
border-bottom: none;
|
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 {
|
.label {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
@include themed() {
|
@include themed() {
|
||||||
|
|||||||
@@ -56,6 +56,13 @@
|
|||||||
{{.metadata.LUD16 | escapeString}}
|
{{.metadata.LUD16 | escapeString}}
|
||||||
</div>
|
</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">
|
<div class="field last_update">
|
||||||
Last update:<br />
|
Last update:<br />
|
||||||
{{.createdAt | escapeString}}
|
{{.createdAt | escapeString}}
|
||||||
|
|||||||
8
utils.go
8
utils.go
@@ -336,3 +336,11 @@ func unique(strSlice []string) []string {
|
|||||||
}
|
}
|
||||||
return list
|
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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user