func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error) {
params := url.Values{}
if isLocal {
- params.Set("local", "t")
+ params.Set("local", "true")
}
var statuses []*Status
}
type TimelinePageTemplateData struct {
+ Title string
Statuses []*mastodon.Status
HasNext bool
NextLink string
NavbarData *NavbarTemplateData
}
-func NewTimelinePageTemplateData(statuses []*mastodon.Status, hasNext bool, nextLink string, hasPrev bool,
+func NewTimelinePageTemplateData(title string, statuses []*mastodon.Status, hasNext bool, nextLink string, hasPrev bool,
prevLink string, postContext model.PostContext, navbarData *NavbarTemplateData) *TimelinePageTemplateData {
return &TimelinePageTemplateData{
+ Title: title,
Statuses: statuses,
HasNext: hasNext,
NextLink: nextLink,
}
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) {
}
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) {
ErrInvalidArgument = errors.New("invalid argument")
ErrInvalidToken = errors.New("invalid token")
ErrInvalidClient = errors.New("invalid client")
+ ErrInvalidTimeline = errors.New("invalid timeline")
)
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)
}
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
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
}
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
sessionID, _ := req.Cookie("session_id")
if sessionID != nil && len(sessionID.Value) > 0 {
- location = "/timeline"
+ location = "/timeline/home"
}
w.Header().Add("Location", location)
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
return
}
- location := "/timeline" + "#status-" + id
+ location := "/timeline/home" + "#status-" + id
if len(replyToID) > 0 {
location = "/thread/" + replyToID + "#status-" + id
}
<div class="page-title"> Error </div>
<div class="error-text"> {{.}} </div>
<div>
-<a href="/timeline">Home</a>
+<a href="/timeline/home">Home</a>
<a href="/signin">Sign In</a>
</div>
{{template "footer.tmpl"}}
<div class="user-info">
<div class="user-info-img-container">
- <a class="img-link" href="/timeline" title="home">
+ <a class="img-link" href="/timeline/home" title="home">
<img class="user-info-img" src="{{.User.AvatarStatic}}" alt="profile-avatar" />
</a>
</div>
</a>
</div>
<div>
- <a class="nav-link" href="/timeline">home</a>
+ <a class="nav-link" href="/timeline/home">home</a>
<a class="nav-link" href="/notifications">notifications{{if gt .NotificationCount 0}}({{.NotificationCount}}){{end}}</a>
+ <a class="nav-link" href="/timeline/local">local</a>
+ <a class="nav-link" href="/timeline/twkn">twkn</a>
<a class="nav-link" href="/about">about</a>
</div>
<div>
{{template "header.tmpl"}}
{{template "navigation.tmpl" .NavbarData}}
-<div class="page-title"> Timeline </div>
+<div class="page-title"> {{.Title}} </div>
{{template "postform.tmpl" .PostContext}}