From ac342dde079a0ca156c36a402a3c0ba86d78821d Mon Sep 17 00:00:00 2001 From: r Date: Sat, 23 Jan 2021 08:44:05 +0000 Subject: Add remote timeline --- mastodon/status.go | 6 ++++-- renderer/model.go | 2 ++ service/service.go | 28 ++++++++++++++++++++++------ service/transport.go | 4 ++-- templates/nav.tmpl | 7 ++++--- templates/root.tmpl | 2 +- templates/timeline.tmpl | 10 ++++++++++ 7 files changed, 45 insertions(+), 14 deletions(-) diff --git a/mastodon/status.go b/mastodon/status.go index c8555d6..80e7e0e 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -191,9 +191,11 @@ func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status } // GetTimelinePublic return statuses from public timeline. -func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error) { +func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, instance string, pg *Pagination) ([]*Status, error) { params := url.Values{} - if isLocal { + if len(instance) > 0 { + params.Set("instance", instance) + } else if isLocal { params.Set("local", "true") } diff --git a/renderer/model.go b/renderer/model.go index a89b379..6c3ba90 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -52,6 +52,8 @@ type RootData struct { type TimelineData struct { *CommonData Title string + Type string + Instance string Statuses []*mastodon.Status NextLink string PrevLink string diff --git a/service/service.go b/service/service.go index f376fde..ce689fd 100644 --- a/service/service.go +++ b/service/service.go @@ -158,7 +158,7 @@ func (s *service) NavPage(c *client) (err error) { return s.renderer.Render(rCtx, c, renderer.NavPage, data) } -func (s *service) TimelinePage(c *client, tType string, +func (s *service) TimelinePage(c *client, tType string, instance string, maxID string, minID string) (err error) { var nextLink, prevLink, title string @@ -179,10 +179,15 @@ func (s *service) TimelinePage(c *client, tType string, statuses, err = c.GetTimelineDirect(ctx, &pg) title = "Direct Timeline" case "local": - statuses, err = c.GetTimelinePublic(ctx, true, &pg) + statuses, err = c.GetTimelinePublic(ctx, true, "", &pg) title = "Local Timeline" + case "remote": + if len(instance) > 0 { + statuses, err = c.GetTimelinePublic(ctx, false, instance, &pg) + } + title = "Remote Timeline" case "twkn": - statuses, err = c.GetTimelinePublic(ctx, false, &pg) + statuses, err = c.GetTimelinePublic(ctx, false, "", &pg) title = "The Whole Known Network" } if err != nil { @@ -196,17 +201,28 @@ func (s *service) TimelinePage(c *client, tType string, } if (len(maxID) > 0 || len(minID) > 0) && len(statuses) > 0 { - prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", tType, - statuses[0].ID) + v := make(url.Values) + v.Set("min_id", statuses[0].ID) + if len(instance) > 0 { + v.Set("instance", instance) + } + prevLink = "/timeline/" + tType + "?" + v.Encode() } if len(minID) > 0 || (len(pg.MaxID) > 0 && len(statuses) == 20) { - nextLink = fmt.Sprintf("/timeline/%s?max_id=%s", tType, pg.MaxID) + v := make(url.Values) + v.Set("max_id", pg.MaxID) + if len(instance) > 0 { + v.Set("instance", instance) + } + nextLink = "/timeline/" + tType + "?" + v.Encode() } commonData := s.getCommonData(c, tType+" timeline ") data := &renderer.TimelineData{ Title: title, + Type: tType, + Instance: instance, Statuses: statuses, NextLink: nextLink, PrevLink: prevLink, diff --git a/service/transport.go b/service/transport.go index 882a351..096b44e 100644 --- a/service/transport.go +++ b/service/transport.go @@ -190,10 +190,10 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { timelinePage := handle(func(c *client) error { tType, _ := mux.Vars(c.Req)["type"] q := c.Req.URL.Query() + instance := q.Get("instance") maxID := q.Get("max_id") minID := q.Get("min_id") - return s.TimelinePage(c, tType, maxID, minID) - return nil + return s.TimelinePage(c, tType, instance, maxID, minID) }, SESSION, HTML) defaultTimelinePage := handle(func(c *client) error { diff --git a/templates/nav.tmpl b/templates/nav.tmpl index fdff885..98f0532 100644 --- a/templates/nav.tmpl +++ b/templates/nav.tmpl @@ -17,9 +17,9 @@ home direct local - twkn - search - about + remote + twkn + search
settings @@ -28,6 +28,7 @@ + about
diff --git a/templates/root.tmpl b/templates/root.tmpl index ef25c90..b1305f5 100644 --- a/templates/root.tmpl +++ b/templates/root.tmpl @@ -6,7 +6,7 @@ {{.Title}} - + diff --git a/templates/timeline.tmpl b/templates/timeline.tmpl index eabb3ed..bde050a 100644 --- a/templates/timeline.tmpl +++ b/templates/timeline.tmpl @@ -2,6 +2,16 @@ {{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
{{.Title}}
+{{if eq .Type "remote"}} +
+ + + + + +
+{{end}} + {{range .Statuses}} {{template "status.tmpl" (WithContext . $.Ctx)}} {{end}} -- cgit v1.2.3