aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-02-02 07:24:06 +0000
committerr <r@freesoftwareextremist.com>2020-02-02 07:24:06 +0000
commit4d9e0af373b3a92d04498070c6fc8f6c197fc9c0 (patch)
treecdd8f8f3b2decbcf85bad4235bb4b914f39bbaad /service
parentc702a2b501769697576d601875d1db4553eeff12 (diff)
downloadbloat-4d9e0af373b3a92d04498070c6fc8f6c197fc9c0.tar.gz
bloat-4d9e0af373b3a92d04498070c6fc8f6c197fc9c0.zip
Add conversation muting
Diffstat (limited to 'service')
-rw-r--r--service/auth.go24
-rw-r--r--service/logging.go16
-rw-r--r--service/service.go14
-rw-r--r--service/transport.go34
4 files changed, 88 insertions, 0 deletions
diff --git a/service/auth.go b/service/auth.go
index 5ffe9ea..afb324a 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -284,3 +284,27 @@ func (s *as) SaveSettings(ctx context.Context, c *model.Client, settings *model.
}
return s.Service.SaveSettings(ctx, c, settings)
}
+
+func (s *as) MuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
+ err = s.authenticateClient(ctx, c)
+ if err != nil {
+ return
+ }
+ err = checkCSRF(ctx, c)
+ if err != nil {
+ return
+ }
+ return s.Service.MuteConversation(ctx, c, id)
+}
+
+func (s *as) UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
+ err = s.authenticateClient(ctx, c)
+ if err != nil {
+ return
+ }
+ err = checkCSRF(ctx, c)
+ if err != nil {
+ return
+ }
+ return s.Service.UnMuteConversation(ctx, c, id)
+}
diff --git a/service/logging.go b/service/logging.go
index 3d2baba..f26abaf 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -212,3 +212,19 @@ func (s *ls) SaveSettings(ctx context.Context, c *model.Client, settings *model.
}(time.Now())
return s.Service.SaveSettings(ctx, c, settings)
}
+
+func (s *ls) MuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
+ "MuteConversation", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.MuteConversation(ctx, c, id)
+}
+
+func (s *ls) UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
+ "UnMuteConversation", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.UnMuteConversation(ctx, c, id)
+}
diff --git a/service/service.go b/service/service.go
index ab6261e..043191b 100644
--- a/service/service.go
+++ b/service/service.go
@@ -44,6 +44,8 @@ type Service interface {
Follow(ctx context.Context, c *model.Client, id string) (err error)
UnFollow(ctx context.Context, c *model.Client, id string) (err error)
SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error)
+ MuteConversation(ctx context.Context, c *model.Client, id string) (err error)
+ UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error)
}
type service struct {
@@ -848,3 +850,15 @@ func (svc *service) SaveSettings(ctx context.Context, c *model.Client,
session.Settings = *settings
return svc.sessionRepo.Add(session)
}
+
+func (svc *service) MuteConversation(ctx context.Context, c *model.Client,
+ id string) (err error) {
+ _, err = c.MuteConversation(ctx, id)
+ return
+}
+
+func (svc *service) UnMuteConversation(ctx context.Context, c *model.Client,
+ id string) (err error) {
+ _, err = c.UnmuteConversation(ctx, id)
+ return
+}
diff --git a/service/transport.go b/service/transport.go
index 02168e8..cc864e7 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -481,6 +481,38 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound)
}
+ muteConversation := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.MuteConversation(ctx, c, id)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ s.ServeErrorPage(ctx, c, err)
+ return
+ }
+
+ w.Header().Add("Location", req.Header.Get("Referer"))
+ w.WriteHeader(http.StatusFound)
+ }
+
+ unMuteConversation := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.UnMuteConversation(ctx, c, id)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ s.ServeErrorPage(ctx, c, err)
+ return
+ }
+
+ w.Header().Add("Location", req.Header.Get("Referer"))
+ w.WriteHeader(http.StatusFound)
+ }
+
signout := func(w http.ResponseWriter, req *http.Request) {
// TODO remove session from database
http.SetCookie(w, &http.Cookie{
@@ -588,6 +620,8 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost)
r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost)
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
+ r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost)
+ r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
r.HandleFunc("/signout", signout).Methods(http.MethodGet)
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)