aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2021-01-23 08:44:05 +0000
committerr <r@freesoftwareextremist.com>2021-01-23 08:44:05 +0000
commitac342dde079a0ca156c36a402a3c0ba86d78821d (patch)
tree03d3daf98c5e14736e9ba66f1781df83ea4eed65
parenteca0366c21c94f7cbf6d1b701dd31be8ee81abc7 (diff)
downloadbloat-ac342dde079a0ca156c36a402a3c0ba86d78821d.tar.gz
bloat-ac342dde079a0ca156c36a402a3c0ba86d78821d.zip
Add remote timeline
-rw-r--r--mastodon/status.go6
-rw-r--r--renderer/model.go2
-rw-r--r--service/service.go28
-rw-r--r--service/transport.go4
-rw-r--r--templates/nav.tmpl7
-rw-r--r--templates/root.tmpl2
-rw-r--r--templates/timeline.tmpl10
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 @@
<a class="nav-link" href="/timeline/home" accesskey="1" title="Home timeline (1)">home</a>
<a class="nav-link" href="/timeline/direct" accesskey="2" title="Direct timeline (2)">direct</a>
<a class="nav-link" href="/timeline/local" accesskey="3" title="Local timeline (3)">local</a>
- <a class="nav-link" href="/timeline/twkn" accesskey="4" title="The Whole Known Netwwork (4)">twkn</a>
- <a class="nav-link" href="/search" accesskey="5" title="Search (5)">search</a>
- <a class="nav-link" href="/about" accesskey="6" title="About (6)">about</a>
+ <a class="nav-link" href="/timeline/remote" accesskey="4" title="Remote timeline (4)">remote</a>
+ <a class="nav-link" href="/timeline/twkn" accesskey="5" title="The Whole Known Netwwork (5)">twkn</a>
+ <a class="nav-link" href="/search" accesskey="6" title="Search (6)">search</a>
</div>
<div>
<a class="nav-link" href="/settings" target="_top" accesskey="7" title="Settings (7)">settings</a>
@@ -28,6 +28,7 @@
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
<input type="submit" value="signout" class="btn-link nav-link" accesskey="8" title="Signout (8)">
</form>
+ <a class="nav-link" href="/about" accesskey="9" title="About (9)">about</a>
</div>
</div>
</div>
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 @@
<link rel="icon" type="image/png" href="/static/favicon.png">
<title>{{.Title}}</title>
</head>
-<frameset cols="420px,*">
+<frameset cols="424px,*">
<frameset rows="316px,*">
<frame name="nav" src="/nav">
<frame name="notification" src="/notifications">
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)}}
<div class="page-title"> {{.Title}} </div>
+{{if eq .Type "remote"}}
+<form class="search-form" action="/timeline/remote" method="GET">
+ <span class="post-form-field">
+ <label for="instance"> Instance </label>
+ <input id="instance" name="instance" value="{{.Instance}}">
+ </span>
+ <button type="submit"> Submit </button>
+</form>
+{{end}}
+
{{range .Statuses}}
{{template "status.tmpl" (WithContext . $.Ctx)}}
{{end}}