aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-25 04:30:21 +0000
committerr <r@freesoftwareextremist.com>2019-12-25 04:30:21 +0000
commitf6f7b27e40f97ffe88323be01bea1d04ca39d6b0 (patch)
tree2aad7592cc20bc9d1d59e5e9da5d83b1d15774cc /service
parent51bdb20402abc08102e83a234bb4f6720c5a1166 (diff)
downloadbloat-f6f7b27e40f97ffe88323be01bea1d04ca39d6b0.tar.gz
bloat-f6f7b27e40f97ffe88323be01bea1d04ca39d6b0.zip
Add local and twkn timelines
Diffstat (limited to 'service')
-rw-r--r--service/auth.go4
-rw-r--r--service/logging.go8
-rw-r--r--service/service.go23
-rw-r--r--service/transport.go14
4 files changed, 35 insertions, 14 deletions
diff --git a/service/auth.go b/service/auth.go
index 57ef3d0..cadb050 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -85,12 +85,12 @@ func (s *authService) ServeSigninPage(ctx context.Context, client io.Writer) (er
}
func (s *authService) ServeTimelinePage(ctx context.Context, client io.Writer,
- c *model.Client, maxID string, sinceID string, minID string) (err error) {
+ c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error) {
c, err = s.getClient(ctx)
if err != nil {
return
}
- return s.Service.ServeTimelinePage(ctx, client, c, maxID, sinceID, minID)
+ return s.Service.ServeTimelinePage(ctx, client, c, timelineType, maxID, sinceID, minID)
}
func (s *authService) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
diff --git a/service/logging.go b/service/logging.go
index 9848e54..87433a4 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -61,12 +61,12 @@ func (s *loggingService) ServeSigninPage(ctx context.Context, client io.Writer)
}
func (s *loggingService) ServeTimelinePage(ctx context.Context, client io.Writer,
- c *model.Client, maxID string, sinceID string, minID string) (err error) {
+ c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error) {
defer func(begin time.Time) {
- s.logger.Printf("method=%v, max_id=%v, since_id=%v, min_id=%v, took=%v, err=%v\n",
- "ServeTimelinePage", maxID, sinceID, minID, time.Since(begin), err)
+ s.logger.Printf("method=%v, timeline_type=%v, max_id=%v, since_id=%v, min_id=%v, took=%v, err=%v\n",
+ "ServeTimelinePage", timelineType, maxID, sinceID, minID, time.Since(begin), err)
}(time.Now())
- return s.Service.ServeTimelinePage(ctx, client, c, maxID, sinceID, minID)
+ return s.Service.ServeTimelinePage(ctx, client, c, timelineType, maxID, sinceID, minID)
}
func (s *loggingService) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
diff --git a/service/service.go b/service/service.go
index 8a262b6..7fc27fc 100644
--- a/service/service.go
+++ b/service/service.go
@@ -21,6 +21,7 @@ var (
ErrInvalidArgument = errors.New("invalid argument")
ErrInvalidToken = errors.New("invalid token")
ErrInvalidClient = errors.New("invalid client")
+ ErrInvalidTimeline = errors.New("invalid timeline")
)
type Service interface {
@@ -29,7 +30,7 @@ type Service interface {
GetUserToken(ctx context.Context, sessionID string, c *model.Client, token string) (accessToken string, err error)
ServeErrorPage(ctx context.Context, client io.Writer, err error)
ServeSigninPage(ctx context.Context, client io.Writer) (err error)
- ServeTimelinePage(ctx context.Context, client io.Writer, c *model.Client, maxID string, sinceID string, minID string) (err error)
+ ServeTimelinePage(ctx context.Context, client io.Writer, c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error)
ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error)
ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error)
ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
@@ -210,7 +211,7 @@ func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err
}
func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
- c *model.Client, maxID string, sinceID string, minID string) (err error) {
+ c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error) {
var hasNext, hasPrev bool
var nextLink, prevLink string
@@ -221,7 +222,21 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
Limit: 20,
}
- statuses, err := c.GetTimelineHome(ctx, &pg)
+ var statuses []*mastodon.Status
+ var title string
+ switch timelineType {
+ default:
+ return ErrInvalidTimeline
+ case "home":
+ statuses, err = c.GetTimelineHome(ctx, &pg)
+ title = "Timeline"
+ case "local":
+ statuses, err = c.GetTimelinePublic(ctx, true, &pg)
+ title = "Local Timeline"
+ case "twkn":
+ statuses, err = c.GetTimelinePublic(ctx, false, &pg)
+ title = "The Whole Known Network"
+ }
if err != nil {
return err
}
@@ -261,7 +276,7 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
return
}
- data := renderer.NewTimelinePageTemplateData(statuses, hasNext, nextLink, hasPrev, prevLink, postContext, navbarData)
+ data := renderer.NewTimelinePageTemplateData(title, statuses, hasNext, nextLink, hasPrev, prevLink, postContext, navbarData)
err = svc.renderer.RenderTimelinePage(ctx, client, data)
if err != nil {
return
diff --git a/service/transport.go b/service/transport.go
index 437d32f..438b39d 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -26,7 +26,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
sessionID, _ := req.Cookie("session_id")
if sessionID != nil && len(sessionID.Value) > 0 {
- location = "/timeline"
+ location = "/timeline/home"
}
w.Header().Add("Location", location)
@@ -63,18 +63,24 @@ func NewHandler(s Service, staticDir string) http.Handler {
return
}
- w.Header().Add("Location", "/timeline")
+ w.Header().Add("Location", "/timeline/home")
w.WriteHeader(http.StatusFound)
}).Methods(http.MethodGet)
r.HandleFunc("/timeline", func(w http.ResponseWriter, req *http.Request) {
+ w.Header().Add("Location", "/timeline/home")
+ w.WriteHeader(http.StatusFound)
+ }).Methods(http.MethodGet)
+
+ r.HandleFunc("/timeline/{type}", func(w http.ResponseWriter, req *http.Request) {
ctx := getContextWithSession(context.Background(), req)
+ timelineType, _ := mux.Vars(req)["type"]
maxID := req.URL.Query().Get("max_id")
sinceID := req.URL.Query().Get("since_id")
minID := req.URL.Query().Get("min_id")
- err := s.ServeTimelinePage(ctx, w, nil, maxID, sinceID, minID)
+ err := s.ServeTimelinePage(ctx, w, nil, timelineType, maxID, sinceID, minID)
if err != nil {
s.ServeErrorPage(ctx, w, err)
return
@@ -166,7 +172,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
return
}
- location := "/timeline" + "#status-" + id
+ location := "/timeline/home" + "#status-" + id
if len(replyToID) > 0 {
location = "/thread/" + replyToID + "#status-" + id
}