mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
fix slowness of previous refactors that injected nostr-sdk into this codebase + refactors.
- adjusting many small things related to nostr-sdk usage - fetching profiles in a smarter way - decoupling the logic for rendering profile pages from the `grabData`/`getEvent` flow of other event pages. - incorporating nostr-sdk more holistically, including more hints stuff - improving nostr-sdk itself after some bugs and weird behaviors observed here - set up opentelemetry (should probably remove this later)
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
@@ -29,12 +28,11 @@ type EnhancedEvent struct {
|
||||
func NewEnhancedEvent(
|
||||
ctx context.Context,
|
||||
event *nostr.Event,
|
||||
relays []string,
|
||||
) EnhancedEvent {
|
||||
ee := EnhancedEvent{
|
||||
Event: event,
|
||||
relays: relays,
|
||||
}
|
||||
ctx, span := tracer.Start(ctx, "make-enhanced-event")
|
||||
defer span.End()
|
||||
|
||||
ee := EnhancedEvent{Event: event}
|
||||
|
||||
for _, tag := range event.Tags {
|
||||
if tag[0] == "subject" || tag[0] == "title" {
|
||||
@@ -52,6 +50,7 @@ func NewEnhancedEvent(
|
||||
} else {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
|
||||
defer cancel()
|
||||
|
||||
ee.author = sys.FetchProfileMetadata(ctx, event.PubKey)
|
||||
}
|
||||
}
|
||||
@@ -201,46 +200,3 @@ func (ee EnhancedEvent) CreatedAtStr() string {
|
||||
func (ee EnhancedEvent) ModifiedAtStr() string {
|
||||
return time.Unix(int64(ee.Event.CreatedAt), 0).Format("2006-01-02T15:04:05Z07:00")
|
||||
}
|
||||
|
||||
func (ee EnhancedEvent) ToJSONHTML() template.HTML {
|
||||
tagsHTML := "["
|
||||
for t, tag := range ee.Tags {
|
||||
tagsHTML += "\n ["
|
||||
for i, item := range tag {
|
||||
cls := `"text-zinc-500 dark:text-zinc-50"`
|
||||
if i == 0 {
|
||||
cls = `"text-amber-500 dark:text-amber-200"`
|
||||
}
|
||||
itemJSON, _ := json.Marshal(item)
|
||||
tagsHTML += "\n <span class=" + cls + ">" + html.EscapeString(string(itemJSON))
|
||||
if i < len(tag)-1 {
|
||||
tagsHTML += ","
|
||||
} else {
|
||||
tagsHTML += "\n "
|
||||
}
|
||||
}
|
||||
tagsHTML += "]"
|
||||
if t < len(ee.Tags)-1 {
|
||||
tagsHTML += ","
|
||||
} else {
|
||||
tagsHTML += "\n "
|
||||
}
|
||||
}
|
||||
tagsHTML += "]"
|
||||
|
||||
contentJSON, _ := json.Marshal(ee.Content)
|
||||
|
||||
keyCls := "text-purple-700 dark:text-purple-300"
|
||||
|
||||
return template.HTML(fmt.Sprintf(
|
||||
`{
|
||||
<span class="`+keyCls+`">"id":</span> <span class="text-zinc-500 dark:text-zinc-50">"%s"</span>,
|
||||
<span class="`+keyCls+`">"pubkey":</span> <span class="text-zinc-500 dark:text-zinc-50">"%s"</span>,
|
||||
<span class="`+keyCls+`">"created_at":</span> <span class="text-green-600">%d</span>,
|
||||
<span class="`+keyCls+`">"kind":</span> <span class="text-amber-500 dark:text-amber-200">%d</span>,
|
||||
<span class="`+keyCls+`">"tags":</span> %s,
|
||||
<span class="`+keyCls+`">"content":</span> <span class="text-zinc-500 dark:text-zinc-50">%s</span>,
|
||||
<span class="`+keyCls+`">"sig":</span> <span class="text-zinc-500 dark:text-zinc-50 content">"%s"</span>
|
||||
}`, ee.ID, ee.PubKey, ee.CreatedAt, ee.Kind, tagsHTML, html.EscapeString(string(contentJSON)), ee.Sig),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user