aboutsummaryrefslogtreecommitdiff
path: root/service/transport.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-04-17 17:19:11 +0000
committerr <r@freesoftwareextremist.com>2020-04-17 17:31:32 +0000
commit04af1b93dc95d761b4e05a448c9d86ac67623ff6 (patch)
tree75da80bfb467874b4fd94617f9c7c4cbd3cdbb85 /service/transport.go
parentccdb5ef051bfcc9e96f4b0ce98a32735eb48d1c4 (diff)
downloadbloat-04af1b93dc95d761b4e05a448c9d86ac67623ff6.tar.gz
bloat-04af1b93dc95d761b4e05a448c9d86ac67623ff6.zip
Add account {,un}subscribe
Diffstat (limited to 'service/transport.go')
-rw-r--r--service/transport.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/service/transport.go b/service/transport.go
index 6540333..108cc18 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -549,6 +549,38 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound)
}
+ subscribe := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.Subscribe(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)
+ }
+
+ unSubscribe := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.UnSubscribe(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"))
@@ -762,6 +794,8 @@ func NewHandler(s Service, staticDir string) http.Handler {
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("/subscribe/{id}", subscribe).Methods(http.MethodPost)
+ r.HandleFunc("/unsubscribe/{id}", unSubscribe).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)