diff options
author | r <r@freesoftwareextremist.com> | 2021-01-14 09:41:53 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2021-01-14 09:41:53 +0000 |
commit | 7ccffa8752baa6f77732d8530704ea7da1b73c92 (patch) | |
tree | 3699f4aa2e66838c5f3a3a9c4bda4c3b85aa7741 | |
parent | b35d62ecbb96b6d5f83b0453ca16e8dc45b39657 (diff) | |
download | bloat-remote_timeline.tar.gz bloat-remote_timeline.zip |
Add WIP remote timelineremote_timeline
-rw-r--r-- | service/service.go | 54 | ||||
-rw-r--r-- | service/transport.go | 4 |
2 files changed, 32 insertions, 26 deletions
diff --git a/service/service.go b/service/service.go index db44e10..78da3d8 100644 --- a/service/service.go +++ b/service/service.go @@ -155,8 +155,8 @@ 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, - maxID string, minID string) (err error) { +func (s *service) TimelinePage(c *client, tType string, maxID string, + minID string, instance string) (err error) { var nextLink, prevLink, title string var statuses []*mastodon.Status @@ -181,6 +181,22 @@ func (s *service) TimelinePage(c *client, tType string, case "twkn": statuses, err = c.GetTimelinePublic(ctx, false, &pg) title = "The Whole Known Network" + case "remote": + if len(instance) < 1 { + return errInvalidArgument + } + var instanceURL string + if strings.HasPrefix(instance, "https://") { + instanceURL = instance + instance = strings.TrimPrefix(instance, "https://") + } else { + instanceURL = "https://" + instance + } + c.Client = mastodon.NewClient(&mastodon.Config{ + Server: instanceURL, + }) + statuses, err = c.GetTimelinePublic(ctx, true, &pg) + title = "Remote Timeline of " + instance } if err != nil { return err @@ -192,32 +208,22 @@ func (s *service) TimelinePage(c *client, tType string, } } - if len(maxID) > 0 && len(statuses) > 0 { - prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", tType, - statuses[0].ID) - } - - if len(minID) > 0 && len(pg.MinID) > 0 { - newPg := &mastodon.Pagination{MinID: pg.MinID, Limit: 20} - newStatuses, err := c.GetTimelineHome(ctx, newPg) - if err != nil { - return err - } - newLen := len(newStatuses) - if newLen == 20 { - prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", - tType, pg.MinID) - } else { - i := 20 - newLen - 1 - if len(statuses) > i { - prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", - tType, statuses[i].ID) - } + if (len(maxID) > 0 || len(minID) > 0) && len(statuses) > 0 { + q := make(url.Values) + q["min_id"] = []string{statuses[0].ID} + if tType == "remote" { + q["instance"] = []string{instance} } + prevLink = fmt.Sprintf("/timeline/%s?%s", tType, q.Encode()) } if len(pg.MaxID) > 0 && len(statuses) == 20 { - nextLink = fmt.Sprintf("/timeline/%s?max_id=%s", tType, pg.MaxID) + q := make(url.Values) + q["max_id"] = []string{pg.MaxID} + if tType == "remote" { + q["instance"] = []string{instance} + } + nextLink = fmt.Sprintf("/timeline/%s?%s", tType, q.Encode()) } commonData := s.getCommonData(c, tType+" timeline ") diff --git a/service/transport.go b/service/transport.go index 80ad7f1..5e87f93 100644 --- a/service/transport.go +++ b/service/transport.go @@ -188,8 +188,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { q := c.Req.URL.Query() maxID := q.Get("max_id") minID := q.Get("min_id") - return s.TimelinePage(c, tType, maxID, minID) - return nil + instance := q.Get("instance") + return s.TimelinePage(c, tType, maxID, minID, instance) }, SESSION, HTML) defaultTimelinePage := handle(func(c *client) error { |