aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-29 03:43:57 +0000
committerr <r@freesoftwareextremist.com>2019-12-29 03:43:57 +0000
commit72dbe50341179d345f8cbd1bf5a97809037db364 (patch)
treee11659a1178179ccbe7e88b794b280cb225746a2
parentb9d7eb05beb57926181f91685a75b3069d1f8cf8 (diff)
downloadbloat-72dbe50341179d345f8cbd1bf5a97809037db364.tar.gz
bloat-72dbe50341179d345f8cbd1bf5a97809037db364.zip
Add following and followers page
-rw-r--r--renderer/model.go14
-rw-r--r--renderer/renderer.go10
-rw-r--r--service/auth.go16
-rw-r--r--service/logging.go16
-rw-r--r--service/service.go83
-rw-r--r--service/transport.go30
-rw-r--r--templates/followers.tmpl12
-rw-r--r--templates/following.tmpl12
-rw-r--r--templates/user.tmpl4
9 files changed, 195 insertions, 2 deletions
diff --git a/renderer/model.go b/renderer/model.go
index 12fa90f..3d344b4 100644
--- a/renderer/model.go
+++ b/renderer/model.go
@@ -90,6 +90,20 @@ type RetweetedByData struct {
NextLink string
}
+type FollowingData struct {
+ *CommonData
+ Users []*mastodon.Account
+ HasNext bool
+ NextLink string
+}
+
+type FollowersData struct {
+ *CommonData
+ Users []*mastodon.Account
+ HasNext bool
+ NextLink string
+}
+
type SearchData struct {
*CommonData
Q string
diff --git a/renderer/renderer.go b/renderer/renderer.go
index a46cfd2..efc412d 100644
--- a/renderer/renderer.go
+++ b/renderer/renderer.go
@@ -23,6 +23,8 @@ type Renderer interface {
RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiData) (err error)
RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error)
RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error)
+ RenderFollowingPage(ctx context.Context, writer io.Writer, data *FollowingData) (err error)
+ RenderFollowersPage(ctx context.Context, writer io.Writer, data *FollowersData) (err error)
RenderSearchPage(ctx context.Context, writer io.Writer, data *SearchData) (err error)
RenderSettingsPage(ctx context.Context, writer io.Writer, data *SettingsData) (err error)
}
@@ -93,6 +95,14 @@ func (r *renderer) RenderRetweetedByPage(ctx context.Context, writer io.Writer,
return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", data)
}
+func (r *renderer) RenderFollowingPage(ctx context.Context, writer io.Writer, data *FollowingData) (err error) {
+ return r.template.ExecuteTemplate(writer, "following.tmpl", data)
+}
+
+func (r *renderer) RenderFollowersPage(ctx context.Context, writer io.Writer, data *FollowersData) (err error) {
+ return r.template.ExecuteTemplate(writer, "followers.tmpl", data)
+}
+
func (r *renderer) RenderSearchPage(ctx context.Context, writer io.Writer, data *SearchData) (err error) {
return r.template.ExecuteTemplate(writer, "search.tmpl", data)
}
diff --git a/service/auth.go b/service/auth.go
index 4d1b5af..efc8dd3 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -149,6 +149,22 @@ func (s *authService) ServeRetweetedByPage(ctx context.Context, client io.Writer
return s.Service.ServeRetweetedByPage(ctx, client, c, id)
}
+func (s *authService) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeFollowingPage(ctx, client, c, id, maxID, minID)
+}
+
+func (s *authService) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeFollowersPage(ctx, client, c, id, maxID, minID)
+}
+
func (s *authService) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
c, err = s.getClient(ctx)
if err != nil {
diff --git a/service/logging.go b/service/logging.go
index cfd3654..d1685ac 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -125,6 +125,22 @@ func (s *loggingService) ServeRetweetedByPage(ctx context.Context, client io.Wri
return s.Service.ServeRetweetedByPage(ctx, client, c, id)
}
+func (s *loggingService) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
+ "ServeFollowingPage", id, maxID, minID, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeFollowingPage(ctx, client, c, id, maxID, minID)
+}
+
+func (s *loggingService) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
+ "ServeFollowersPage", id, maxID, minID, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeFollowersPage(ctx, client, c, id, maxID, minID)
+}
+
func (s *loggingService) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, q=%v, type=%v, offset=%v, took=%v, err=%v\n",
diff --git a/service/service.go b/service/service.go
index bf7967d..d9482c8 100644
--- a/service/service.go
+++ b/service/service.go
@@ -39,6 +39,8 @@ type Service interface {
ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
+ ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
+ ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error)
ServeSettingsPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
SaveSettings(ctx context.Context, client io.Writer, c *model.Client, settings *model.Settings) (err error)
@@ -603,6 +605,87 @@ func (svc *service) ServeRetweetedByPage(ctx context.Context, client io.Writer,
return
}
+func (svc *service) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
+ var hasNext bool
+ var nextLink string
+
+ var pg = mastodon.Pagination{
+ MaxID: maxID,
+ MinID: minID,
+ Limit: 20,
+ }
+
+ followings, err := c.GetAccountFollowing(ctx, id, &pg)
+ if err != nil {
+ return
+ }
+
+ if len(followings) == 20 && len(pg.MaxID) > 0 {
+ hasNext = true
+ nextLink = "/following/" + id + "?max_id=" + pg.MaxID
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.FollowingData{
+ CommonData: commonData,
+ Users: followings,
+ HasNext: hasNext,
+ NextLink: nextLink,
+ }
+
+ err = svc.renderer.RenderFollowingPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
+func (svc *service) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
+ var hasNext bool
+ var nextLink string
+
+ var pg = mastodon.Pagination{
+ MaxID: maxID,
+ MinID: minID,
+ Limit: 20,
+ }
+
+ followers, err := c.GetAccountFollowers(ctx, id, &pg)
+ if err != nil {
+ return
+ }
+
+ fmt.Println(len(followers), pg.MaxID)
+ if len(followers) == 20 && len(pg.MaxID) > 0 {
+ hasNext = true
+ nextLink = "/followers/" + id + "?max_id=" + pg.MaxID
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.FollowersData{
+ CommonData: commonData,
+ Users: followers,
+ HasNext: hasNext,
+ NextLink: nextLink,
+ }
+
+ err = svc.renderer.RenderFollowersPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
func (svc *service) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
var hasNext bool
var nextLink string
diff --git a/service/transport.go b/service/transport.go
index 3ab2546..20d96a5 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -122,6 +122,34 @@ func NewHandler(s Service, staticDir string) http.Handler {
}
}).Methods(http.MethodGet)
+ r.HandleFunc("/following/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+
+ id, _ := mux.Vars(req)["id"]
+ maxID := req.URL.Query().Get("max_id")
+ minID := req.URL.Query().Get("min_id")
+
+ err := s.ServeFollowingPage(ctx, w, nil, id, maxID, minID)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodGet)
+
+ r.HandleFunc("/followers/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+
+ id, _ := mux.Vars(req)["id"]
+ maxID := req.URL.Query().Get("max_id")
+ minID := req.URL.Query().Get("min_id")
+
+ err := s.ServeFollowersPage(ctx, w, nil, id, maxID, minID)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodGet)
+
r.HandleFunc("/like/{id}", func(w http.ResponseWriter, req *http.Request) {
ctx := getContextWithSession(context.Background(), req)
id, _ := mux.Vars(req)["id"]
@@ -323,7 +351,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
copyScope := req.FormValue("copy_scope") == "true"
settings := &model.Settings{
DefaultVisibility: visibility,
- CopyScope: copyScope,
+ CopyScope: copyScope,
}
err := s.SaveSettings(ctx, w, nil, settings)
diff --git a/templates/followers.tmpl b/templates/followers.tmpl
new file mode 100644
index 0000000..1c4e9eb
--- /dev/null
+++ b/templates/followers.tmpl
@@ -0,0 +1,12 @@
+{{template "header.tmpl" .HeaderData}}
+{{template "navigation.tmpl" .NavbarData}}
+<div class="page-title"> Followers </div>
+
+{{template "userlist.tmpl" .Users}}
+<div class="pagination">
+ {{if .HasNext}}
+ <a href="{{.NextLink}}">next</a>
+ {{end}}
+</div>
+
+{{template "footer.tmpl"}}
diff --git a/templates/following.tmpl b/templates/following.tmpl
new file mode 100644
index 0000000..b1d8499
--- /dev/null
+++ b/templates/following.tmpl
@@ -0,0 +1,12 @@
+{{template "header.tmpl" .HeaderData}}
+{{template "navigation.tmpl" .NavbarData}}
+<div class="page-title"> Following </div>
+
+{{template "userlist.tmpl" .Users}}
+<div class="pagination">
+ {{if .HasNext}}
+ <a href="{{.NextLink}}">next</a>
+ {{end}}
+</div>
+
+{{template "footer.tmpl"}}
diff --git a/templates/user.tmpl b/templates/user.tmpl
index fa19338..0c134af 100644
--- a/templates/user.tmpl
+++ b/templates/user.tmpl
@@ -36,7 +36,9 @@
{{end}}
</div>
<div>
- {{.User.StatusesCount}} statuses - {{.User.FollowingCount}} following - {{.User.FollowersCount}} followers
+ {{.User.StatusesCount}} statuses -
+ <a href="/following/{{.User.ID}}"> {{.User.FollowingCount}} following </a> -
+ <a href="/followers/{{.User.ID}}"> {{.User.FollowersCount}} followers </a>
</div>
</div>
<div class="user-profile-decription">