mirror of
https://github.com/aljazceru/njump.git
synced 2026-02-21 22:14:29 +01:00
Use nip52.Participant and add roles to calendard events
This commit is contained in:
@@ -1,5 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
"unicode"
|
||||
"github.com/nbd-wtf/go-nostr/nip19"
|
||||
"github.com/nbd-wtf/go-nostr/nip52"
|
||||
)
|
||||
|
||||
func formatPartecipants(partecipants []nip52.Participant) string {
|
||||
var list = make([]string, 0)
|
||||
for _, p := range partecipants {
|
||||
nreplace, _ := nip19.EncodePublicKey(p.PubKey)
|
||||
bytes := []byte(p.Role)
|
||||
bytes[0] = byte(unicode.ToUpper(rune(bytes[0])))
|
||||
role := string(bytes)
|
||||
nreplace = replaceNostrURLsWithHTMLTags(nostrNpubNprofileMatcher, "nostr:" + nreplace)
|
||||
if p.Role != "" {
|
||||
nreplace = nreplace + " as " + role
|
||||
}
|
||||
list = append(list, nreplace)
|
||||
}
|
||||
return strings.Join(list, ", ")
|
||||
}
|
||||
|
||||
templ calendarEventTemplate(params CalendarPageParams) {
|
||||
<!DOCTYPE html>
|
||||
@eventPageTemplate(
|
||||
@@ -52,12 +76,10 @@ templ calendarEventTemplate(params CalendarPageParams) {
|
||||
</div>
|
||||
|
||||
<div class="mb-4 pt-6">
|
||||
if len(params.People) != 0 {
|
||||
if len(params.CalendarEvent.Participants) != 0 {
|
||||
<div class="pb-4">
|
||||
<strong>People</strong>:
|
||||
for _, p := range params.People {
|
||||
@templ.Raw(replaceNostrURLsWithHTMLTags(nostrNpubNprofileMatcher, "nostr:" + p))
|
||||
}
|
||||
<span class="font-medium">People</span>:
|
||||
@templ.Raw(formatPartecipants(params.CalendarEvent.Participants))
|
||||
</div>
|
||||
}
|
||||
if params.CalendarEvent.Image != "" {
|
||||
@@ -74,4 +96,4 @@ templ calendarEventTemplate(params CalendarPageParams) {
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
1
pages.go
1
pages.go
@@ -246,7 +246,6 @@ type CalendarPageParams struct {
|
||||
EndAtTime string
|
||||
Content template.HTML
|
||||
CalendarEvent Kind31922Or31923Metadata
|
||||
People []string
|
||||
Clients []ClientReference
|
||||
}
|
||||
|
||||
|
||||
@@ -470,14 +470,6 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
data.kind31922Or31923Metadata.End.Second() != 0 {
|
||||
EndAtTime = data.kind31922Or31923Metadata.End.Format("15:04")
|
||||
}
|
||||
var People []string
|
||||
for _, value := range data.event.Tags {
|
||||
nreplace := ""
|
||||
if value[0] == "p" {
|
||||
nreplace, _ = nip19.EncodePublicKey(value[1])
|
||||
People = append(People, nreplace)
|
||||
}
|
||||
}
|
||||
|
||||
component = calendarEventTemplate(CalendarPageParams{
|
||||
BaseEventPageParams: baseEventPageParams,
|
||||
@@ -493,7 +485,6 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
EndAtDate: EndAtDate,
|
||||
EndAtTime: EndAtTime,
|
||||
CalendarEvent: *data.kind31922Or31923Metadata,
|
||||
People: People,
|
||||
Details: detailsData,
|
||||
Content: template.HTML(data.content),
|
||||
Clients: generateClientList(data.event.Kind, data.naddr),
|
||||
|
||||
Reference in New Issue
Block a user