Keep the home page focused on relay identity and connection information. Social provides the notes and articles feed, while Search retains raw event inspection. Remove the home feed query and cover guest and signed-in rendering without loading social events.
- commit
- 91c15ac8a61eb037b8853692dc017dce415920df
- parent
- 862b2c259a03c76493dbb3a30ce5d91d5dce7516
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 3 | +-- |
| M | internal/ | 2 | -- |
| M | internal/ | 29 | ++++++++++++++++++++++++++++- |
| M | internal/ | 2 | +- |
@@ -20,8 +20,7 @@
2020 {{end}}<p>{{range index $c "links"}}{{$l := asMap .}}{{if str (index $l "href")}}<a href="{{str (index $l "href")}}">{{str (index $l "label")}}</a> {{else}}<button type="button" data-copy="{{str (index $l "copy")}}">{{str (index $l "label")}}</button> {{end}}{{end}}{{if index $c "hidden"}}<small>sign in for {{str (index $c "hidden")}} more</small>{{end}}<output role="status"></output></p>2121 {{with str (index $c "qr")}}<details><summary>QR code</summary><img src="/qr.svg?text={{urlquery .}}" alt="QR code" width="200" height="200"></details>{{end}}2222 </connect-card>23-{{end}}{{end}}<h2>Recent activity</h2>24-{{if .Error}}{{template "alert" .Error}}{{else}}{{template "eventList" .}}{{end}}23+{{end}}{{end}}2524 </section>2625 {{end}}2726 @@ -33,8 +33,6 @@ func (a *App) publicFeed(ctx context.Context, tab, actor string, values url.Valu
3333 filter = map[string]any{"authors": []string{actor}, "limit": 50}3434 case "articles":3535 filter = map[string]any{"kinds": []int{30023}, "limit": 50}36- case "home":37- filter = map[string]any{"kinds": []int{1, 30023}, "limit": 12}3836 case "sites":3937 filter = map[string]any{"kinds": []int{sites.KindSite, sites.KindNamedSite}, "limit": 100}4038 default:@@ -11,15 +11,42 @@ import (
1111 "github.com/FelineStateMachine/tinyrelay/internal/policy"1212 )1313 14-type publicBackend struct{ fakeBackend }14+type publicBackend struct {15+ fakeBackend16+ eventQueries int17+}1518 1619 func (b *publicBackend) Query(_ context.Context, method string, _ []json.RawMessage, actor string) (any, error) {1720 if method != "queryevents" {1821 return b.fakeBackend.Query(context.Background(), method, nil, actor)1922 }23+ b.eventQueries++2024 return []map[string]any{{"id": "event-1", "pubkey": actor, "content": "visible result"}}, nil2125 }2226 27+func TestHomeShowsRelayInformationWithoutQueryingSocialEvents(t *testing.T) {28+ owner := strings.Repeat("a", 64)29+ for _, actor := range []string{"", owner} {30+ backend := &publicBackend{fakeBackend: fakeBackend{policy: policy.Defaults(owner)}}31+ backend.policy.Description = "A place to connect."32+ app, err := New(backend, Options{Actor: func(*http.Request) (string, error) { return actor, nil }})33+ if err != nil {34+ t.Fatal(err)35+ }36+ for _, path := range []string{"/", "/?kinds=all"} {37+ recorder := httptest.NewRecorder()38+ app.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, path, nil))39+ body := recorder.Body.String()40+ if recorder.Code != http.StatusOK || !strings.Contains(body, "A place to connect.") || !strings.Contains(body, `href="/social"`) {41+ t.Fatalf("home lost relay information or Social navigation: status=%d", recorder.Code)42+ }43+ if backend.eventQueries != 0 || strings.Contains(body, "Recent activity") || strings.Contains(body, "visible result") {44+ t.Fatalf("home still loads the duplicate feed: queries=%d", backend.eventQueries)45+ }46+ }47+ }48+}49+2350 type articleBackend struct{ fakeBackend }2451 2552 func (b *articleBackend) Query(_ context.Context, method string, _ []json.RawMessage, _ string) (any, error) {@@ -860,7 +860,7 @@ func (a *App) page(writer http.ResponseWriter, request *http.Request) {
860860 actor = ""861861 }862862 data := PageData{Tab: tab, Query: request.URL.Query()}863- if tab == "inbox" || tab == "outbox" || tab == "search" || tab == "articles" || tab == "home" || tab == "sites" {863+ if tab == "inbox" || tab == "outbox" || tab == "search" || tab == "articles" || tab == "sites" {864864 feed, feedErr := a.publicFeed(request.Context(), tab, actor, request.URL.Query())865865 if feedErr != nil {866866 data.Error = feedErr.Error()