clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

main
tinyrelay / tinyclient / social_reference_routes.go
social_reference_routes.go 1.6K
1package tinyclient23import (4 "encoding/json"5 "net/http"6 "strings"7)89// socialReferencePage tries the Social renderer for NIP-19 event references.10// The generic event page remains the fallback for event kinds that Social does11// not publish or for backends that predate the Social browse methods.12func (a *App) socialReferencePage(writer http.ResponseWriter, request *http.Request, identifier string, address bool, actor string) bool {13 if !a.backend.Policy().Features.Pages {14 return false15 }16 if address && !socialArticleAddress(identifier) {17 return false18 }19 params := map[string]any{"limit": 30}20 if cursor := request.URL.Query().Get("cursor"); cursor != "" {21 params["cursor"] = cursor22 }23 if address {24 params["address"] = identifier25 } else {26 params["id"] = identifier27 }28 raw, err := json.Marshal(params)29 if err != nil {30 return false31 }32 result, err := a.backend.Query(request.Context(), "browsesocialthread", []json.RawMessage{raw}, actor)33 if err != nil || !socialThreadPost(result) {34 return false35 }36 data := PageData{37 Event: result,38 Query: request.URL.Query(),39 Tab: "social-thread",40 Title: "Social | " + a.backend.Slug(),41 }42 a.render(writer, request, data)43 return true44}4546func socialArticleAddress(value string) bool {47 parts := strings.SplitN(value, ":", 3)48 return len(parts) == 3 && parts[0] == "30023" && hexID.MatchString(parts[1])49}5051func socialThreadPost(value any) bool {52 post, ok := valueMap(value)["post"]53 if !ok {54 return false55 }56 row := valueMap(post)57 kind := int(unixSeconds(row["kind"]))58 return kind == 1 || kind == 54 || kind == 1111 || kind == 3002359}