aboutsummaryrefslogtreecommitdiff
path: root/service/transport.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-02-08 10:49:06 +0000
committerr <r@freesoftwareextremist.com>2020-02-08 10:49:06 +0000
commit1e44d5d3d50c850505065ef16bc513a207c0656c (patch)
tree3f530fb102ff60075446c76b16bf28d97ecbad9d /service/transport.go
parent9d2e24a7dedc311862f6c0b5c20e9f6eff221caf (diff)
downloadbloat-1e44d5d3d50c850505065ef16bc513a207c0656c.tar.gz
bloat-1e44d5d3d50c850505065ef16bc513a207c0656c.zip
Add account muting and blocking
Diffstat (limited to 'service/transport.go')
-rw-r--r--service/transport.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/service/transport.go b/service/transport.go
index 6316748..81af4fa 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -451,6 +451,70 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound)
}
+ mute := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.Mute(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)
+ }
+
+ unMute := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.UnMute(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)
+ }
+
+ block := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.Block(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)
+ }
+
+ unBlock := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.UnBlock(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)
+ }
+
settings := func(w http.ResponseWriter, req *http.Request) {
c := newClient(w)
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
@@ -635,6 +699,10 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost)
r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost)
r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost)
+ r.HandleFunc("/mute/{id}", mute).Methods(http.MethodPost)
+ r.HandleFunc("/unmute/{id}", unMute).Methods(http.MethodPost)
+ r.HandleFunc("/block/{id}", block).Methods(http.MethodPost)
+ r.HandleFunc("/unblock/{id}", unBlock).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)