aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-26 09:11:24 +0000
committerr <r@freesoftwareextremist.com>2019-12-26 09:44:05 +0000
commitac4ff88adb9a2526555757f8d4e65c69cafb3788 (patch)
tree9277e726f3c152aa72c01167744ba9465ded4cbd /service
parentc34bde2d52bf71ff7de7d92f659e820fe4ea315b (diff)
downloadbloat-ac4ff88adb9a2526555757f8d4e65c69cafb3788.tar.gz
bloat-ac4ff88adb9a2526555757f8d4e65c69cafb3788.zip
Add liked by and retweeted by page
Diffstat (limited to 'service')
-rw-r--r--service/auth.go16
-rw-r--r--service/logging.go16
-rw-r--r--service/service.go82
-rw-r--r--service/transport.go22
4 files changed, 131 insertions, 5 deletions
diff --git a/service/auth.go b/service/auth.go
index cadb050..c408672 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -133,6 +133,22 @@ func (s *authService) ServeEmojiPage(ctx context.Context, client io.Writer, c *m
return s.Service.ServeEmojiPage(ctx, client, c)
}
+func (s *authService) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeLikedByPage(ctx, client, c, id)
+}
+
+func (s *authService) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeRetweetedByPage(ctx, client, c, id)
+}
+
func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
c, err = s.getClient(ctx)
if err != nil {
diff --git a/service/logging.go b/service/logging.go
index 87433a4..fbc6371 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -109,6 +109,22 @@ func (s *loggingService) ServeEmojiPage(ctx context.Context, client io.Writer, c
return s.Service.ServeEmojiPage(ctx, client, c)
}
+func (s *loggingService) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
+ "ServeLikedByPage", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeLikedByPage(ctx, client, c, id)
+}
+
+func (s *loggingService) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
+ "ServeRetweetedByPage", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeRetweetedByPage(ctx, client, c, id)
+}
+
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
diff --git a/service/service.go b/service/service.go
index ea0d078..7dc784f 100644
--- a/service/service.go
+++ b/service/service.go
@@ -37,6 +37,8 @@ type Service interface {
ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
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)
Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
@@ -192,25 +194,48 @@ func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *model
}
func (svc *service) ServeHomePage(ctx context.Context, client io.Writer) (err error) {
- err = svc.renderer.RenderHomePage(ctx, client)
+ commonData, err := svc.getCommonData(ctx, client, nil)
if err != nil {
return
}
- return
+ data := &renderer.HomePageData{
+ CommonData: commonData,
+ }
+
+ return svc.renderer.RenderHomePage(ctx, client, data)
}
func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
- svc.renderer.RenderErrorPage(ctx, client, err)
+ var errStr string
+ if err != nil {
+ errStr = err.Error()
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, nil)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.ErrorData{
+ CommonData: commonData,
+ Error: errStr,
+ }
+
+ svc.renderer.RenderErrorPage(ctx, client, data)
}
func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
- err = svc.renderer.RenderSigninPage(ctx, client)
+ commonData, err := svc.getCommonData(ctx, client, nil)
if err != nil {
return
}
- return
+ data := &renderer.SigninData{
+ CommonData: commonData,
+ }
+
+ return svc.renderer.RenderSigninPage(ctx, client, data)
}
func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
@@ -517,6 +542,53 @@ func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *mod
return
}
+func (svc *service) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ likers, err := c.GetFavouritedBy(ctx, id, nil)
+ if err != nil {
+ return
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.LikedByData{
+ CommonData: commonData,
+ Users: likers,
+ }
+
+ err = svc.renderer.RenderLikedByPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
+func (svc *service) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ retweeters, err := c.GetRebloggedBy(ctx, id, nil)
+ if err != nil {
+ return
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.RetweetedByData{
+ CommonData: commonData,
+ Users: retweeters,
+ }
+
+ err = svc.renderer.RenderRetweetedByPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
func (svc *service) getCommonData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.CommonData, err error) {
data = new(renderer.CommonData)
diff --git a/service/transport.go b/service/transport.go
index 438b39d..d4011db 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -98,6 +98,28 @@ func NewHandler(s Service, staticDir string) http.Handler {
}
}).Methods(http.MethodGet)
+ r.HandleFunc("/likedby/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.ServeLikedByPage(ctx, w, nil, id)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodGet)
+
+ r.HandleFunc("/retweetedby/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.ServeRetweetedByPage(ctx, w, nil, id)
+ 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"]