mirror of
https://git.freesoftwareextremist.com/bloat
synced 2024-12-22 09:10:42 +00:00
Add local and twkn timelines
This commit is contained in:
parent
51bdb20402
commit
f6f7b27e40
9 changed files with 45 additions and 20 deletions
|
@ -192,7 +192,7 @@ func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status
|
|||
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
|
||||
|
|
|
@ -18,6 +18,7 @@ func NewNavbarTemplateData(notificationCount int, user *mastodon.Account) *Navba
|
|||
}
|
||||
|
||||
type TimelinePageTemplateData struct {
|
||||
Title string
|
||||
Statuses []*mastodon.Status
|
||||
HasNext bool
|
||||
NextLink string
|
||||
|
@ -27,9 +28,10 @@ type TimelinePageTemplateData struct {
|
|||
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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<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"}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<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>
|
||||
|
@ -12,8 +12,10 @@
|
|||
</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>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{template "header.tmpl"}}
|
||||
{{template "navigation.tmpl" .NavbarData}}
|
||||
<div class="page-title"> Timeline </div>
|
||||
<div class="page-title"> {{.Title}} </div>
|
||||
|
||||
|
||||
{{template "postform.tmpl" .PostContext}}
|
||||
|
|
Loading…
Reference in a new issue