aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-22 18:10:42 +0000
committerr <r@freesoftwareextremist.com>2019-12-22 18:10:42 +0000
commit08cc2a6adeb591c687d68c22bac9bc5b5f9f62b6 (patch)
treefb4a475f9328b2d27f19c8e63ad2b56f7eb9980b /service
parent967a9c954e9709d57e860b8ea5c4e7f495402848 (diff)
downloadbloat-08cc2a6adeb591c687d68c22bac9bc5b5f9f62b6.tar.gz
bloat-08cc2a6adeb591c687d68c22bac9bc5b5f9f62b6.zip
Add emojis page
Diffstat (limited to 'service')
-rw-r--r--service/auth.go8
-rw-r--r--service/logging.go8
-rw-r--r--service/service.go21
-rw-r--r--service/transport.go10
4 files changed, 47 insertions, 0 deletions
diff --git a/service/auth.go b/service/auth.go
index 1b2700c..57ef3d0 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -125,6 +125,14 @@ func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *m
return s.Service.ServeAboutPage(ctx, client, c)
}
+func (s *authService) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeEmojiPage(ctx, client, c)
+}
+
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 444584e..9848e54 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -101,6 +101,14 @@ func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c
return s.Service.ServeAboutPage(ctx, client, c)
}
+func (s *loggingService) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, took=%v, err=%v\n",
+ "ServeEmojiPage", time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeEmojiPage(ctx, client, c)
+}
+
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 ad47408..27ee6bf 100644
--- a/service/service.go
+++ b/service/service.go
@@ -34,6 +34,7 @@ type Service interface {
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)
ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
+ ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (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)
@@ -444,6 +445,26 @@ func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mod
return
}
+func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
+ navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ emojis, err := c.GetInstanceEmojis(ctx)
+ if err != nil {
+ return
+ }
+
+ data := renderer.NewEmojiPageTemplateData(navbarData, emojis)
+ err = svc.renderer.RenderEmojiPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.NavbarTemplateData, err error) {
notifications, err := c.GetNotifications(ctx, nil)
if err != nil {
diff --git a/service/transport.go b/service/transport.go
index e3ec113..437d32f 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -241,6 +241,16 @@ func NewHandler(s Service, staticDir string) http.Handler {
}
}).Methods(http.MethodGet)
+ r.HandleFunc("/emojis", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+
+ err := s.ServeEmojiPage(ctx, w, nil)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodGet)
+
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
// TODO remove session from database
w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0"))