tinyrelayfile
tinyrelay/tinyclient/social_reference_routes.go/

tinyclient/social_reference_routes.go raw
1package tinyclient
2
3import (
4 "encoding/json"
5 "net/http"
6 "strings"
7)
8
9// socialReferencePage tries the Social renderer for NIP-19 event references.
10// The generic event page remains the fallback for event kinds that Social does
11// 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 false
15 }
16 if address && !socialArticleAddress(identifier) {
17 return false
18 }
19 params := map[string]any{"limit": 30}
20 if cursor := request.URL.Query().Get("cursor"); cursor != "" {
21 params["cursor"] = cursor
22 }
23 if address {
24 params["address"] = identifier
25 } else {
26 params["id"] = identifier
27 }
28 raw, err := json.Marshal(params)
29 if err != nil {
30 return false
31 }
32 result, err := a.backend.Query(request.Context(), "browsesocialthread", []json.RawMessage{raw}, actor)
33 if err != nil || !socialThreadPost(result) {
34 return false
35 }
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 true
44}
45
46func socialArticleAddress(value string) bool {
47 parts := strings.SplitN(value, ":", 3)
48 return len(parts) == 3 && parts[0] == "30023" && hexID.MatchString(parts[1])
49}
50
51func socialThreadPost(value any) bool {
52 post, ok := valueMap(value)["post"]
53 if !ok {
54 return false
55 }
56 row := valueMap(post)
57 kind := int(unixSeconds(row["kind"]))
58 return kind == 1 || kind == 1111 || kind == 30023
59}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs